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

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.478   ! mike      227:   </nav><p>This is revision 1.3256.</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
                   1349:     this common encoding.</p>
                   1350: 
                   1351:    </li>
1.1       mike     1352: 
                   1353:    <li><p>Otherwise, return an implementation-defined or
                   1354:    user-specified default character encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1.459     mike     1355:    <i>tentative</i>. In controlled environments or in environments
                   1356:    where the encoding of documents can be prescribed (for example, for
                   1357:    user agents intended for dedicated use in new networks), the more
1.1       mike     1358:    comprehensive <code title="">UTF-8</code> encoding is
1.459     mike     1359:    suggested. Due to its use in legacy content, <code title="">windows-1252</code> is suggested as a default in
1.187     mike     1360:    predominantly Western demographics instead.</p></li>
1.1       mike     1361: 
                   1362:   </ol><p>The <a href="dom.html#document-s-character-encoding">document's character encoding</a> must immediately
                   1363:   be set to the value returned from this algorithm, at the same time
                   1364:   as the user agent uses the returned value to select the decoder to
                   1365:   use for the input stream.</p>
                   1366: 
                   1367: 
1.237     mike     1368:   <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     1369: 
1.237     mike     1370:   <p>User agents must at a minimum support the UTF-8 and Windows-1252
                   1371:   encodings, but may support more.</p>
                   1372: 
                   1373:   <p class="note">It is not unusual for Web browsers to support dozens
                   1374:   if not upwards of a hundred distinct character encodings.</p>
                   1375: 
1.365     mike     1376:   <p>User agents must support the <a href="infrastructure.html#preferred-mime-name">preferred MIME name</a> of
                   1377:   every character encoding they support, and should support all the
                   1378:   IANA-registered names and aliases of every character encoding they
                   1379:   support. <a href="references.html#refsIANACHARSET">[IANACHARSET]</a></p>
1.237     mike     1380: 
                   1381:   <p>When comparing a string specifying a character encoding with the
                   1382:   name or alias of a character encoding to determine if they are
                   1383:   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
                   1384:   then perform the comparison in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   1385:   case-insensitive</a> manner.</p>
                   1386: 
                   1387: <!-- this bit will be replaced by actual alias registrations in due course -->
                   1388: 
                   1389:   <p>In addition, user agents must support the aliases given in the
                   1390:   following table for every character encoding they support, so that
                   1391:   labels from the first column are treated as equivalent to the labels
                   1392:   given in the corresponding cell from the second column on the same
                   1393:   row.</p>
                   1394: 
                   1395:   <table><caption>Additional character encoding aliases</caption>
                   1396:    <thead><tr><th> Alias </th><th> Corresponding encoding </th><th> References
                   1397:    </th></tr></thead><tbody><tr><td> x-sjis </td><td> windows-31J </td><td>
                   1398:          <a href="references.html#refsSHIFTJIS">[SHIFTJIS]</a>
                   1399:          <a href="references.html#refsWIN31J">[WIN31J]</a>
                   1400:     </td></tr><tr><td> windows-932 </td><td> windows-31J </td><td>
                   1401:          <a href="references.html#refsWIN31J">[WIN31J]</a>
                   1402:     </td></tr><tr><td> x-x-big5 </td><td> Big5 </td><td>
                   1403:          <a href="references.html#refsBIG5">[BIG5]</a>
                   1404:    </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
                   1405:   first column of the following table to either convert content to
                   1406:   Unicode characters or convert Unicode characters to bytes, it must
                   1407:   instead use the encoding given in the cell in the second column of
                   1408:   the same row. When a byte or sequence of bytes is treated
                   1409:   differently due to this encoding aliasing, it is said to have been
                   1410:   <dfn id="misinterpreted-for-compatibility">misinterpreted for compatibility</dfn>.</p>
                   1411: 
                   1412:   <table><caption>Character encoding overrides</caption>
                   1413:    <thead><tr><th> Input encoding </th><th> Replacement encoding </th><th> References
                   1414:    </th></tr></thead><tbody><!-- how about EUC-JP? --><tr><td> EUC-KR </td><td> windows-949 </td><td>
                   1415:          <a href="references.html#refsEUCKR">[EUCKR]</a>
                   1416:          <a href="references.html#refsWIN949">[WIN949]</a>
                   1417:     </td></tr><tr><td> GB2312 </td><td> GBK </td><td>
                   1418:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1419:          <a href="references.html#refsGBK">[GBK]</a>
                   1420:     </td></tr><tr><td> GB_2312-80 </td><td> GBK </td><td>
                   1421:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1422:          <a href="references.html#refsGBK">[GBK]</a>
                   1423:     </td></tr><tr><td> ISO-8859-1 </td><td> windows-1252 </td><td>
                   1424:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1425:          <a href="references.html#refsWIN1252">[WIN1252]</a>
                   1426:     </td></tr><tr><td> ISO-8859-9 </td><td> windows-1254 </td><td>
                   1427:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1428:          <a href="references.html#refsWIN1254">[WIN1254]</a>
                   1429:     </td></tr><tr><td> ISO-8859-11 </td><td> windows-874 </td><td>
                   1430:          <a href="references.html#refsISO885911">[ISO885911]</a>
                   1431:          <a href="references.html#refsWIN874">[WIN874]</a>
                   1432:     </td></tr><tr><td> KS_C_5601-1987 </td><td> windows-949 </td><td>
                   1433:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1434:          <a href="references.html#refsWIN949">[WIN949]</a>
                   1435:     </td></tr><tr><td> Shift_JIS </td><td> windows-31J </td><td>
                   1436:          <a href="references.html#refsSHIFTJIS">[SHIFTJIS]</a>
                   1437:          <a href="references.html#refsWIN31J">[WIN31J]</a>
                   1438:     </td></tr><tr><td> TIS-620 </td><td> windows-874 </td><td>
                   1439:          <a href="references.html#refsTIS620">[TIS620]</a>
                   1440:          <a href="references.html#refsWIN874">[WIN874]</a>
                   1441:     </td></tr><tr><td> US-ASCII </td><td> windows-1252 </td><td>
                   1442:          <a href="references.html#refsRFC1345">[RFC1345]</a>
                   1443:          <a href="references.html#refsWIN1252">[WIN1252]</a>
                   1444:    </td></tr></tbody></table><p class="note">The requirement to treat certain encodings as other
                   1445:   encodings according to the table above is a <a href="introduction.html#willful-violation">willful
                   1446:   violation</a> of the W3C Character Model specification, motivated
                   1447:   by a desire for compatibility with legacy content. <a href="references.html#refsCHARMOD">[CHARMOD]</a></p>
                   1448: 
                   1449:   <p>When a user agent is to use the UTF-16 encoding but no BOM has
                   1450:   been found, user agents must default to UTF-16LE.</p>
                   1451: 
                   1452:   <p class="note">The requirement to default UTF-16 to LE rather than
                   1453:   BE is a <a href="introduction.html#willful-violation">willful violation</a> of RFC 2781, motivated by a
                   1454:   desire for compatibility with legacy content. <a href="references.html#refsCHARMOD">[CHARMOD]</a></p>
                   1455: 
                   1456:   <hr><p>User agents must not support the CESU-8, UTF-7, BOCU-1 and SCSU
                   1457:   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>
                   1458: 
                   1459:   <p>Support for encodings based on EBCDIC is not recommended. This
                   1460:   encoding is rarely used for publicly-facing Web content.</p>
                   1461: 
                   1462:   <p>Support for UTF-32 is not recommended. This encoding is rarely
                   1463:   used, and frequently implemented incorrectly.</p>
                   1464: 
                   1465:   <p class="note">This specification does not make any attempt to
                   1466:   support EBCDIC-based encodings and UTF-32 in its algorithms; support
                   1467:   and use of these encodings can thus lead to unexpected behavior in
                   1468:   implementations of this specification.</p>
                   1469: 
                   1470: 
                   1471: 
                   1472:   <h5 id="preprocessing-the-input-stream"><span class="secno">9.2.2.3 </span>Preprocessing the input stream</h5>
1.1       mike     1473: 
                   1474:   <p>Given an encoding, the bytes in the input stream must be
                   1475:   converted to Unicode characters for the tokenizer, as described by
                   1476:   the rules for that encoding, except that the leading U+FEFF BYTE
                   1477:   ORDER MARK character, if any, must not be stripped by the encoding
                   1478:   layer (it is stripped by the rule below).</p> <!-- this is to
                   1479:   prevent two leading BOMs from being both stripped, once by the
                   1480:   decoder, and once by the parser -->
                   1481: 
                   1482:   <p>Bytes or sequences of bytes in the original byte stream that
1.393     mike     1483:   could not be converted to Unicode code points must be converted to
                   1484:   U+FFFD REPLACEMENT CHARACTERs.</p>
1.1       mike     1485: 
                   1486:   <p class="note">Bytes or sequences of bytes in the original byte
                   1487:   stream that did not conform to the encoding specification
                   1488:   (e.g. invalid UTF-8 byte sequences in a UTF-8 input stream) are
                   1489:   errors that conformance checkers are expected to report.</p>
                   1490: 
1.438     mike     1491:   <p>Any byte or sequence of bytes in the original byte stream that is
                   1492:   <a href="#misinterpreted-for-compatibility">misinterpreted for compatibility</a> is a <a href="#parse-error">parse
1.1       mike     1493:   error</a>.</p>
                   1494: 
                   1495:   <p>One leading U+FEFF BYTE ORDER MARK character must be ignored if
                   1496:   any are present.</p>
                   1497: 
1.300     mike     1498:   <p class="note">The requirement to strip a U+FEFF BYTE ORDER MARK
                   1499:   character regardless of whether that character was used to determine
                   1500:   the byte order is a <a href="introduction.html#willful-violation">willful violation</a> of Unicode,
                   1501:   motivated by a desire to increase the resilience of user agents in
                   1502:   the face of na&#239;ve transcoders.</p>
                   1503: 
1.316     mike     1504:   <p>All U+0000 NULL characters and code points in the range U+D800 to
1.315     mike     1505:   U+DFFF<!-- surrogates not allowed e.g. in UTF-8, and we don't want
                   1506:   them to suddenly turn into codepoints when they go through a UTF-16
                   1507:   pipe --> in the input must be replaced by U+FFFD REPLACEMENT
1.316     mike     1508:   CHARACTERs. Any occurrences of such characters and code points are
                   1509:   <a href="#parse-error" title="parse error">parse errors</a>.</p>
1.1       mike     1510: 
                   1511:   <p>Any occurrences of any characters in the ranges U+0001 to U+0008,
                   1512:   <!-- HT, LF allowed --> <!-- U+000B is in the next list --> <!-- FF,
                   1513:   CR allowed --> U+000E to U+001F, <!-- ASCII allowed --> U+007F
1.315     mike     1514:   <!--to U+0084, (U+0085 NEL not allowed), U+0086--> to U+009F, U+FDD0
                   1515:   to U+FDEF, and characters U+000B, U+FFFE, U+FFFF, U+1FFFE, U+1FFFF,
                   1516:   U+2FFFE, U+2FFFF, U+3FFFE, U+3FFFF, U+4FFFE, U+4FFFF, U+5FFFE,
                   1517:   U+5FFFF, U+6FFFE, U+6FFFF, U+7FFFE, U+7FFFF, U+8FFFE, U+8FFFF,
                   1518:   U+9FFFE, U+9FFFF, U+AFFFE, U+AFFFF, U+BFFFE, U+BFFFF, U+CFFFE,
                   1519:   U+CFFFF, U+DFFFE, U+DFFFF, U+EFFFE, U+EFFFF, U+FFFFE, U+FFFFF,
                   1520:   U+10FFFE, and U+10FFFF are <a href="#parse-error" title="parse error">parse
1.316     mike     1521:   errors</a>. These are all control characters or permanently
                   1522:   undefined Unicode characters (noncharacters).</p>
1.1       mike     1523: 
                   1524:   <p>U+000D CARRIAGE RETURN (CR) characters and U+000A LINE FEED (LF)
                   1525:   characters are treated specially. Any CR characters that are
                   1526:   followed by LF characters must be removed, and any CR characters not
                   1527:   followed by LF characters must be converted to LF characters. Thus,
                   1528:   newlines in HTML DOMs are represented by LF characters, and there
                   1529:   are never any CR characters in the input to the
                   1530:   <a href="#tokenization">tokenization</a> stage.</p>
                   1531: 
                   1532:   <p>The <dfn id="next-input-character">next input character</dfn> is the first character in the
                   1533:   input stream that has not yet been <dfn id="consumed">consumed</dfn>. Initially,
                   1534:   the <i><a href="#next-input-character">next input character</a></i> is the first character in the
                   1535:   input. The <dfn id="current-input-character">current input character</dfn> is the last character
                   1536:   to have been <i><a href="#consumed">consumed</a></i>.</p>
                   1537: 
                   1538:   <p>The <dfn id="insertion-point">insertion point</dfn> is the position (just before a
                   1539:   character or just before the end of the input stream) where content
1.159     mike     1540:   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     1541:   inserted. The insertion point is relative to the position of the
                   1542:   character immediately after it, it is not an absolute offset into
                   1543:   the input stream. Initially, the insertion point is
1.10      mike     1544:   undefined.</p>
1.1       mike     1545: 
                   1546:   <p>The "EOF" character in the tables below is a conceptual character
                   1547:   representing the end of the <a href="#the-input-stream">input stream</a>. If the parser
1.159     mike     1548:   is a <a href="embedded-content-0.html#script-created-parser">script-created parser</a>, then the end of the
1.1       mike     1549:   <a href="#the-input-stream">input stream</a> is reached when an <dfn id="explicit-eof-character">explicit "EOF"
1.159     mike     1550:   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     1551:   consumed. Otherwise, the "EOF" character is not a real character in
                   1552:   the stream, but rather the lack of any further characters.</p>
                   1553: 
                   1554: 
1.237     mike     1555:   <h5 id="changing-the-encoding-while-parsing"><span class="secno">9.2.2.4 </span>Changing the encoding while parsing</h5>
1.1       mike     1556: 
                   1557:   <p>When the parser requires the user agent to <dfn id="change-the-encoding">change the
                   1558:   encoding</dfn>, it must run the following steps. This might happen
                   1559:   if the <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> described above
                   1560:   failed to find an encoding, or if it found an encoding that was not
                   1561:   the actual encoding of the file.</p>
                   1562: 
                   1563:   <ol><li>If the new encoding is identical or equivalent to the encoding
                   1564:    that is already being used to interpret the input stream, then set
                   1565:    the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1566:    <i>certain</i> and abort these steps. This happens when the
                   1567:    encoding information found in the file matches what the
                   1568:    <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> determined to be the
                   1569:    encoding, and in the second pass through the parser if the first
                   1570:    pass found that the encoding sniffing algorithm described in the
                   1571:    earlier section failed to find the right encoding.</li>
                   1572: 
                   1573:    <li>If the encoding that is already being used to interpret the
                   1574:    input stream is a UTF-16 encoding, then set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1575:    <i>certain</i> and abort these steps. The new encoding is ignored;
                   1576:    if it was anything but the same encoding, then it would be clearly
                   1577:    incorrect.</li>
                   1578: 
                   1579:    <li>If the new encoding is a UTF-16 encoding, change it to
                   1580:    UTF-8.</li>
                   1581: 
                   1582:    <li>If all the bytes up to the last byte converted by the current
                   1583:    decoder have the same Unicode interpretations in both the current
                   1584:    encoding and the new encoding, and if the user agent supports
                   1585:    changing the converter on the fly, then the user agent may change
                   1586:    to the new converter for the encoding on the fly. Set the
                   1587:    <a href="dom.html#document-s-character-encoding">document's character encoding</a> and the encoding used to
                   1588:    convert the input stream to the new encoding, set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1589:    <i>certain</i>, and abort these steps.</li>
                   1590: 
                   1591:    <li>Otherwise, <a href="history.html#navigate">navigate</a> to the document again, with
                   1592:    <a href="history.html#replacement-enabled">replacement enabled</a>, and using the same <a href="history.html#source-browsing-context">source
                   1593:    browsing context</a>, but this time skip the <a href="#encoding-sniffing-algorithm">encoding
                   1594:    sniffing algorithm</a> and instead just set the encoding to the
                   1595:    new encoding and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1596:    <i>certain</i>. Whenever possible, this should be done without
                   1597:    actually contacting the network layer (the bytes should be
                   1598:    re-parsed from memory), even if, e.g., the document is marked as
                   1599:    not being cacheable. If this is not possible and contacting the
                   1600:    network layer would involve repeating a request that uses a method
                   1601:    other than HTTP GET (<a href="infrastructure.html#concept-http-equivalent-get" title="concept-http-equivalent-get">or
                   1602:    equivalent</a> for non-HTTP URLs), then instead set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1603:    <i>certain</i> and ignore the new encoding. The resource will be
                   1604:    misinterpreted. User agents may notify the user of the situation,
                   1605:    to aid in application development.</li>
                   1606: 
1.266     mike     1607:   </ol></div><div class="impl">
                   1608: 
                   1609:   <h4 id="parse-state"><span class="secno">9.2.3 </span>Parse state</h4>
1.1       mike     1610: 
                   1611:   <h5 id="the-insertion-mode"><span class="secno">9.2.3.1 </span>The insertion mode</h5>
                   1612: 
                   1613:   <p>The <dfn id="insertion-mode">insertion mode</dfn> is a state variable that controls
                   1614:   the primary operation of the tree construction stage.</p>
                   1615: 
                   1616:   <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
                   1617:   "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>",
                   1618:   "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>",
                   1619:   "<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     1620:   "<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     1621:   "<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>",
                   1622:   "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table body</a>",
                   1623:   "<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
                   1624:   table</a>", "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in
                   1625:   foreign content</a>", "<a href="#parsing-main-afterbody" title="insertion mode: after
                   1626:   body">after body</a>", "<a href="#parsing-main-inframeset" title="insertion mode: in
                   1627:   frameset">in frameset</a>", "<a href="#parsing-main-afterframeset" title="insertion mode: after
                   1628:   frameset">after frameset</a>", "<a href="#the-after-after-body-insertion-mode" title="insertion mode:
                   1629:   after after body">after after body</a>", and "<a href="#the-after-after-frameset-insertion-mode" title="insertion mode: after after frameset">after after
                   1630:   frameset</a>" during the course of the parsing, as described in
                   1631:   the <a href="#tree-construction">tree construction</a> stage. The insertion mode affects
                   1632:   how tokens are processed and whether CDATA sections are
                   1633:   supported.</p>
                   1634: 
                   1635:   <p>Seven of these modes, namely "<a href="#parsing-main-inhead" title="insertion mode: in
                   1636:   head">in head</a>", "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   1637:   body</a>", "<a href="#parsing-main-intable" title="insertion mode: in table">in
                   1638:   table</a>", "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   1639:   body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>",
                   1640:   "<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
                   1641:   that the other modes defer to them at various times. When the
                   1642:   algorithm below says that the user agent is to do something
                   1643:   "<dfn id="using-the-rules-for">using the rules for</dfn> the <var title="">m</var> insertion
                   1644:   mode", where <var title="">m</var> is one of these modes, the user
                   1645:   agent must use the rules described under the <var title="">m</var>
                   1646:   <a href="#insertion-mode">insertion mode</a>'s section, but must leave the
                   1647:   <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>
                   1648:   to a new value.</p>
                   1649: 
                   1650:   <p>When the insertion mode is switched to "<a href="#parsing-main-incdata" title="insertion
1.91      mike     1651:   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     1652:   <dfn id="original-insertion-mode">original insertion mode</dfn> is also set. This is the
                   1653:   insertion mode to which the tree construction stage will return.</p>
                   1654: 
                   1655:   <p>When the insertion mode is switched to "<a href="#parsing-main-inforeign" title="insertion
                   1656:   mode: in foreign content">in foreign content</a>", the
                   1657:   <dfn id="secondary-insertion-mode">secondary insertion mode</dfn> is also set. This secondary mode
                   1658:   is used within the rules for the "<a href="#parsing-main-inforeign" title="insertion mode: in
                   1659:   foreign content">in foreign content</a>" mode to handle HTML
                   1660:   (i.e. not foreign) content.</p>
                   1661: 
                   1662:   <hr><p>When the steps below require the UA to <dfn id="reset-the-insertion-mode-appropriately">reset the insertion
                   1663:   mode appropriately</dfn>, it means the UA must follow these
                   1664:   steps:</p>
                   1665: 
                   1666:   <ol><li>Let <var title="">last</var> be false.</li>
                   1667: 
                   1668:    <li>Let <var title="">node</var> be the last node in the
                   1669:    <a href="#stack-of-open-elements">stack of open elements</a>.</li>
                   1670: 
                   1671:    <li>If <var title="">node</var> is the first node in the stack of
                   1672:    open elements, then set <var title="">last</var> to true and set
                   1673:    <var title="">node</var> to the <var title="">context</var>
                   1674:    element. (<a href="#fragment-case">fragment case</a>)</li>
                   1675: 
                   1676:    <li>If <var title="">node</var> is a <code><a href="forms.html#the-select-element">select</a></code> element,
                   1677:    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
                   1678:    steps. (<a href="#fragment-case">fragment case</a>)</li>
                   1679: 
                   1680:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-td-element">td</a></code> or
                   1681:    <code><a href="tabular-data.html#the-th-element">th</a></code> element and <var title="">last</var> is false, then
                   1682:    switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion
                   1683:    mode: in cell">in cell</a>" and abort these steps.</li>
                   1684: 
                   1685:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then
                   1686:    switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion
                   1687:    mode: in row">in row</a>" and abort these steps.</li>
                   1688: 
                   1689:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
                   1690:    <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
                   1691:    <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in
                   1692:    table body">in table body</a>" and abort these steps.</li>
                   1693: 
                   1694:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-caption-element">caption</a></code> element,
                   1695:    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
                   1696:    these steps.</li>
                   1697: 
                   1698:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element,
                   1699:    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
                   1700:    abort these steps. (<a href="#fragment-case">fragment case</a>)</li>
                   1701: 
                   1702:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-table-element">table</a></code> element,
                   1703:    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
                   1704:    steps.</li>
                   1705: 
                   1706:    <li>If <var title="">node</var> is an element from the <a href="#mathml-namespace">MathML
                   1707:    namespace</a> or the <a href="#svg-namespace">SVG namespace</a>, then switch the
                   1708:    <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
                   1709:    foreign content">in foreign content</a>", let the
                   1710:    <a href="#secondary-insertion-mode">secondary insertion mode</a> be "<a href="#parsing-main-inbody" title="insertion
                   1711:    mode: in body">in body</a>", and abort these steps.</li>
                   1712: 
1.159     mike     1713:    <li>If <var title="">node</var> is a <code><a href="semantics.html#the-head-element-0">head</a></code> element,
1.1       mike     1714:    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
                   1715:    these steps. (<a href="#fragment-case">fragment case</a>)</li> <!-- This is only
                   1716:    here for now in case people think that the spec accidentally
                   1717:    omitted it and try to "fix" it. Note that noscript-in-head is also
                   1718:    handled this way. This is all intentional. The only thing it
                   1719:    doesn't handle is the scripting-disabled fragment parsing case for
                   1720:    a <head> element containing a <noscript> which itself contains
                   1721:    something other than a <link> or a <style> element; you'd expect
                   1722:    that to break out of the <noscript> but it doesn't. This is an edge
                   1723:    case that doesn't affect the spec, since the algorithm for fragment
                   1724:    parsing is only used for innerHTML/outerHTML/insertAdjacentHTML(),
1.333     mike     1725:    where we know scripting is enabled. -->
1.1       mike     1726: 
1.159     mike     1727:    <li>If <var title="">node</var> is a <code><a href="semantics.html#the-body-element-0">body</a></code> element,
1.1       mike     1728:    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
                   1729:    steps.</li>
                   1730: 
1.5       mike     1731:    <li>If <var title="">node</var> is a <code><a href="obsolete.html#frameset">frameset</a></code> element,
1.1       mike     1732:    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
                   1733:    these steps. (<a href="#fragment-case">fragment case</a>)</li>
                   1734: 
1.159     mike     1735:    <li>If <var title="">node</var> is an <code><a href="semantics.html#the-html-element-0">html</a></code> element,
1.333     mike     1736:    then <!--: if the <span><code title="">head</code> element
                   1737:    pointer</span> is null,--> switch the <a href="#insertion-mode">insertion mode</a>
                   1738:    to "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before
                   1739:    head</a>"<!--, otherwise, switch the <span>insertion mode</span>
                   1740:    to "<span title="insertion mode: after head">after head</span>".-->
                   1741:    Then, <!-- in either case, --> abort these steps. (<a href="#fragment-case">fragment
                   1742:    case</a>)</li> <!-- if the head element pointer can ever be
                   1743:    non-null when we're going through these steps, we'll need to
                   1744:    uncomment out the commented-out bits -->
1.1       mike     1745: 
                   1746:    <li>If <var title="">last</var> is true, then switch the
                   1747:    <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in
                   1748:    body">in body</a>" and abort these steps. (<a href="#fragment-case">fragment
                   1749:    case</a>)</li>
                   1750: 
                   1751:    <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
                   1752:    elements</a>.</li>
                   1753: 
                   1754:    <li>Return to step 3.</li>
                   1755: 
                   1756:   </ol><h5 id="the-stack-of-open-elements"><span class="secno">9.2.3.2 </span>The stack of open elements</h5>
                   1757: 
                   1758:   <p>Initially, the <dfn id="stack-of-open-elements">stack of open elements</dfn> is empty. The
                   1759:   stack grows downwards; the topmost node on the stack is the first
                   1760:   one added to the stack, and the bottommost node of the stack is the
                   1761:   most recently added node in the stack (notwithstanding when the
                   1762:   stack is manipulated in a random access fashion as part of <a href="#adoptionAgency">the handling for misnested tags</a>).</p>
                   1763: 
                   1764:   <p>The "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before
                   1765:   html</a>" <a href="#insertion-mode">insertion mode</a> creates the
1.159     mike     1766:   <code><a href="semantics.html#the-html-element-0">html</a></code> root element node, which is then added to the
1.1       mike     1767:   stack.</p>
                   1768: 
                   1769:   <p>In the <a href="#fragment-case">fragment case</a>, the <a href="#stack-of-open-elements">stack of open
1.159     mike     1770:   elements</a> is initialized to contain an <code><a href="semantics.html#the-html-element-0">html</a></code>
1.1       mike     1771:   element that is created as part of <a href="#html-fragment-parsing-algorithm" title="html fragment
                   1772:   parsing algorithm">that algorithm</a>. (The <a href="#fragment-case">fragment
                   1773:   case</a> skips the "<a href="#the-before-html-insertion-mode" title="insertion mode: before
                   1774:   html">before html</a>" <a href="#insertion-mode">insertion mode</a>.)</p>
                   1775: 
1.159     mike     1776:   <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     1777:   node of the stack. It never gets popped off the stack.</p>
                   1778: 
                   1779:   <p>The <dfn id="current-node">current node</dfn> is the bottommost node in this
                   1780:   stack.</p>
                   1781: 
                   1782:   <p>The <dfn id="current-table">current table</dfn> is the last <code><a href="tabular-data.html#the-table-element">table</a></code>
                   1783:   element in the <a href="#stack-of-open-elements">stack of open elements</a>, if there is
                   1784:   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
                   1785:   open elements</a> (<a href="#fragment-case">fragment case</a>), then the
                   1786:   <a href="#current-table">current table</a> is the first element in the <a href="#stack-of-open-elements">stack
1.159     mike     1787:   of open elements</a> (the <code><a href="semantics.html#the-html-element-0">html</a></code> element).</p>
1.1       mike     1788: 
                   1789:   <p>Elements in the stack fall into the following categories:</p>
                   1790: 
                   1791:   <dl><dt><dfn id="special">Special</dfn></dt>
                   1792: 
                   1793:    <dd><p>The following HTML elements have varying levels of special
                   1794:    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>,
                   1795:    <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     1796:    <code><a href="obsolete.html#basefont">basefont</a></code>, <code>bgsound</code>,
1.159     mike     1797:    <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     1798:    <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     1799:    <code><a href="interactive-elements.html#the-command">command</a></code>, <!--v2DDATAGRID--><code>datagrid</code>,
1.422     mike     1800:    <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>,
                   1801:    <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>,
                   1802:    <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>,
                   1803:    <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>,
                   1804:    <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>,
                   1805:    <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>,
                   1806:    <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>,
                   1807:    <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>,
                   1808:    (commented out because this isn't an element that can end up on the
                   1809:    stack, so it doesn't matter) --> <code><a href="text-level-semantics.html#the-img-element">img</a></code>,
                   1810:    <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>,
                   1811:    <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>,
                   1812:    <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>,
                   1813:    <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>,
                   1814:    <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>,
                   1815:    <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>,
                   1816:    <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>,
                   1817:    <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>,
                   1818:    <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>,
                   1819:    <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     1820: 
                   1821:    <dt><dfn id="scoping">Scoping</dfn></dt>
                   1822:    <dd><p>The following HTML elements introduce new <a href="#has-an-element-in-scope" title="has
                   1823:    an element in scope">scopes</a> for various parts of the
1.5       mike     1824:    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     1825:    <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>,
                   1826:    <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     1827:    <code><a href="tabular-data.html#the-th-element">th</a></code>, and SVG's <code>foreignObject</code>.</p></dd>
                   1828: 
                   1829:    <dt><dfn id="formatting">Formatting</dfn></dt>
                   1830:    <dd><p>The following HTML elements are those that end up in the
                   1831:    <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     1832:    <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>,
                   1833:    <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>,
                   1834:    <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>,
                   1835:    <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
                   1836:    <code><a href="obsolete.html#u">u</a></code>.</p></dd>
1.1       mike     1837: 
                   1838:    <dt><dfn id="phrasing">Phrasing</dfn></dt>
                   1839:    <dd><p>All other elements found while parsing an HTML
                   1840:    document.</p></dd>
                   1841: 
1.234     mike     1842:   </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
                   1843:   specific scope</dfn> consisting of a list of element types <var title="">list</var> when the following algorithm terminates in a
                   1844:   match state:</p>
1.1       mike     1845: 
                   1846:   <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   1847:    node</a> (the bottommost node of the stack).</p></li>
                   1848: 
                   1849:    <li><p>If <var title="">node</var> is the target node, terminate in
                   1850:    a match state.</p></li>
                   1851: 
1.234     mike     1852:    <li><p>Otherwise, if <var title="">node</var> is one of the element
                   1853:    types in <var title="">list</var>, terminate in a failure
                   1854:    state.</p></li>
1.1       mike     1855: 
                   1856:    <li><p>Otherwise, set <var title="">node</var> to the previous
                   1857:    entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to step
                   1858:    2. (This will never fail, since the loop will always terminate in
                   1859:    the previous step if the top of the stack &#8212; an
1.159     mike     1860:    <code><a href="semantics.html#the-html-element-0">html</a></code> element &#8212; is reached.)</p></li>
1.1       mike     1861: 
1.234     mike     1862:   </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
                   1863:   it <a href="#has-an-element-in-the-specific-scope">has an element in the specific scope</a> consisting
                   1864:   of the following element types:</p>
                   1865: 
                   1866:   <ul class="brief"><li><code><a href="obsolete.html#the-applet-element">applet</a></code> in the HTML namespace</li>
                   1867:    <li><code><a href="tabular-data.html#the-caption-element">caption</a></code> in the HTML namespace</li>
                   1868:    <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.) -->
                   1869:    <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
                   1870:    <li><code><a href="tabular-data.html#the-td-element">td</a></code> in the HTML namespace</li>
                   1871:    <li><code><a href="tabular-data.html#the-th-element">th</a></code> in the HTML namespace</li>
                   1872:    <li><code><a href="forms.html#the-button-element">button</a></code> in the HTML namespace</li>
                   1873:    <li><code><a href="obsolete.html#the-marquee-element">marquee</a></code> in the HTML namespace</li>
                   1874:    <li><code><a href="text-level-semantics.html#the-object-element">object</a></code> in the HTML namespace</li>
                   1875:    <li><code title="">foreignObject</code> in the SVG namespace</li>
                   1876:   </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
                   1877:   item scope</dfn> when it <a href="#has-an-element-in-the-specific-scope">has an element in the specific
                   1878:   scope</a> consisting of the following element types:</p>
                   1879: 
                   1880:   <ul class="brief"><li>All the element types listed above for the <i><a href="#has-an-element-in-scope">has an element
                   1881:    in scope</a></i> algorithm.</li>
                   1882:    <li><code><a href="semantics.html#the-ol-element">ol</a></code> in the HTML namespace</li>
                   1883:    <li><code><a href="semantics.html#the-ul-element">ul</a></code> in the HTML namespace</li>
                   1884:   </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
                   1885:   scope</em></dfn> when it <a href="#has-an-element-in-the-specific-scope">has an element in the specific
                   1886:   scope</a> consisting of the following element types:</p>
                   1887: 
                   1888:   <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.) -->
                   1889:    <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
                   1890:   </ul><p>Nothing happens if at any time any of the elements in the
1.1       mike     1891:   <a href="#stack-of-open-elements">stack of open elements</a> are moved to a new location in,
                   1892:   or removed from, the <code>Document</code> tree. In particular, the
                   1893:   stack is not changed in this situation. This can cause, amongst
                   1894:   other strange effects, content to be appended to nodes that are no
                   1895:   longer in the DOM.</p>
                   1896: 
                   1897:   <p class="note">In some cases (namely, when <a href="#adoptionAgency">closing misnested formatting elements</a>),
                   1898:   the stack is manipulated in a random-access fashion.</p>
                   1899: 
                   1900: 
                   1901:   <h5 id="the-list-of-active-formatting-elements"><span class="secno">9.2.3.3 </span>The list of active formatting elements</h5>
                   1902: 
                   1903:   <p>Initially, the <dfn id="list-of-active-formatting-elements">list of active formatting elements</dfn> is
                   1904:   empty. It is used to handle mis-nested <a href="#formatting" title="formatting">formatting element tags</a>.</p>
                   1905: 
                   1906:   <p>The list contains elements in the <a href="#formatting">formatting</a>
                   1907:   category, and scope markers. The scope markers are inserted when
1.159     mike     1908:   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     1909:   elements, marquees, table cells, and table captions, and are used to
1.5       mike     1910:   prevent formatting from "leaking" <em>into</em> <code><a href="obsolete.html#the-applet-element">applet</a></code>
1.159     mike     1911:   elements, buttons, <code><a href="text-level-semantics.html#the-object-element">object</a></code> elements, marquees, and
1.1       mike     1912:   tables.</p>
                   1913: 
                   1914:   <p class="note">The scope markers are unrelated to the concept of an
                   1915:   element being <a href="#has-an-element-in-scope" title="has an element in scope">in
                   1916:   scope</a>.</p>
                   1917: 
                   1918:   <p>In addition, each element in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1919:   elements</a> is associated with the token for which it was
                   1920:   created, so that further elements can be created for that token if
                   1921:   necessary.</p>
                   1922: 
                   1923:   <p>When the steps below require the UA to <dfn id="reconstruct-the-active-formatting-elements">reconstruct the
                   1924:   active formatting elements</dfn>, the UA must perform the following
                   1925:   steps:</p>
                   1926: 
                   1927:   <ol><li>If there are no entries in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1928:    elements</a>, then there is nothing to reconstruct; stop this
                   1929:    algorithm.</li>
                   1930: 
                   1931:    <li>If the last (most recently added) entry in the <a href="#list-of-active-formatting-elements">list of
                   1932:    active formatting elements</a> is a marker, or if it is an
                   1933:    element that is in the <a href="#stack-of-open-elements">stack of open elements</a>, then
                   1934:    there is nothing to reconstruct; stop this algorithm.</li>
                   1935: 
                   1936:    <li>Let <var title="">entry</var> be the last (most recently added)
                   1937:    element in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1938:    elements</a>.</li>
                   1939: 
                   1940:    <li>If there are no entries before <var title="">entry</var> in the
                   1941:    <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, then jump to step
                   1942:    8.</li>
                   1943: 
                   1944:    <li>Let <var title="">entry</var> be the entry one earlier than
                   1945:    <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1946:    elements</a>.</li>
                   1947: 
                   1948:    <li>If <var title="">entry</var> is neither a marker nor an element
                   1949:    that is also in the <a href="#stack-of-open-elements">stack of open elements</a>, go to step
                   1950:    4.</li>
                   1951: 
                   1952:    <li>Let <var title="">entry</var> be the element one later than
                   1953:    <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1954:    elements</a>.</li>
                   1955: 
                   1956:    <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
                   1957:    element <var title="">entry</var> was created, to obtain <var title="">new element</var>.</li>
                   1958: 
                   1959:    <li>Append <var title="">new element</var> to the <a href="#current-node">current
                   1960:    node</a> and push it onto the <a href="#stack-of-open-elements">stack of open
                   1961:    elements</a> so that it is the new <a href="#current-node">current
                   1962:    node</a>.</li>
                   1963: 
                   1964:    <li>Replace the entry for <var title="">entry</var> in the list
                   1965:    with an entry for <var title="">new element</var>.</li>
                   1966: 
                   1967:    <li>If the entry for <var title="">new element</var> in the
                   1968:    <a href="#list-of-active-formatting-elements">list of active formatting elements</a> is not the last
                   1969:    entry in the list, return to step 7.</li>
                   1970: 
                   1971:   </ol><p>This has the effect of reopening all the formatting elements that
                   1972:   were opened in the current body, cell, or caption (whichever is
                   1973:   youngest) that haven't been explicitly closed.</p>
                   1974: 
                   1975:   <p class="note">The way this specification is written, the
                   1976:   <a href="#list-of-active-formatting-elements">list of active formatting elements</a> always consists of
                   1977:   elements in chronological order with the least recently added
                   1978:   element first and the most recently added element last (except for
                   1979:   while steps 8 to 11 of the above algorithm are being executed, of
                   1980:   course).</p>
                   1981: 
                   1982:   <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
                   1983:   active formatting elements up to the last marker</dfn>, the UA must
                   1984:   perform the following steps:</p>
                   1985: 
                   1986:   <ol><li>Let <var title="">entry</var> be the last (most recently added)
                   1987:    entry in the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</li>
                   1988: 
                   1989:    <li>Remove <var title="">entry</var> from the <a href="#list-of-active-formatting-elements">list of active
                   1990:    formatting elements</a>.</li>
                   1991: 
                   1992:    <li>If <var title="">entry</var> was a marker, then stop the
                   1993:    algorithm at this point. The list has been cleared up to the last
                   1994:    marker.</li>
                   1995: 
                   1996:    <li>Go to step 1.</li>
                   1997: 
                   1998:   </ol><h5 id="the-element-pointers"><span class="secno">9.2.3.4 </span>The element pointers</h5>
                   1999: 
                   2000:   <p>Initially, the <dfn id="head-element-pointer"><code title="">head</code> element
                   2001:   pointer</dfn> and the <dfn id="form-element-pointer"><code title="">form</code> element
                   2002:   pointer</dfn> are both null.</p>
                   2003: 
1.159     mike     2004:   <p>Once a <code><a href="semantics.html#the-head-element-0">head</a></code> element has been parsed (whether
1.1       mike     2005:   implicitly or explicitly) the <a href="#head-element-pointer"><code title="">head</code>
                   2006:   element pointer</a> gets set to point to this node.</p>
                   2007: 
                   2008:   <p>The <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
                   2009:   points to the last <code><a href="forms.html#the-form-element">form</a></code> element that was opened and
                   2010:   whose end tag has not yet been seen. It is used to make form
                   2011:   controls associate with forms in the face of dramatically bad
                   2012:   markup, for historical reasons.</p>
                   2013: 
                   2014: 
                   2015:   <h5 id="other-parsing-state-flags"><span class="secno">9.2.3.5 </span>Other parsing state flags</h5>
                   2016: 
                   2017:   <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
                   2018:   <code>Document</code> with which the parser is associated when the
                   2019:   parser was created, and "disabled" otherwise.</p>
                   2020: 
                   2021:   <p class="note">The <a href="#scripting-flag">scripting flag</a> can be enabled even
                   2022:   when the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML fragment
                   2023:   parsing algorithm</a>, even though <code><a href="semantics.html#script">script</a></code> elements
                   2024:   don't execute in that case.</p>
                   2025: 
                   2026:   <p>The <dfn id="frameset-ok-flag">frameset-ok flag</dfn> is set to "ok" when the parser is
                   2027:   created. It is set to "not ok" after certain tokens are seen.</p>
                   2028: 
1.266     mike     2029:   </div><div class="impl">
1.1       mike     2030: 
1.159     mike     2031:   <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     2032: 
                   2033:   <p>Implementations must act as if they used the following state
                   2034:   machine to tokenize HTML. The state machine must start in the
                   2035:   <a href="#data-state">data state</a>. Most states consume a single character,
                   2036:   which may have various side-effects, and either switches the state
                   2037:   machine to a new state to <em>reconsume</em> the same character, or
                   2038:   switches it to a new state (to consume the next character), or
                   2039:   repeats the same state (to consume the next character). Some states
                   2040:   have more complicated behavior and can consume several characters
                   2041:   before switching to another state.</p>
                   2042: 
                   2043:   <p>The exact behavior of certain states depends on a <dfn id="content-model-flag">content
                   2044:   model flag</dfn> that is set after certain tokens are emitted. The
1.91      mike     2045:   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
                   2046:   state. In the RCDATA and RAWTEXT states, a further <dfn id="escape-flag">escape
1.1       mike     2047:   flag</dfn> is used to control the behavior of the tokenizer. It is
                   2048:   either true or false, and initially must be set to the false
                   2049:   state. The <a href="#insertion-mode">insertion mode</a> and the <a href="#stack-of-open-elements">stack of open
                   2050:   elements</a> also affects tokenization.</p>
                   2051: 
                   2052:   <p>The output of the tokenization step is a series of zero or more
                   2053:   of the following tokens: DOCTYPE, start tag, end tag, comment,
                   2054:   character, end-of-file. DOCTYPE tokens have a name, a public
                   2055:   identifier, a system identifier, and a <i>force-quirks
                   2056:   flag</i>. When a DOCTYPE token is created, its name, public
                   2057:   identifier, and system identifier must be marked as missing (which
                   2058:   is a distinct state from the empty string), and the <i>force-quirks
                   2059:   flag</i> must be set to <i>off</i> (its other state is
                   2060:   <i>on</i>). Start and end tag tokens have a tag name, a
                   2061:   <i>self-closing flag</i>, and a list of attributes, each of which
                   2062:   has a name and a value. When a start or end tag token is created,
                   2063:   its <i>self-closing flag</i> must be unset (its other state is that
                   2064:   it be set), and its attributes list must be empty. Comment and
                   2065:   character tokens have data.</p>
                   2066: 
                   2067:   <p>When a token is emitted, it must immediately be handled by the
                   2068:   <a href="#tree-construction">tree construction</a> stage. The tree construction stage
                   2069:   can affect the state of the <a href="#content-model-flag">content model flag</a>, and can
                   2070:   insert additional characters into the stream. (For example, the
                   2071:   <code><a href="semantics.html#script">script</a></code> element can result in scripts executing and
1.159     mike     2072:   using the <a href="embedded-content-0.html#dynamic-markup-insertion">dynamic markup insertion</a> APIs to insert
1.1       mike     2073:   characters into the stream being tokenized.)</p>
                   2074: 
                   2075:   <p>When a start tag token is emitted with its <i>self-closing
                   2076:   flag</i> set, if the flag is not <dfn id="acknowledge-self-closing-flag" title="acknowledge
                   2077:   self-closing flag">acknowledged</dfn> when it is processed by the
                   2078:   tree construction stage, that is a <a href="#parse-error">parse error</a>.</p>
                   2079: 
                   2080:   <p>When an end tag token is emitted, the <a href="#content-model-flag">content model
                   2081:   flag</a> must be switched to the PCDATA state.</p>
                   2082: 
                   2083:   <p>When an end tag token is emitted with attributes, that is a
                   2084:   <a href="#parse-error">parse error</a>.</p>
                   2085: 
                   2086:   <p>When an end tag token is emitted with its <i>self-closing
                   2087:   flag</i> set, that is a <a href="#parse-error">parse error</a>.</p>
                   2088: 
                   2089:   <p>Before each step of the tokenizer, the user agent must first
                   2090:   check the <a href="#parser-pause-flag">parser pause flag</a>. If it is true, then the
                   2091:   tokenizer must abort the processing of any nested invocations of the
                   2092:   tokenizer, yielding control back to the caller. If it is false, then
                   2093:   the user agent may then check to see if either one of the scripts in
                   2094:   the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts that will execute as soon as
                   2095:   possible</a> or the first script in the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts
                   2096:   that will execute asynchronously</a>, has <a href="semantics.html#completed-loading">completed
                   2097:   loading</a>. If one has, then it must be <a href="semantics.html#executing-a-script-block" title="executing a
                   2098:   script block">executed</a> and removed from its list.</p>
                   2099: 
                   2100:   <p>The tokenizer state machine consists of the states defined in the
                   2101:   following subsections.</p>
                   2102: 
1.333     mike     2103:   <!-- Order of the lists below is supposed to be non-error then
                   2104:   error, by unicode, then EOF, ending with "anything else" -->
1.1       mike     2105: 
                   2106:   <h5 id="data-state"><span class="secno">9.2.4.1 </span><dfn>Data state</dfn></h5>
                   2107: 
                   2108:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2109: 
                   2110:   <dl class="switch"><dt>U+0026 AMPERSAND (&amp;)</dt>
                   2111:    <dd>When the <a href="#content-model-flag">content model flag</a> is set to one of the
                   2112:    PCDATA or RCDATA states and the <a href="#escape-flag">escape flag</a> is
1.299     mike     2113:    false: switch to the <a href="#character-reference-in-data-state">character reference in data
1.56      mike     2114:    state</a>.</dd>
                   2115:    <dd>Otherwise: treat it as per the "anything else" entry
                   2116:    below.</dd>
1.1       mike     2117: 
                   2118:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2119:    <dd>
                   2120: 
                   2121:     <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91      mike     2122:     RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1       mike     2123:     is false, and there are at least three characters before this
                   2124:     one in the input stream, and the last four characters in the
                   2125:     input stream, including this one, are U+003C LESS-THAN SIGN,
                   2126:     U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS, and U+002D
                   2127:     HYPHEN-MINUS ("&lt;!--"), then set the <a href="#escape-flag">escape flag</a>
                   2128:     to true.</p>
                   2129: 
                   2130:     <p>In any case, emit the input character as a character
                   2131:     token. Stay in the <a href="#data-state">data state</a>.</p>
                   2132: 
                   2133:    </dd>
                   2134: 
                   2135:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2136:    <dd>When the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
                   2137:    state: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
                   2138:    <dd>When the <a href="#content-model-flag">content model flag</a> is set to either the
1.91      mike     2139:    RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1       mike     2140:    is false: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
                   2141:    <dd>Otherwise: treat it as per the "anything else" entry
                   2142:    below.</dd>
                   2143: 
                   2144:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2145:    <dd>
                   2146: 
                   2147:     <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91      mike     2148:     RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape
1.1       mike     2149:     flag</a> is true, and the last three characters in the input
                   2150:     stream including this one are U+002D HYPHEN-MINUS, U+002D
                   2151:     HYPHEN-MINUS, U+003E GREATER-THAN SIGN ("--&gt;"), set the
                   2152:     <a href="#escape-flag">escape flag</a> to false.</p> <!-- no need to check
                   2153:     that there are enough characters, since you can only run into
                   2154:     this if the flag is true in the first place, which requires four
                   2155:     characters. -->
                   2156: 
                   2157:     <p>In any case, emit the input character as a character
                   2158:     token. Stay in the <a href="#data-state">data state</a>.</p>
                   2159: 
                   2160:    </dd>
                   2161: 
                   2162:    <dt>EOF</dt>
                   2163:    <dd>Emit an end-of-file token.</dd>
                   2164: 
                   2165:    <dt>Anything else</dt>
                   2166:    <dd>Emit the input character as a character token. Stay in the
                   2167:    <a href="#data-state">data state</a>.</dd>
                   2168: 
1.299     mike     2169:   </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     2170: 
                   2171:   <p><i>(This cannot happen if the <a href="#content-model-flag">content model flag</a>
1.91      mike     2172:   is set to the RAWTEXT state.)</i></p>
1.1       mike     2173: 
                   2174:   <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>, with no
                   2175:   <a href="#additional-allowed-character">additional allowed character</a>.</p>
                   2176: 
                   2177:   <p>If nothing is returned, emit a U+0026 AMPERSAND character
                   2178:   token.</p>
                   2179: 
                   2180:   <p>Otherwise, emit the character token that was returned.</p>
                   2181: 
                   2182:   <p>Finally, switch to the <a href="#data-state">data state</a>.</p>
                   2183: 
                   2184: 
                   2185:   <h5 id="tag-open-state"><span class="secno">9.2.4.3 </span><dfn>Tag open state</dfn></h5>
                   2186: 
                   2187:   <p>The behavior of this state depends on the <a href="#content-model-flag">content model
                   2188:   flag</a>.</p>
                   2189: 
                   2190:   <dl><dt>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA
1.91      mike     2191:    or RAWTEXT states</dt>
1.1       mike     2192: 
                   2193:    <dd>
                   2194: 
                   2195:     <p>Consume the <a href="#next-input-character">next input character</a>. If it is a
1.464     mike     2196:     U+002F SOLIDUS character (/), switch to the <a href="#close-tag-open-state">close tag open
1.1       mike     2197:     state</a>. Otherwise, emit a U+003C LESS-THAN SIGN character
                   2198:     token and reconsume the <a href="#current-input-character">current input character</a> in the
                   2199:     <a href="#data-state">data state</a>.</p>
                   2200: 
                   2201:    </dd>
                   2202: 
                   2203:    <dt>If the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
                   2204:    state</dt>
                   2205: 
                   2206:    <dd>
                   2207: 
                   2208:     <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2209: 
                   2210:     <dl class="switch"><dt>U+0021 EXCLAMATION MARK (!)</dt>
                   2211:      <dd>Switch to the <a href="#markup-declaration-open-state">markup declaration open state</a>.</dd>
                   2212: 
                   2213:      <dt>U+002F SOLIDUS (/)</dt>
                   2214:      <dd>Switch to the <a href="#close-tag-open-state">close tag open state</a>.</dd>
                   2215: 
                   2216:      <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2217:      <dd>Create a new start tag token, set its tag name to the
                   2218:      lowercase version of the input character (add 0x0020 to the
                   2219:      character's code point), then switch to the <a href="#tag-name-state">tag name
                   2220:      state</a>. (Don't emit the token yet; further details will
                   2221:      be filled in before it is emitted.)</dd>
                   2222: 
                   2223:      <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
                   2224:      <dd>Create a new start tag token, set its tag name to the input
                   2225:      character, then switch to the <a href="#tag-name-state">tag name
                   2226:      state</a>. (Don't emit the token yet; further details will
                   2227:      be filled in before it is emitted.)</dd>
                   2228: 
                   2229:      <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2230:      <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
                   2231:      character token and a U+003E GREATER-THAN SIGN character
                   2232:      token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2233: 
                   2234:      <dt>U+003F QUESTION MARK (?)</dt>
                   2235:      <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
                   2236:      comment state</a>.</dd>
                   2237: 
                   2238:      <dt>Anything else</dt>
                   2239:      <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
                   2240:      character token and reconsume the <a href="#current-input-character">current input character</a> in the
                   2241:      <a href="#data-state">data state</a>.</dd>
                   2242: 
                   2243:     </dl></dd>
                   2244: 
                   2245:   </dl><h5 id="close-tag-open-state"><span class="secno">9.2.4.4 </span><dfn>Close tag open state</dfn></h5>
                   2246: 
                   2247:   <p>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA or
1.91      mike     2248:   RAWTEXT states but no start tag token has ever been emitted by this
1.1       mike     2249:   instance of the tokenizer (<a href="#fragment-case">fragment case</a>), or, if the
1.91      mike     2250:   <a href="#content-model-flag">content model flag</a> is set to the RCDATA or RAWTEXT states
1.1       mike     2251:   and the next few characters do not match the tag name of the last
                   2252:   start tag token emitted (compared in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   2253:   case-insensitive</a> manner), or if they do but they are not
                   2254:   immediately followed by one of the following characters:</p>
                   2255: 
                   2256:   <ul class="brief"><li>U+0009 CHARACTER TABULATION</li>
                   2257:    <li>U+000A LINE FEED (LF)</li>
                   2258:    <li>U+000C FORM FEED (FF)</li>
                   2259:    <!--<li>U+000D CARRIAGE RETURN (CR)</li>-->
                   2260:    <li>U+0020 SPACE</li>
                   2261:    <li>U+003E GREATER-THAN SIGN (&gt;)</li>
                   2262:    <li>U+002F SOLIDUS (/)</li>
                   2263:    <li>EOF</li>
                   2264:   </ul><p>...then emit a U+003C LESS-THAN SIGN character token, a U+002F
                   2265:   SOLIDUS character token, and switch to the <a href="#data-state">data state</a>
                   2266:   to process the <a href="#next-input-character">next input character</a>.</p>
                   2267: 
                   2268:   <p>Otherwise, if the <a href="#content-model-flag">content model flag</a> is set to the
                   2269:   PCDATA state, or if the next few characters <em>do</em> match that tag
                   2270:   name, consume the <a href="#next-input-character">next input character</a>:</p>
                   2271: 
                   2272:   <dl class="switch"><dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2273:    <dd>Create a new end tag token, set its tag name to the lowercase
                   2274:    version of the input character (add 0x0020 to the character's
                   2275:    code point), then switch to the <a href="#tag-name-state">tag name
                   2276:    state</a>. (Don't emit the token yet; further details will be
                   2277:    filled in before it is emitted.)</dd>
                   2278: 
                   2279:    <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
                   2280:    <dd>Create a new end tag token, set its tag name to the input
                   2281:    character, then switch to the <a href="#tag-name-state">tag name state</a>. (Don't
                   2282:    emit the token yet; further details will be filled in before it
                   2283:    is emitted.)</dd>
                   2284: 
                   2285:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2286:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#data-state">data
                   2287:    state</a>.</dd>
                   2288: 
                   2289:    <dt>EOF</dt>
                   2290:    <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
                   2291:    character token and a U+002F SOLIDUS character token. Reconsume
                   2292:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2293: 
                   2294:    <dt>Anything else</dt>
                   2295:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
                   2296:    comment state</a>.</dd>
                   2297: 
                   2298:   </dl><h5 id="tag-name-state"><span class="secno">9.2.4.5 </span><dfn>Tag name state</dfn></h5>
                   2299: 
                   2300:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2301: 
                   2302:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2303:    <dt>U+000A LINE FEED (LF)</dt>
                   2304:    <dt>U+000C FORM FEED (FF)</dt>
                   2305:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2306:    <dt>U+0020 SPACE</dt>
                   2307:    <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2308: 
                   2309:    <dt>U+002F SOLIDUS (/)</dt>
                   2310:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2311: 
                   2312:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2313:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2314:    state</a>.</dd>
                   2315: 
                   2316:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2317:    <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
                   2318:    (add 0x0020 to the character's code point) to the current tag
                   2319:    token's tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
                   2320: 
                   2321:    <dt>EOF</dt>
                   2322:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2323:    <a href="#data-state">data state</a>.</dd>
                   2324: 
                   2325:    <dt>Anything else</dt>
                   2326:    <dd>Append the <a href="#current-input-character">current input character</a> to the current tag token's
                   2327:    tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
                   2328: 
                   2329:   </dl><h5 id="before-attribute-name-state"><span class="secno">9.2.4.6 </span><dfn>Before attribute name state</dfn></h5>
                   2330: 
                   2331:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2332: 
                   2333:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2334:    <dt>U+000A LINE FEED (LF)</dt>
                   2335:    <dt>U+000C FORM FEED (FF)</dt>
                   2336:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2337:    <dt>U+0020 SPACE</dt>
                   2338:    <dd>Stay in the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2339: 
                   2340:    <dt>U+002F SOLIDUS (/)</dt>
                   2341:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2342: 
                   2343:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2344:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2345:    state</a>.</dd>
                   2346: 
                   2347:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2348:    <dd>Start a new attribute in the current tag token. Set that
                   2349:    attribute's name to the lowercase version of the <a href="#current-input-character">current input
                   2350:    character</a> (add 0x0020 to the character's code point), and its
                   2351:    value to the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2352:    state</a>.</dd>
                   2353: 
                   2354:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2355:    <dt>U+0027 APOSTROPHE (')</dt>
                   2356:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2357:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2358:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2359:    entry below.</dd>
                   2360: 
                   2361:    <dt>EOF</dt>
                   2362:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2363:    <a href="#data-state">data state</a>.</dd>
                   2364: 
                   2365:    <dt>Anything else</dt>
                   2366:    <dd>Start a new attribute in the current tag token. Set that
                   2367:    attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
                   2368:    the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2369:    state</a>.</dd>
                   2370: 
                   2371:   </dl><h5 id="attribute-name-state"><span class="secno">9.2.4.7 </span><dfn>Attribute name state</dfn></h5>
                   2372: 
                   2373:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2374: 
                   2375:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2376:    <dt>U+000A LINE FEED (LF)</dt>
                   2377:    <dt>U+000C FORM FEED (FF)</dt>
                   2378:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2379:    <dt>U+0020 SPACE</dt>
                   2380:    <dd>Switch to the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
                   2381: 
                   2382:    <dt>U+002F SOLIDUS (/)</dt>
                   2383:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2384: 
                   2385:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2386:    <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
                   2387: 
                   2388:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2389:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2390:    state</a>.</dd>
                   2391: 
                   2392:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2393:    <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
                   2394:    (add 0x0020 to the character's code point) to the current
                   2395:    attribute's name. Stay in the <a href="#attribute-name-state">attribute name
                   2396:    state</a>.</dd>
                   2397: 
                   2398:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2399:    <dt>U+0027 APOSTROPHE (')</dt>
                   2400:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2401:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2402:    entry below.</dd>
                   2403: 
                   2404:    <dt>EOF</dt>
                   2405:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2406:    <a href="#data-state">data state</a>.</dd>
                   2407: 
                   2408:    <dt>Anything else</dt>
                   2409:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2410:    name. Stay in the <a href="#attribute-name-state">attribute name state</a>.</dd>
                   2411: 
                   2412:   </dl><p>When the user agent leaves the attribute name state (and before
                   2413:   emitting the tag token, if appropriate), the complete attribute's
                   2414:   name must be compared to the other attributes on the same token;
                   2415:   if there is already an attribute on the token with the exact same
                   2416:   name, then this is a <a href="#parse-error">parse error</a> and the new
                   2417:   attribute must be dropped, along with the value that gets
                   2418:   associated with it (if any).</p>
                   2419: 
                   2420: 
                   2421:   <h5 id="after-attribute-name-state"><span class="secno">9.2.4.8 </span><dfn>After attribute name state</dfn></h5>
                   2422: 
                   2423:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2424: 
                   2425:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2426:    <dt>U+000A LINE FEED (LF)</dt>
                   2427:    <dt>U+000C FORM FEED (FF)</dt>
                   2428:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2429:    <dt>U+0020 SPACE</dt>
                   2430:    <dd>Stay in the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
                   2431: 
                   2432:    <dt>U+002F SOLIDUS (/)</dt>
                   2433:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2434: 
                   2435:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2436:    <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
                   2437: 
                   2438:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2439:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2440:    state</a>.</dd>
                   2441: 
                   2442:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2443:    <dd>Start a new attribute in the current tag token. Set that
                   2444:    attribute's name to the lowercase version of the <a href="#current-input-character">current input character</a>
                   2445:    (add 0x0020 to the character's code point), and its value to
                   2446:    the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2447:    state</a>.</dd>
                   2448: 
                   2449:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2450:    <dt>U+0027 APOSTROPHE (')</dt>
                   2451:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2452:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2453:    entry below.</dd>
                   2454: 
                   2455:    <dt>EOF</dt>
                   2456:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2457:    <a href="#data-state">data state</a>.</dd>
                   2458: 
                   2459:    <dt>Anything else</dt>
                   2460:    <dd>Start a new attribute in the current tag token. Set that
                   2461:    attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
                   2462:    the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2463:    state</a>.</dd>
                   2464: 
                   2465:   </dl><h5 id="before-attribute-value-state"><span class="secno">9.2.4.9 </span><dfn>Before attribute value state</dfn></h5>
                   2466: 
                   2467:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2468: 
                   2469:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2470:    <dt>U+000A LINE FEED (LF)</dt>
                   2471:    <dt>U+000C FORM FEED (FF)</dt>
                   2472:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2473:    <dt>U+0020 SPACE</dt>
                   2474:    <dd>Stay in the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
                   2475: 
                   2476:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2477:    <dd>Switch to the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted) state</a>.</dd>
                   2478: 
                   2479:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2480:    <dd>Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted) state</a>
                   2481:    and reconsume this input character.</dd>
                   2482: 
                   2483:    <dt>U+0027 APOSTROPHE (')</dt>
                   2484:    <dd>Switch to the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted) state</a>.</dd>
                   2485: 
                   2486:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2487:    <dd><a href="#parse-error">Parse error</a>. Emit the current tag token. Switch to
                   2488:    the <a href="#data-state">data state</a>.</dd>
                   2489: 
                   2490:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2491:    <dt>U+003D EQUALS SIGN (=)</dt>
1.463     mike     2492:    <dt>U+0060 GRAVE ACCENT (`)</dt>
1.1       mike     2493:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2494:    entry below.</dd>
                   2495: 
                   2496:    <dt>EOF</dt>
                   2497:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2498:    <a href="#data-state">data state</a>.</dd>
                   2499: 
                   2500:    <dt>Anything else</dt>
                   2501:    <dd>Append the <a href="#current-input-character">current input character</a> to the current
                   2502:    attribute's value. Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
                   2503:    state</a>.</dd>
                   2504: 
                   2505:   </dl><h5 id="attribute-value-double-quoted-state"><span class="secno">9.2.4.10 </span><dfn>Attribute value (double-quoted) state</dfn></h5>
                   2506: 
                   2507:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2508: 
                   2509:   <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
                   2510:    <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
                   2511:    state</a>.</dd>
                   2512: 
                   2513:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2514:    <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
                   2515:    state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
                   2516:    being U+0022 QUOTATION MARK (").</dd>
                   2517: 
                   2518:    <dt>EOF</dt>
                   2519:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2520:    <a href="#data-state">data state</a>.</dd>
                   2521: 
                   2522:    <dt>Anything else</dt>
                   2523:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2524:    value. Stay in the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted)
                   2525:    state</a>.</dd>
                   2526: 
                   2527:   </dl><h5 id="attribute-value-single-quoted-state"><span class="secno">9.2.4.11 </span><dfn>Attribute value (single-quoted) state</dfn></h5>
                   2528: 
                   2529:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2530: 
                   2531:   <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
                   2532:    <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
                   2533:    state</a>.</dd>
                   2534: 
                   2535:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2536:    <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
                   2537:    state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
                   2538:    being U+0027 APOSTROPHE (').</dd>
                   2539: 
                   2540:    <dt>EOF</dt>
                   2541:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2542:    <a href="#data-state">data state</a>.</dd>
                   2543: 
                   2544:    <dt>Anything else</dt>
                   2545:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2546:    value. Stay in the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted)
                   2547:    state</a>.</dd>
                   2548: 
                   2549:   </dl><h5 id="attribute-value-unquoted-state"><span class="secno">9.2.4.12 </span><dfn>Attribute value (unquoted) state</dfn></h5>
                   2550: 
                   2551:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2552: 
                   2553:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2554:    <dt>U+000A LINE FEED (LF)</dt>
                   2555:    <dt>U+000C FORM FEED (FF)</dt>
                   2556:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2557:    <dt>U+0020 SPACE</dt>
                   2558:    <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2559: 
                   2560:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2561:    <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
1.299     mike     2562:    state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
                   2563:    being U+003E GREATER-THAN SIGN (&gt;).</dd>
1.1       mike     2564: 
                   2565:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2566:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2567:    state</a>.</dd>
                   2568: 
                   2569:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2570:    <dt>U+0027 APOSTROPHE (')</dt>
                   2571:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2572:    <dt>U+003D EQUALS SIGN (=)</dt>
1.463     mike     2573:    <dt>U+0060 GRAVE ACCENT (`)</dt>
1.1       mike     2574:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2575:    entry below.</dd>
                   2576: 
                   2577:    <dt>EOF</dt>
                   2578:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2579:    <a href="#data-state">data state</a>.</dd>
                   2580: 
                   2581:    <dt>Anything else</dt>
                   2582:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2583:    value. Stay in the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
                   2584:    state</a>.</dd>
                   2585: 
                   2586:   </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>
                   2587: 
                   2588:   <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>.</p>
                   2589: 
                   2590:   <p>If nothing is returned, append a U+0026 AMPERSAND character to
                   2591:   the current attribute's value.</p>
                   2592: 
                   2593:   <p>Otherwise, append the returned character token to the current
                   2594:   attribute's value.</p>
                   2595: 
                   2596:   <p>Finally, switch back to the attribute value state that you were
                   2597:   in when were switched into this state.</p>
                   2598: 
                   2599: 
                   2600:   <h5 id="after-attribute-value-quoted-state"><span class="secno">9.2.4.14 </span><dfn>After attribute value (quoted) state</dfn></h5>
                   2601: 
                   2602:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2603: 
                   2604:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2605:    <dt>U+000A LINE FEED (LF)</dt>
                   2606:    <dt>U+000C FORM FEED (FF)</dt>
                   2607:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2608:    <dt>U+0020 SPACE</dt>
                   2609:    <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2610: 
                   2611:    <dt>U+002F SOLIDUS (/)</dt>
                   2612:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2613: 
                   2614:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2615:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2616:    state</a>.</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><a href="#parse-error">Parse error</a>. Reconsume the character in
                   2624:    the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2625: 
                   2626:   </dl><h5 id="self-closing-start-tag-state"><span class="secno">9.2.4.15 </span><dfn>Self-closing start tag state</dfn></h5>
                   2627: 
                   2628:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2629: 
                   2630:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2631:    <dd>Set the <i>self-closing flag</i> of the current tag
                   2632:    token. Emit the current tag token. Switch to the <a href="#data-state">data
                   2633:    state</a>.</dd>
                   2634: 
                   2635:    <dt>EOF</dt>
                   2636:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2637:    <a href="#data-state">data state</a>.</dd>
                   2638: 
                   2639:    <dt>Anything else</dt>
                   2640:    <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
                   2641:    the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2642: 
                   2643:   </dl><h5 id="bogus-comment-state"><span class="secno">9.2.4.16 </span><dfn>Bogus comment state</dfn></h5>
                   2644: 
                   2645:   <p><i>(This can only happen if the <a href="#content-model-flag">content model
                   2646:   flag</a> is set to the PCDATA state.)</i></p>
                   2647: 
                   2648:   <p>Consume every character up to and including the first U+003E
                   2649:   GREATER-THAN SIGN character (&gt;) or the end of the file (EOF),
                   2650:   whichever comes first. Emit a comment token whose data is the
                   2651:   concatenation of all the characters starting from and including
                   2652:   the character that caused the state machine to switch into the
                   2653:   bogus comment state, up to and including the character immediately
                   2654:   before the last consumed character (i.e. up to the character just
                   2655:   before the U+003E or EOF character). (If the comment was started
                   2656:   by the end of the file (EOF), the token is empty.)</p>
                   2657: 
                   2658:   <p>Switch to the <a href="#data-state">data state</a>.</p>
                   2659: 
                   2660:   <p>If the end of the file was reached, reconsume the EOF
                   2661:   character.</p>
                   2662: 
                   2663: 
                   2664:   <h5 id="markup-declaration-open-state"><span class="secno">9.2.4.17 </span><dfn>Markup declaration open state</dfn></h5>
                   2665: 
                   2666:   <p><i>(This can only happen if the <a href="#content-model-flag">content model
                   2667:   flag</a> is set to the PCDATA state.)</i></p>
                   2668: 
                   2669:   <p>If the next two characters are both U+002D HYPHEN-MINUS (-)
                   2670:   characters, consume those two characters, create a comment token
                   2671:   whose data is the empty string, and switch to the <a href="#comment-start-state">comment
                   2672:   start state</a>.</p>
                   2673: 
                   2674:   <p>Otherwise, if the next seven characters are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   2675:   case-insensitive</a> match for the word "DOCTYPE", then consume
                   2676:   those characters and switch to the <a href="#doctype-state">DOCTYPE state</a>.</p>
                   2677: 
                   2678:   <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
                   2679:   content</a>" and the <a href="#current-node">current node</a> is not an element
                   2680:   in the <a href="#html-namespace-0">HTML namespace</a> and the next seven characters are
                   2681:   an <span>ASCII case-sensitive</span> match for the string "[CDATA["
                   2682:   (the five uppercase letters "CDATA" with a U+005B LEFT SQUARE
                   2683:   BRACKET character before and after), then consume those characters
1.91      mike     2684:   and switch to the <a href="#cdata-section-state">CDATA section state</a>.</p>
1.1       mike     2685: 
                   2686:   <p>Otherwise, this is a <a href="#parse-error">parse error</a>. Switch to the
                   2687:   <a href="#bogus-comment-state">bogus comment state</a>. The next character that is
                   2688:   consumed, if any, is the first character that will be in the
                   2689:   comment.</p>
                   2690: 
                   2691: 
                   2692:   <h5 id="comment-start-state"><span class="secno">9.2.4.18 </span><dfn>Comment start state</dfn></h5>
                   2693: 
                   2694:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2695: 
                   2696:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2697:    <dd>Switch to the <a href="#comment-start-dash-state">comment start dash state</a>.</dd>
                   2698: 
                   2699:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2700:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to the
                   2701:    <a href="#data-state">data state</a>.</dd> <!-- see comment in comment end state
                   2702:    -->
                   2703: 
                   2704:    <dt>EOF</dt>
                   2705:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2706:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2707: 
                   2708:    <dt>Anything else</dt>
                   2709:    <dd>Append the input character to the comment token's
                   2710:    data. Switch to the <a href="#comment-state">comment state</a>.</dd>
                   2711: 
                   2712:   </dl><h5 id="comment-start-dash-state"><span class="secno">9.2.4.19 </span><dfn>Comment start dash state</dfn></h5>
                   2713: 
                   2714:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2715: 
                   2716:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2717:    <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
                   2718: 
                   2719:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2720:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to
                   2721:    the <a href="#data-state">data state</a>.</dd>
                   2722: 
                   2723:    <dt>EOF</dt>
                   2724:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
                   2725:    EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
                   2726:    in comment end state -->
                   2727: 
                   2728:    <dt>Anything else</dt>
1.464     mike     2729:    <dd>Append a U+002D HYPHEN-MINUS character (-) and the input
1.1       mike     2730:    character to the comment token's data. Switch to the
                   2731:    <a href="#comment-state">comment state</a>.</dd>
                   2732: 
                   2733:   </dl><h5 id="comment-state"><span class="secno">9.2.4.20 </span><dfn id="comment">Comment state</dfn></h5>
                   2734: 
                   2735:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2736: 
                   2737:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2738:    <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a></dd>
                   2739: 
                   2740:    <dt>EOF</dt>
                   2741:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
                   2742:    EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
                   2743:    in comment end state -->
                   2744: 
                   2745:    <dt>Anything else</dt>
                   2746:    <dd>Append the input character to the comment token's data. Stay
                   2747:    in the <a href="#comment-state">comment state</a>.</dd>
                   2748: 
                   2749:   </dl><h5 id="comment-end-dash-state"><span class="secno">9.2.4.21 </span><dfn>Comment end dash state</dfn></h5>
                   2750: 
                   2751:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2752: 
                   2753:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2754:    <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
                   2755: 
                   2756:    <dt>EOF</dt>
                   2757:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
                   2758:    EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
                   2759:    in comment end state -->
                   2760: 
                   2761:    <dt>Anything else</dt>
1.464     mike     2762:    <dd>Append a U+002D HYPHEN-MINUS character (-) and the input
1.1       mike     2763:    character to the comment token's data. Switch to the
                   2764:    <a href="#comment-state">comment state</a>.</dd>
                   2765: 
                   2766:   </dl><h5 id="comment-end-state"><span class="secno">9.2.4.22 </span><dfn>Comment end state</dfn></h5>
                   2767: 
                   2768:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2769: 
                   2770:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2771:    <dd>Emit the comment token. Switch to the <a href="#data-state">data
                   2772:    state</a>.</dd>
                   2773: 
                   2774:    <dt>U+0009 CHARACTER TABULATION</dt>
                   2775:    <dt>U+000A LINE FEED (LF)</dt>
                   2776:    <dt>U+000C FORM FEED (FF)</dt>
                   2777:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2778:    <dt>U+0020 SPACE</dt>
                   2779:    <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
                   2780:    characters and the input character to the comment token's
                   2781:    data. Switch to the <a href="#comment-end-space-state">comment end space state</a>.</dd>
                   2782: 
                   2783:    <dt>U+0021 EXCLAMATION MARK (!)</dt>
                   2784:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#comment-end-bang-state">comment end bang
                   2785:    state</a>.</dd>
                   2786: 
1.333     mike     2787:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2788:    <dd><a href="#parse-error">Parse error</a>. Append a U+002D HYPHEN-MINUS
1.464     mike     2789:    character (-) to the comment token's data. Stay in the
1.333     mike     2790:    <a href="#comment-end-state">comment end state</a>.</dd>
                   2791: 
1.1       mike     2792:    <dt>EOF</dt>
                   2793:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2794:    the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- For
                   2795:    security reasons: otherwise, hostile user could put a <script> in
                   2796:    a comment e.g. in a blog comment and then DOS the server so that
                   2797:    the end tag isn't read, and then the commented <script> tag would
                   2798:    be treated as live code -->
                   2799: 
                   2800:    <dt>Anything else</dt>
                   2801:    <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
                   2802:    characters and the input character to the comment token's
                   2803:    data. Switch to the <a href="#comment-state">comment state</a>.</dd>
                   2804: 
                   2805:   </dl><h5 id="comment-end-bang-state"><span class="secno">9.2.4.23 </span><dfn>Comment end bang state</dfn></h5>
                   2806: 
                   2807:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2808: 
1.333     mike     2809:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
1.1       mike     2810:    <dd>Append two U+002D HYPHEN-MINUS (-) characters and a U+0021
1.464     mike     2811:    EXCLAMATION MARK character (!) to the comment token's data. Switch
1.1       mike     2812:    to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
                   2813: 
1.333     mike     2814:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2815:    <dd>Emit the comment token. Switch to the <a href="#data-state">data
                   2816:    state</a>.</dd>
                   2817: 
1.1       mike     2818:    <dt>EOF</dt>
                   2819:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2820:    the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
                   2821:    comment in comment end state -->
                   2822: 
                   2823:    <dt>Anything else</dt>
                   2824:    <dd>Append two U+002D HYPHEN-MINUS (-) characters, a U+0021
1.464     mike     2825:    EXCLAMATION MARK character (!), and the input character to the
1.1       mike     2826:    comment token's data. Switch to the <a href="#comment-state">comment
                   2827:    state</a>.</dd>
                   2828: 
                   2829:   </dl><h5 id="comment-end-space-state"><span class="secno">9.2.4.24 </span><dfn>Comment end space state</dfn></h5>
                   2830: 
                   2831:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2832: 
1.333     mike     2833:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
1.1       mike     2834:    <dt>U+000A LINE FEED (LF)</dt>
                   2835:    <dt>U+000C FORM FEED (FF)</dt>
                   2836:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2837:    <dt>U+0020 SPACE</dt>
                   2838:    <dd>Append the input character to the comment token's data. Stay in
                   2839:    the <a href="#comment-end-space-state">comment end space state</a>.</dd>
                   2840: 
1.333     mike     2841:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2842:    <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
                   2843: 
                   2844:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2845:    <dd>Emit the comment token. Switch to the <a href="#data-state">data
                   2846:    state</a>.</dd>
                   2847: 
1.1       mike     2848:    <dt>EOF</dt>
                   2849:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2850:    the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
                   2851:    comment in comment end state -->
                   2852: 
                   2853:    <dt>Anything else</dt>
                   2854:    <dd>Append the input character to the comment token's data. Switch
                   2855:    to the <a href="#comment-state">comment state</a>.</dd>
                   2856: 
                   2857:   </dl><h5 id="doctype-state"><span class="secno">9.2.4.25 </span><dfn>DOCTYPE state</dfn></h5>
                   2858: 
                   2859:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2860: 
                   2861:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2862:    <dt>U+000A LINE FEED (LF)</dt>
                   2863:    <dt>U+000C FORM FEED (FF)</dt>
                   2864:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2865:    <dt>U+0020 SPACE</dt>
                   2866:    <dd>Switch to the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
                   2867: 
                   2868:    <dt>EOF</dt>
                   2869:    <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
                   2870:    <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
                   2871:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2872: 
                   2873:    <dt>Anything else</dt>
                   2874:    <dd><a href="#parse-error">Parse error</a>. Reconsume the current
                   2875:    character in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
                   2876: 
                   2877:   </dl><h5 id="before-doctype-name-state"><span class="secno">9.2.4.26 </span><dfn>Before DOCTYPE name state</dfn></h5>
                   2878: 
                   2879:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2880: 
                   2881:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2882:    <dt>U+000A LINE FEED (LF)</dt>
                   2883:    <dt>U+000C FORM FEED (FF)</dt>
                   2884:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2885:    <dt>U+0020 SPACE</dt>
                   2886:    <dd>Stay in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
                   2887: 
                   2888:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2889:    <dd>Create a new DOCTYPE token. Set the token's name to the
                   2890:    lowercase version of the input character (add 0x0020 to the
                   2891:    character's code point). Switch to the <a href="#doctype-name-state">DOCTYPE name
                   2892:    state</a>.</dd>
                   2893: 
1.333     mike     2894:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2895:    <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
                   2896:    <i>force-quirks flag</i> to <i>on</i>. Emit the token. Switch to
                   2897:    the <a href="#data-state">data state</a>.</dd>
                   2898: 
1.1       mike     2899:    <dt>EOF</dt>
                   2900:    <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
                   2901:    <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
                   2902:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2903: 
                   2904:    <dt>Anything else</dt>
                   2905:    <dd>Create a new DOCTYPE token. Set the token's name to the
                   2906:    <a href="#current-input-character">current input character</a>. Switch to the <a href="#doctype-name-state">DOCTYPE name
                   2907:    state</a>.</dd>
                   2908: 
                   2909:   </dl><h5 id="doctype-name-state"><span class="secno">9.2.4.27 </span><dfn>DOCTYPE name state</dfn></h5>
                   2910: 
                   2911:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2912: 
                   2913:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2914:    <dt>U+000A LINE FEED (LF)</dt>
                   2915:    <dt>U+000C FORM FEED (FF)</dt>
                   2916:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2917:    <dt>U+0020 SPACE</dt>
                   2918:    <dd>Switch to the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
                   2919: 
                   2920:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2921:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   2922:    state</a>.</dd>
                   2923: 
                   2924:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2925:    <dd>Append the lowercase version of the input character (add 0x0020
                   2926:    to the character's code point) to the current DOCTYPE token's
                   2927:    name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
                   2928: 
                   2929:    <dt>EOF</dt>
                   2930:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2931:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2932:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2933: 
                   2934:    <dt>Anything else</dt>
                   2935:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   2936:    token's name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
                   2937: 
                   2938:   </dl><h5 id="after-doctype-name-state"><span class="secno">9.2.4.28 </span><dfn>After DOCTYPE name state</dfn></h5>
                   2939: 
                   2940:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2941: 
                   2942:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2943:    <dt>U+000A LINE FEED (LF)</dt>
                   2944:    <dt>U+000C FORM FEED (FF)</dt>
                   2945:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2946:    <dt>U+0020 SPACE</dt>
                   2947:    <dd>Stay in the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
                   2948: 
                   2949:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2950:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   2951:    state</a>.</dd>
                   2952: 
                   2953:    <dt>EOF</dt>
                   2954:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2955:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2956:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2957: 
                   2958:    <dt>Anything else</dt>
                   2959:    <dd>
                   2960: 
                   2961:     <p>If the six characters starting from the <a href="#current-input-character">current input
                   2962:     character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match
                   2963:     for the word "PUBLIC", then consume those characters and switch to
1.444     mike     2964:     the <a href="#after-doctype-public-keyword-state">after DOCTYPE public keyword state</a>.</p>
1.1       mike     2965: 
                   2966:     <p>Otherwise, if the six characters starting from the
                   2967:     <a href="#current-input-character">current input character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   2968:     case-insensitive</a> match for the word "SYSTEM", then consume
1.444     mike     2969:     those characters and switch to the <a href="#after-doctype-system-keyword-state">after DOCTYPE system
                   2970:     keyword state</a>.</p>
1.1       mike     2971: 
                   2972:     <p>Otherwise, this is the <a href="#parse-error">parse error</a>. Set the
                   2973:     DOCTYPE token's <i>force-quirks flag</i> to <i>on</i>. Switch to
                   2974:     the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</p>
                   2975: 
                   2976:    </dd>
                   2977: 
1.444     mike     2978:   </dl><h5 id="after-doctype-public-keyword-state"><span class="secno">9.2.4.29 </span><dfn>After DOCTYPE public keyword state</dfn></h5>
                   2979: 
                   2980:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2981: 
                   2982:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2983:    <dt>U+000A LINE FEED (LF)</dt>
                   2984:    <dt>U+000C FORM FEED (FF)</dt>
                   2985:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2986:    <dt>U+0020 SPACE</dt>
                   2987:    <dd>Switch to the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier
                   2988:    state</a>.</dd>
                   2989: 
                   2990:    <dt>EOF</dt>
                   2991:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2992:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2993:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2994: 
                   2995:    <dt>Anything else</dt>
                   2996:    <dd><a href="#parse-error">Parse error</a>. Reconsume the current character in
                   2997:    the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</dd>
                   2998: 
                   2999:   </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     3000: 
                   3001:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3002: 
                   3003:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3004:    <dt>U+000A LINE FEED (LF)</dt>
                   3005:    <dt>U+000C FORM FEED (FF)</dt>
                   3006:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3007:    <dt>U+0020 SPACE</dt>
                   3008:    <dd>Stay in the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</dd>
                   3009: 
                   3010:    <dt>U+0022 QUOTATION MARK (")</dt>
                   3011:    <dd>Set the DOCTYPE token's public identifier to the empty string
                   3012:    (not missing), then switch to the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public identifier
                   3013:    (double-quoted) state</a>.</dd>
                   3014: 
                   3015:    <dt>U+0027 APOSTROPHE (')</dt>
                   3016:    <dd>Set the DOCTYPE token's public identifier to the empty string
                   3017:    (not missing), then switch to the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public identifier
                   3018:    (single-quoted) state</a>.</dd>
                   3019: 
                   3020:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3021:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3022:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3023:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3024: 
                   3025:    <dt>EOF</dt>
                   3026:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3027:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3028:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3029: 
                   3030:    <dt>Anything else</dt>
                   3031:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3032:    <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
                   3033:    DOCTYPE state</a>.</dd>
                   3034: 
1.444     mike     3035:   </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     3036: 
                   3037:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3038: 
                   3039:   <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
                   3040:    <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
                   3041: 
                   3042:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3043:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3044:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3045:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3046: 
                   3047:    <dt>EOF</dt>
                   3048:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3049:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3050:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3051: 
                   3052:    <dt>Anything else</dt>
                   3053:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   3054:    token's public identifier. Stay in the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public
                   3055:    identifier (double-quoted) state</a>.</dd>
                   3056: 
1.444     mike     3057:   </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     3058: 
                   3059:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3060: 
                   3061:   <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
                   3062:    <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
                   3063: 
                   3064:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3065:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3066:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3067:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3068: 
                   3069:    <dt>EOF</dt>
                   3070:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3071:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3072:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3073: 
                   3074:    <dt>Anything else</dt>
                   3075:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   3076:    token's public identifier. Stay in the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public
                   3077:    identifier (single-quoted) state</a>.</dd>
                   3078: 
1.444     mike     3079:   </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     3080: 
                   3081:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3082: 
                   3083:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3084:    <dt>U+000A LINE FEED (LF)</dt>
                   3085:    <dt>U+000C FORM FEED (FF)</dt>
                   3086:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3087:    <dt>U+0020 SPACE</dt>
1.444     mike     3088:    <dd>Switch to the <a href="#between-doctype-public-and-system-identifiers-state">between DOCTYPE public and system identifiers state</a>.</dd>
                   3089: 
                   3090:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3091:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   3092:    state</a>.</dd>
                   3093: 
                   3094:    <dt>U+0022 QUOTATION MARK (")</dt>
                   3095:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's system
                   3096:    identifier to the empty string (not missing), then switch to the
                   3097:    <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier (double-quoted) state</a>.</dd>
                   3098: 
                   3099:    <dt>U+0027 APOSTROPHE (')</dt>
                   3100:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's system
                   3101:    identifier to the empty string (not missing), then switch to the
                   3102:    <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier (single-quoted) state</a>.</dd>
                   3103: 
                   3104:    <dt>EOF</dt>
                   3105:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3106:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3107:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3108: 
                   3109:    <dt>Anything else</dt>
                   3110:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3111:    <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
                   3112:    DOCTYPE state</a>.</dd>
                   3113: 
                   3114:   </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>
                   3115: 
                   3116:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3117: 
                   3118:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3119:    <dt>U+000A LINE FEED (LF)</dt>
                   3120:    <dt>U+000C FORM FEED (FF)</dt>
                   3121:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3122:    <dt>U+0020 SPACE</dt>
                   3123:    <dd>Stay in the <a href="#between-doctype-public-and-system-identifiers-state">between DOCTYPE public and system identifiers state</a>.</dd>
                   3124: 
                   3125:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3126:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   3127:    state</a>.</dd>
1.1       mike     3128: 
                   3129:    <dt>U+0022 QUOTATION MARK (")</dt>
                   3130:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   3131:    (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
                   3132:    (double-quoted) state</a>.</dd>
                   3133: 
                   3134:    <dt>U+0027 APOSTROPHE (')</dt>
                   3135:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   3136:    (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
                   3137:    (single-quoted) state</a>.</dd>
                   3138: 
                   3139:    <dt>EOF</dt>
                   3140:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3141:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3142:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3143: 
                   3144:    <dt>Anything else</dt>
                   3145:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3146:    <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
                   3147:    DOCTYPE state</a>.</dd>
                   3148: 
1.444     mike     3149:   </dl><h5 id="after-doctype-system-keyword-state"><span class="secno">9.2.4.35 </span><dfn>After DOCTYPE system keyword state</dfn></h5>
                   3150: 
                   3151:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3152: 
                   3153:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3154:    <dt>U+000A LINE FEED (LF)</dt>
                   3155:    <dt>U+000C FORM FEED (FF)</dt>
                   3156:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3157:    <dt>U+0020 SPACE</dt>
                   3158:    <dd>Switch to the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier
                   3159:    state</a>.</dd>
                   3160: 
                   3161:    <dt>EOF</dt>
                   3162:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3163:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3164:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3165: 
                   3166:    <dt>Anything else</dt>
                   3167:    <dd><a href="#parse-error">Parse error</a>. Reconsume the current character in
                   3168:    the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier state</a>.</dd>
                   3169: 
                   3170:   </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     3171: 
                   3172:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3173: 
                   3174:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3175:    <dt>U+000A LINE FEED (LF)</dt>
                   3176:    <dt>U+000C FORM FEED (FF)</dt>
                   3177:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3178:    <dt>U+0020 SPACE</dt>
                   3179:    <dd>Stay in the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier state</a>.</dd>
                   3180: 
                   3181:    <dt>U+0022 QUOTATION MARK (")</dt>
                   3182:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   3183:    (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
                   3184:    (double-quoted) state</a>.</dd>
                   3185: 
                   3186:    <dt>U+0027 APOSTROPHE (')</dt>
                   3187:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   3188:    (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
                   3189:    (single-quoted) state</a>.</dd>
                   3190: 
                   3191:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3192:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3193:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3194:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3195: 
                   3196:    <dt>EOF</dt>
                   3197:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3198:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3199:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3200: 
                   3201:    <dt>Anything else</dt>
                   3202:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3203:    <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
                   3204:    DOCTYPE state</a>.</dd>
                   3205: 
1.444     mike     3206:   </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     3207: 
                   3208:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3209: 
                   3210:   <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
                   3211:    <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
                   3212: 
                   3213:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3214:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3215:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3216:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3217: 
                   3218:    <dt>EOF</dt>
                   3219:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3220:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3221:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3222: 
                   3223:    <dt>Anything else</dt>
                   3224:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   3225:    token's system identifier. Stay in the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system
                   3226:    identifier (double-quoted) state</a>.</dd>
                   3227: 
1.444     mike     3228:   </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     3229: 
                   3230:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3231: 
                   3232:   <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
                   3233:    <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
                   3234: 
                   3235:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3236:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3237:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3238:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3239: 
                   3240:    <dt>EOF</dt>
                   3241:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3242:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3243:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3244: 
                   3245:    <dt>Anything else</dt>
                   3246:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   3247:    token's system identifier. Stay in the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system
                   3248:    identifier (single-quoted) state</a>.</dd>
                   3249: 
1.444     mike     3250:   </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     3251: 
                   3252:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3253: 
                   3254:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3255:    <dt>U+000A LINE FEED (LF)</dt>
                   3256:    <dt>U+000C FORM FEED (FF)</dt>
                   3257:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3258:    <dt>U+0020 SPACE</dt>
                   3259:    <dd>Stay in the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
                   3260: 
                   3261:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3262:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   3263:    state</a>.</dd>
                   3264: 
                   3265:    <dt>EOF</dt>
                   3266:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3267:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3268:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3269: 
                   3270:    <dt>Anything else</dt>
                   3271:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-doctype-state">bogus DOCTYPE
                   3272:    state</a>. (This does <em>not</em> set the DOCTYPE token's
                   3273:    <i>force-quirks flag</i> to <i>on</i>.)</dd>
                   3274: 
1.444     mike     3275:   </dl><h5 id="bogus-doctype-state"><span class="secno">9.2.4.40 </span><dfn>Bogus DOCTYPE state</dfn></h5>
1.1       mike     3276: 
                   3277:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3278: 
                   3279:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3280:    <dd>Emit the DOCTYPE token. Switch to the <a href="#data-state">data
                   3281:    state</a>.</dd>
                   3282: 
                   3283:    <dt>EOF</dt>
                   3284:    <dd>Emit the DOCTYPE token. Reconsume the EOF character in the
                   3285:    <a href="#data-state">data state</a>.</dd>
                   3286: 
                   3287:    <dt>Anything else</dt>
                   3288:    <dd>Stay in the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</dd>
                   3289: 
1.444     mike     3290:   </dl><h5 id="cdata-section-state"><span class="secno">9.2.4.41 </span><dfn>CDATA section state</dfn></h5>
1.1       mike     3291: 
                   3292:   <p><i>(This can only happen if the <a href="#content-model-flag">content model
1.91      mike     3293:   flag</a> is set to the PCDATA state.)</i></p>
1.1       mike     3294: 
                   3295:   <p>Consume every character up to the next occurrence of the three
                   3296:   character sequence U+005D RIGHT SQUARE BRACKET U+005D RIGHT SQUARE
                   3297:   BRACKET U+003E GREATER-THAN SIGN (<code title="">]]&gt;</code>), or the
                   3298:   end of the file (EOF), whichever comes first. Emit a series of
                   3299:   character tokens consisting of all the characters consumed except
                   3300:   the matching three character sequence at the end (if one was found
                   3301:   before the end of the file).</p>
                   3302: 
                   3303:   <p>Switch to the <a href="#data-state">data state</a>.</p>
                   3304: 
                   3305:   <p>If the end of the file was reached, reconsume the EOF
                   3306:   character.</p>
                   3307: 
                   3308: 
                   3309: 
1.444     mike     3310:   <h5 id="tokenizing-character-references"><span class="secno">9.2.4.42 </span>Tokenizing character references</h5>
1.1       mike     3311: 
                   3312:   <p>This section defines how to <dfn id="consume-a-character-reference">consume a character
                   3313:   reference</dfn>. This definition is used when parsing character
1.299     mike     3314:   references <a href="#character-reference-in-data-state" title="character reference in data state">in
1.1       mike     3315:   text</a> and <a href="#character-reference-in-attribute-value-state" title="character reference in attribute value
                   3316:   state">in attributes</a>.</p>
                   3317: 
                   3318:   <p>The behavior depends on the identity of the next character (the
                   3319:   one immediately after the U+0026 AMPERSAND character):</p>
                   3320: 
                   3321:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3322:    <dt>U+000A LINE FEED (LF)</dt>
                   3323:    <dt>U+000C FORM FEED (FF)</dt>
                   3324:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3325:    <dt>U+0020 SPACE</dt>
                   3326:    <dt>U+003C LESS-THAN SIGN</dt>
                   3327:    <dt>U+0026 AMPERSAND</dt>
                   3328:    <dt>EOF</dt>
                   3329:    <dt>The <dfn id="additional-allowed-character">additional allowed character</dfn>, if there is one</dt>
                   3330: 
                   3331:    <dd>Not a character reference. No characters are consumed, and
                   3332:    nothing is returned. (This is not an error, either.)</dd>
                   3333: 
                   3334: 
                   3335:    <dt>U+0023 NUMBER SIGN (#)</dt>
                   3336: 
                   3337:    <dd>
                   3338: 
                   3339:     <p>Consume the U+0023 NUMBER SIGN.</p>
                   3340: 
                   3341:     <p>The behavior further depends on the character after the U+0023
                   3342:     NUMBER SIGN:</p>
                   3343: 
                   3344:     <dl class="switch"><dt>U+0078 LATIN SMALL LETTER X</dt>
                   3345:      <dt>U+0058 LATIN CAPITAL LETTER X</dt>
                   3346: 
                   3347:      <dd>
                   3348: 
                   3349:       <p>Consume the X.</p>
                   3350: 
                   3351:       <p>Follow the steps below, but using the range of characters
1.464     mike     3352:       U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), U+0061 LATIN
                   3353:       SMALL LETTER A to U+0066 LATIN SMALL LETTER F, and U+0041 LATIN
                   3354:       CAPITAL LETTER A to U+0046 LATIN CAPITAL LETTER F (in other
                   3355:       words, 0-9, A-F, a-f).</p>
1.1       mike     3356: 
                   3357:       <p>When it comes to interpreting the number, interpret it as a
                   3358:       hexadecimal number.</p>
                   3359: 
                   3360:      </dd>
                   3361: 
                   3362: 
                   3363:      <dt>Anything else</dt>
                   3364: 
                   3365:      <dd>
                   3366: 
                   3367:       <p>Follow the steps below, but using the range of characters
1.464     mike     3368:       U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9).</p>
1.1       mike     3369: 
                   3370:       <p>When it comes to interpreting the number, interpret it as a
                   3371:       decimal number.</p>
                   3372: 
                   3373:      </dd>
                   3374: 
                   3375:     </dl><p>Consume as many characters as match the range of characters
                   3376:     given above.</p>
                   3377: 
                   3378:     <p>If no characters match the range, then don't consume any
                   3379:     characters (and unconsume the U+0023 NUMBER SIGN character and, if
                   3380:     appropriate, the X character). This is a <a href="#parse-error">parse
                   3381:     error</a>; nothing is returned.</p>
                   3382: 
                   3383:     <p>Otherwise, if the next character is a U+003B SEMICOLON, consume
                   3384:     that too. If it isn't, there is a <a href="#parse-error">parse
                   3385:     error</a>.</p>
                   3386: 
                   3387:     <p>If one or more characters match the range, then take them all
                   3388:     and interpret the string of characters as a number (either
                   3389:     hexadecimal or decimal as appropriate).</p>
                   3390: 
                   3391:     <p>If that number is one of the numbers in the first column of the
                   3392:     following table, then this is a <a href="#parse-error">parse error</a>. Find the
                   3393:     row with that number in the first column, and return a character
                   3394:     token for the Unicode character given in the second column of that
                   3395:     row.</p>
                   3396: 
                   3397:     <table><thead><tr><th>Number </th><th colspan="2">Unicode character
                   3398:      </th></tr></thead><tbody><tr><td>0x00 </td><td>U+FFFD </td><td>REPLACEMENT CHARACTER
                   3399:       </td></tr><tr><td>0x0D </td><td>U+000A </td><td>LINE FEED (LF)
1.464     mike     3400:       </td></tr><tr><td>0x80 </td><td>U+20AC </td><td>EURO SIGN (&#8364;)
1.1       mike     3401:       </td></tr><tr><td>0x81 </td><td>U+0081 </td><td>&lt;control&gt;
1.464     mike     3402:       </td></tr><tr><td>0x82 </td><td>U+201A </td><td>SINGLE LOW-9 QUOTATION MARK (&#8218;)
                   3403:       </td></tr><tr><td>0x83 </td><td>U+0192 </td><td>LATIN SMALL LETTER F WITH HOOK (&#402;)
                   3404:       </td></tr><tr><td>0x84 </td><td>U+201E </td><td>DOUBLE LOW-9 QUOTATION MARK (&#8222;)
                   3405:       </td></tr><tr><td>0x85 </td><td>U+2026 </td><td>HORIZONTAL ELLIPSIS (&#8230;)
                   3406:       </td></tr><tr><td>0x86 </td><td>U+2020 </td><td>DAGGER (&#8224;)
                   3407:       </td></tr><tr><td>0x87 </td><td>U+2021 </td><td>DOUBLE DAGGER (&#8225;)
                   3408:       </td></tr><tr><td>0x88 </td><td>U+02C6 </td><td>MODIFIER LETTER CIRCUMFLEX ACCENT (&#710;)
                   3409:       </td></tr><tr><td>0x89 </td><td>U+2030 </td><td>PER MILLE SIGN (&#8240;)
                   3410:       </td></tr><tr><td>0x8A </td><td>U+0160 </td><td>LATIN CAPITAL LETTER S WITH CARON (&#352;)
                   3411:       </td></tr><tr><td>0x8B </td><td>U+2039 </td><td>SINGLE LEFT-POINTING ANGLE QUOTATION MARK (&#8249;)
                   3412:       </td></tr><tr><td>0x8C </td><td>U+0152 </td><td>LATIN CAPITAL LIGATURE OE (&#338;)
1.1       mike     3413:       </td></tr><tr><td>0x8D </td><td>U+008D </td><td>&lt;control&gt;
1.464     mike     3414:       </td></tr><tr><td>0x8E </td><td>U+017D </td><td>LATIN CAPITAL LETTER Z WITH CARON (&#381;)
1.1       mike     3415:       </td></tr><tr><td>0x8F </td><td>U+008F </td><td>&lt;control&gt;
                   3416:       </td></tr><tr><td>0x90 </td><td>U+0090 </td><td>&lt;control&gt;
1.464     mike     3417:       </td></tr><tr><td>0x91 </td><td>U+2018 </td><td>LEFT SINGLE QUOTATION MARK (&#8216;)
                   3418:       </td></tr><tr><td>0x92 </td><td>U+2019 </td><td>RIGHT SINGLE QUOTATION MARK (&#8217;)
                   3419:       </td></tr><tr><td>0x93 </td><td>U+201C </td><td>LEFT DOUBLE QUOTATION MARK (&#8220;)
                   3420:       </td></tr><tr><td>0x94 </td><td>U+201D </td><td>RIGHT DOUBLE QUOTATION MARK (&#8221;)
                   3421:       </td></tr><tr><td>0x95 </td><td>U+2022 </td><td>BULLET (&#8226;)
                   3422:       </td></tr><tr><td>0x96 </td><td>U+2013 </td><td>EN DASH (&#8211;)
                   3423:       </td></tr><tr><td>0x97 </td><td>U+2014 </td><td>EM DASH (&#8212;)
                   3424:       </td></tr><tr><td>0x98 </td><td>U+02DC </td><td>SMALL TILDE (&#732;)
                   3425:       </td></tr><tr><td>0x99 </td><td>U+2122 </td><td>TRADE MARK SIGN (&#8482;)
                   3426:       </td></tr><tr><td>0x9A </td><td>U+0161 </td><td>LATIN SMALL LETTER S WITH CARON (&#353;)
                   3427:       </td></tr><tr><td>0x9B </td><td>U+203A </td><td>SINGLE RIGHT-POINTING ANGLE QUOTATION MARK (&#8250;)
                   3428:       </td></tr><tr><td>0x9C </td><td>U+0153 </td><td>LATIN SMALL LIGATURE OE (&#339;)
1.1       mike     3429:       </td></tr><tr><td>0x9D </td><td>U+009D </td><td>&lt;control&gt;
1.464     mike     3430:       </td></tr><tr><td>0x9E </td><td>U+017E </td><td>LATIN SMALL LETTER Z WITH CARON (&#382;)
                   3431:       </td></tr><tr><td>0x9F </td><td>U+0178 </td><td>LATIN CAPITAL LETTER Y WITH DIAERESIS (&#376;)
1.315     mike     3432:     </td></tr></tbody></table><p>Otherwise, if the number is in the range 0xD800 to 0xDFFF<!--
                   3433:     surrogates not allowed; see the comment in the "preprocessing the
                   3434:     input stream" section for details --> or is greater than 0x10FFFF,
                   3435:     then this is a <a href="#parse-error">parse error</a>. Return a U+FFFD
                   3436:     REPLACEMENT CHARACTER.</p>
1.18      mike     3437: 
                   3438:     <p>Otherwise, return a character token for the Unicode character
1.1       mike     3439:     whose code point is that number.
                   3440: 
                   3441:     <!-- this is the same as the equivalent list in the input stream
                   3442:     section -->
                   3443:     If the number is in the range 0x0001 to 0x0008, <!-- HT, LF
                   3444:     allowed --> <!-- U+000B is in the next list --> <!-- FF, CR
                   3445:     allowed --> 0x000E to 0x001F, <!-- ASCII allowed --> 0x007F <!--to
1.315     mike     3446:     0x0084, (0x0085 NEL not allowed), 0x0086--> to 0x009F, 0xFDD0 to
                   3447:     0xFDEF, or is one of 0x000B, 0xFFFE, 0xFFFF, 0x1FFFE, 0x1FFFF,
                   3448:     0x2FFFE, 0x2FFFF, 0x3FFFE, 0x3FFFF, 0x4FFFE, 0x4FFFF, 0x5FFFE,
                   3449:     0x5FFFF, 0x6FFFE, 0x6FFFF, 0x7FFFE, 0x7FFFF, 0x8FFFE, 0x8FFFF,
                   3450:     0x9FFFE, 0x9FFFF, 0xAFFFE, 0xAFFFF, 0xBFFFE, 0xBFFFF, 0xCFFFE,
                   3451:     0xCFFFF, 0xDFFFE, 0xDFFFF, 0xEFFFE, 0xEFFFF, 0xFFFFE, 0xFFFFF,
                   3452:     0x10FFFE, or 0x10FFFF, then this is a <a href="#parse-error">parse
                   3453:     error</a>.</p>
1.1       mike     3454: 
                   3455:    </dd>
                   3456: 
                   3457: 
                   3458:    <dt>Anything else</dt>
                   3459: 
                   3460:    <dd>
                   3461: 
                   3462:     <p>Consume the maximum number of characters possible, with the
                   3463:     consumed characters matching one of the identifiers in the first
                   3464:     column of the <a href="named-character-references.html#named-character-references">named character references</a> table (in a
                   3465:     <a href="infrastructure.html#case-sensitive">case-sensitive</a> manner).</p>
                   3466: 
                   3467:     <p>If no match can be made, then this is a <a href="#parse-error">parse
                   3468:     error</a>. No characters are consumed, and nothing is
                   3469:     returned.</p>
                   3470: 
                   3471:     <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>
                   3472: 
                   3473:     <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
                   3474:     attribute</a>, and the last character matched is not a U+003B
1.464     mike     3475:     SEMICOLON character (<code title="">;</code>), and the next
                   3476:     character is in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT
                   3477:     NINE (9), U+0041 LATIN CAPITAL LETTER A to U+005A LATIN CAPITAL
                   3478:     LETTER Z, or U+0061 LATIN SMALL LETTER A to U+007A LATIN SMALL
                   3479:     LETTER Z, then, for historical reasons, all the characters that
                   3480:     were matched after the U+0026 AMPERSAND character (&amp;) must be
                   3481:     unconsumed, and nothing is returned.</p>
1.1       mike     3482: 
                   3483:     <p>Otherwise, return a character token for the character
                   3484:     corresponding to the character reference name (as given by the
                   3485:     second column of the <a href="named-character-references.html#named-character-references">named character references</a>
                   3486:     table).</p>
                   3487: 
                   3488:     <div class="example">
                   3489: 
                   3490:      <p>If the markup contains <code title="">I'm &amp;notit; I tell
                   3491:      you</code>, the character reference is parsed as "not", as in,
                   3492:      <code title="">I'm &#172;it; I tell you</code>. But if the markup
                   3493:      was <code title="">I'm &amp;notin; I tell you</code>, the
                   3494:      character reference would be parsed as "notin;", resulting in
                   3495:      <code title="">I'm &#8713; I tell you</code>.</p>
                   3496: 
                   3497:     </div>
                   3498: 
                   3499:    </dd>
                   3500: 
1.266     mike     3501:   </dl></div><div class="impl">
                   3502: 
1.363     mike     3503:   <!-- v2: One thing that this doesn't define is handling deeply
                   3504:   nested documents. There are compatibility requirements around that:
                   3505:   you can't throw away the elements altogether, consider Tux made only
                   3506:   with opening <font> elements, one per character. Seems that the best
                   3507:   thing to do is to close some formatting elements from the middle of
                   3508:   the stack when you hit a limit, or something. -->
                   3509: 
1.266     mike     3510:   <h4 id="tree-construction"><span class="secno">9.2.5 </span><dfn>Tree construction</dfn></h4>
1.1       mike     3511: 
                   3512:   <p>The input to the tree construction stage is a sequence of tokens
                   3513:   from the <a href="#tokenization">tokenization</a> stage. The tree construction
                   3514:   stage is associated with a DOM <code>Document</code> object when a
                   3515:   parser is created. The "output" of this stage consists of
                   3516:   dynamically modifying or extending that document's DOM tree.</p>
                   3517: 
                   3518:   <p>This specification does not define when an interactive user agent
                   3519:   has to render the <code>Document</code> so that it is available to
                   3520:   the user, or when it has to begin accepting user input.</p>
                   3521: 
                   3522:   <p>As each token is emitted from the tokenizer, the user agent must
                   3523:   process the token according to the rules given in the section
                   3524:   corresponding to the current <a href="#insertion-mode">insertion mode</a>.</p>
                   3525: 
                   3526:   <p>When the steps below require the UA to <dfn id="insert-a-character">insert a
                   3527:   character</dfn> into a node, if that node has a child immediately
                   3528:   before where the character is to be inserted, and that child is a
                   3529:   <code>Text</code> node, and that <code>Text</code> node was the last
                   3530:   node that the parser inserted into the document, then the character
                   3531:   must be appended to that <code>Text</code> node; otherwise, a new
                   3532:   <code>Text</code> node whose data is just that character must be
                   3533:   inserted in the appropriate place.</p>
                   3534: 
                   3535:   <div class="example">
                   3536: 
                   3537:    <p>Here are some sample inputs to the parser and the corresponding
                   3538:    number of text nodes that they result in, assuming a user agent
                   3539:    that executes scripts.</p>
                   3540: 
                   3541:    <table><thead><tr><th>Input </th><th>Number of text nodes
                   3542:     </th></tr></thead><tbody><tr><td><pre>A&lt;script&gt;
                   3543: var&#160;script&#160;=&#160;document.getElementsByTagName('script')[0];
                   3544: document.body.removeChild(script);
                   3545: &lt;/script&gt;B</pre>
                   3546:       </td><td>Two adjacent text nodes in the document, containing "A" and "B".
                   3547:      </td></tr><tr><td><pre>A&lt;script&gt;
                   3548: var&#160;text&#160;=&#160;document.createTextNode('B');
                   3549: document.body.appendChild(text);
                   3550: &lt;/script&gt;C</pre>
                   3551:       </td><td>Four text nodes; "A" before the script, the script's contents, "B" after the script, and then, immediately after that, "C".
                   3552:      </td></tr><tr><td><pre>A&lt;script&gt;
                   3553: var&#160;text&#160;=&#160;document.getElementsByTagName('script')[0].firstChild;
                   3554: text.data&#160;=&#160;'B';
                   3555: document.body.appendChild(text);
                   3556: &lt;/script&gt;B</pre>
                   3557:       </td><td>Two adjacent text nodes in the document, containing "A" and "BB".
                   3558:      </td></tr><tr><td><pre>A&lt;table&gt;B&lt;tr&gt;C&lt;/tr&gt;C&lt;/table&gt;</pre>
                   3559:       </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>.)
                   3560:      </td></tr><tr><td><pre>A&lt;table&gt;&lt;tr&gt;&#160;B&lt;/tr&gt;&#160;B&lt;/table&gt;</pre>
                   3561:       </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>.)
                   3562:      </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>
                   3563:       </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.)
                   3564:    </td></tr></tbody></table></div>
                   3565: 
                   3566:   <p id="mutation-during-parsing">DOM mutation events must not fire
                   3567:   for changes caused by the UA parsing the document. (Conceptually,
                   3568:   the parser is not mutating the DOM, it is constructing it.) This
1.159     mike     3569:   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     3570: 
                   3571:   <p class="note">Not all of the tag names mentioned below are
                   3572:   conformant tag names in this specification; many are included to
                   3573:   handle legacy content. They still form part of the algorithm that
                   3574:   implementations are required to implement to claim conformance.</p>
                   3575: 
                   3576:   <p class="note">The algorithm described below places no limit on the
                   3577:   depth of the DOM tree generated, or on the length of tag names,
                   3578:   attribute names, attribute values, text nodes, etc. While
                   3579:   implementors are encouraged to avoid arbitrary limits, it is
                   3580:   recognized that <a href="infrastructure.html#hardwareLimitations">practical
1.445     mike     3581:   concerns</a> will likely force user agents to impose nesting depth
                   3582:   constraints.</p>
1.1       mike     3583: 
                   3584: 
                   3585:   <h5 id="creating-and-inserting-elements"><span class="secno">9.2.5.1 </span>Creating and inserting elements</h5>
                   3586: 
                   3587:   <p>When the steps below require the UA to <dfn id="create-an-element-for-the-token" title="create an
                   3588:   element for the token">create an element for a token</dfn> in a
                   3589:   particular namespace, the UA must create a node implementing the
                   3590:   interface appropriate for the element type corresponding to the tag
                   3591:   name of the token in the given namespace (as given in the
                   3592:   specification that defines that element, e.g. for an <code><a href="text-level-semantics.html#the-a-element">a</a></code>
                   3593:   element in the <a href="#html-namespace-0">HTML namespace</a>, this specification
                   3594:   defines it to be the <code><a href="text-level-semantics.html#htmlanchorelement">HTMLAnchorElement</a></code> interface), with
                   3595:   the tag name being the name of that element, with the node being in
                   3596:   the given namespace, and with the attributes on the node being those
                   3597:   given in the given token.</p>
                   3598: 
                   3599:   <p>The interface appropriate for an element in the <a href="#html-namespace-0">HTML
1.426     mike     3600:   namespace</a> that is not defined in this specification (or
                   3601:   <a href="infrastructure.html#other-applicable-specifications">other applicable specifications</a>) is
1.44      mike     3602:   <code><a href="dom.html#htmlunknownelement">HTMLUnknownElement</a></code>. Element in other namespaces whose
1.1       mike     3603:   interface is not defined by that namespace's specification must use
                   3604:   the interface <code>Element</code>.</p>
                   3605: 
                   3606:   <p>When a <a href="forms.html#category-reset" title="category-reset">resettable</a> element is
                   3607:   created in this manner, its <a href="forms.html#concept-form-reset-control" title="concept-form-reset-control">reset algorithm</a> must be
                   3608:   invoked once the attributes are set. (This initializes the element's
                   3609:   <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
                   3610:   attributes.)</p>
                   3611: 
                   3612:   <hr><p>When the steps below require the UA to <dfn id="insert-an-html-element">insert an HTML
                   3613:   element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
                   3614:   for the token</a> in the <a href="#html-namespace-0">HTML namespace</a>, and then
                   3615:   append this node to the <a href="#current-node">current node</a>, and push it onto
                   3616:   the <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
                   3617:   <a href="#current-node">current node</a>.</p>
                   3618: 
                   3619:   <p>The steps below may also require that the UA insert an HTML
                   3620:   element in a particular place, in which case the UA must follow the
                   3621:   same steps except that it must insert or append the new node in the
                   3622:   location specified instead of appending it to the <a href="#current-node">current
                   3623:   node</a>. (This happens in particular during the parsing of
                   3624:   tables with invalid content.)</p>
                   3625: 
                   3626:   <p>If an element created by the <a href="#insert-an-html-element">insert an HTML element</a>
                   3627:   algorithm is a <a href="forms.html#form-associated-element">form-associated element</a>, and the
                   3628:   <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is not null,
                   3629:   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
                   3630:   <a href="forms.html#concept-form-association" title="concept-form-association">associate</a> the newly
                   3631:   created element with the <code><a href="forms.html#the-form-element">form</a></code> element pointed to by the
                   3632:   <a href="#form-element-pointer"><code title="">form</code> element pointer</a> before
                   3633:   inserting it wherever it is to be inserted.</p>
                   3634: 
                   3635:   <hr><p>When the steps below require the UA to <dfn id="insert-a-foreign-element">insert a foreign
                   3636:   element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
                   3637:   for the token</a> in the given namespace, and then append this
                   3638:   node to the <a href="#current-node">current node</a>, and push it onto the
                   3639:   <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
                   3640:   <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>
                   3641:   whose value is not exactly the same as the element's namespace, that
                   3642:   is a <a href="#parse-error">parse error</a>. Similarly, if the newly created
                   3643:   element has an <code title="">xmlns:xlink</code> attribute in the
                   3644:   <a href="#xmlns-namespace">XMLNS namespace</a> whose value is not the <a href="#xlink-namespace">XLink
                   3645:   Namespace</a>, that is a <a href="#parse-error">parse error</a>.</p>
                   3646: 
                   3647:   <p>When the steps below require the user agent to <dfn id="adjust-mathml-attributes">adjust MathML
                   3648:   attributes</dfn> for a token, then, if the token has an attribute
                   3649:   named <code title="">definitionurl</code>, change its name to <code title="">definitionURL</code> (note the case difference).</p>
                   3650: 
                   3651:   <p>When the steps below require the user agent to <dfn id="adjust-svg-attributes">adjust SVG
                   3652:   attributes</dfn> for a token, then, for each attribute on the token
                   3653:   whose attribute name is one of the ones in the first column of the
                   3654:   following table, change the attribute's name to the name given in
                   3655:   the corresponding cell in the second column. (This fixes the case of
                   3656:   SVG attributes that are not all lowercase.)</p>
                   3657: 
                   3658:   <table><thead><tr><th> Attribute name on token </th><th> Attribute name on element
                   3659:    </th></tr></thead><tbody><tr><td> <code title="">attributename</code> </td><td> <code title="">attributeName</code>
                   3660:     </td></tr><tr><td> <code title="">attributetype</code> </td><td> <code title="">attributeType</code>
                   3661:     </td></tr><tr><td> <code title="">basefrequency</code> </td><td> <code title="">baseFrequency</code>
                   3662:     </td></tr><tr><td> <code title="">baseprofile</code> </td><td> <code title="">baseProfile</code>
                   3663:     </td></tr><tr><td> <code title="">calcmode</code> </td><td> <code title="">calcMode</code>
                   3664:     </td></tr><tr><td> <code title="">clippathunits</code> </td><td> <code title="">clipPathUnits</code>
                   3665:     </td></tr><tr><td> <code title="">contentscripttype</code> </td><td> <code title="">contentScriptType</code>
                   3666:     </td></tr><tr><td> <code title="">contentstyletype</code> </td><td> <code title="">contentStyleType</code>
                   3667:     </td></tr><tr><td> <code title="">diffuseconstant</code> </td><td> <code title="">diffuseConstant</code>
                   3668:     </td></tr><tr><td> <code title="">edgemode</code> </td><td> <code title="">edgeMode</code>
                   3669:     </td></tr><tr><td> <code title="">externalresourcesrequired</code> </td><td> <code title="">externalResourcesRequired</code>
                   3670:     </td></tr><tr><td> <code title="">filterres</code> </td><td> <code title="">filterRes</code>
                   3671:     </td></tr><tr><td> <code title="">filterunits</code> </td><td> <code title="">filterUnits</code>
                   3672:     </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
                   3673:     </td></tr><tr><td> <code title="">gradienttransform</code> </td><td> <code title="">gradientTransform</code>
                   3674:     </td></tr><tr><td> <code title="">gradientunits</code> </td><td> <code title="">gradientUnits</code>
                   3675:     </td></tr><tr><td> <code title="">kernelmatrix</code> </td><td> <code title="">kernelMatrix</code>
                   3676:     </td></tr><tr><td> <code title="">kernelunitlength</code> </td><td> <code title="">kernelUnitLength</code>
                   3677:     </td></tr><tr><td> <code title="">keypoints</code> </td><td> <code title="">keyPoints</code>
                   3678:     </td></tr><tr><td> <code title="">keysplines</code> </td><td> <code title="">keySplines</code>
                   3679:     </td></tr><tr><td> <code title="">keytimes</code> </td><td> <code title="">keyTimes</code>
                   3680:     </td></tr><tr><td> <code title="">lengthadjust</code> </td><td> <code title="">lengthAdjust</code>
                   3681:     </td></tr><tr><td> <code title="">limitingconeangle</code> </td><td> <code title="">limitingConeAngle</code>
                   3682:     </td></tr><tr><td> <code title="">markerheight</code> </td><td> <code title="">markerHeight</code>
                   3683:     </td></tr><tr><td> <code title="">markerunits</code> </td><td> <code title="">markerUnits</code>
                   3684:     </td></tr><tr><td> <code title="">markerwidth</code> </td><td> <code title="">markerWidth</code>
                   3685:     </td></tr><tr><td> <code title="">maskcontentunits</code> </td><td> <code title="">maskContentUnits</code>
                   3686:     </td></tr><tr><td> <code title="">maskunits</code> </td><td> <code title="">maskUnits</code>
                   3687:     </td></tr><tr><td> <code title="">numoctaves</code> </td><td> <code title="">numOctaves</code>
                   3688:     </td></tr><tr><td> <code title="">pathlength</code> </td><td> <code title="">pathLength</code>
                   3689:     </td></tr><tr><td> <code title="">patterncontentunits</code> </td><td> <code title="">patternContentUnits</code>
                   3690:     </td></tr><tr><td> <code title="">patterntransform</code> </td><td> <code title="">patternTransform</code>
                   3691:     </td></tr><tr><td> <code title="">patternunits</code> </td><td> <code title="">patternUnits</code>
                   3692:     </td></tr><tr><td> <code title="">pointsatx</code> </td><td> <code title="">pointsAtX</code>
                   3693:     </td></tr><tr><td> <code title="">pointsaty</code> </td><td> <code title="">pointsAtY</code>
                   3694:     </td></tr><tr><td> <code title="">pointsatz</code> </td><td> <code title="">pointsAtZ</code>
                   3695:     </td></tr><tr><td> <code title="">preservealpha</code> </td><td> <code title="">preserveAlpha</code>
                   3696:     </td></tr><tr><td> <code title="">preserveaspectratio</code> </td><td> <code title="">preserveAspectRatio</code>
                   3697:     </td></tr><tr><td> <code title="">primitiveunits</code> </td><td> <code title="">primitiveUnits</code>
                   3698:     </td></tr><tr><td> <code title="">refx</code> </td><td> <code title="">refX</code>
                   3699:     </td></tr><tr><td> <code title="">refy</code> </td><td> <code title="">refY</code>
                   3700:     </td></tr><tr><td> <code title="">repeatcount</code> </td><td> <code title="">repeatCount</code>
                   3701:     </td></tr><tr><td> <code title="">repeatdur</code> </td><td> <code title="">repeatDur</code>
                   3702:     </td></tr><tr><td> <code title="">requiredextensions</code> </td><td> <code title="">requiredExtensions</code>
                   3703:     </td></tr><tr><td> <code title="">requiredfeatures</code> </td><td> <code title="">requiredFeatures</code>
                   3704:     </td></tr><tr><td> <code title="">specularconstant</code> </td><td> <code title="">specularConstant</code>
                   3705:     </td></tr><tr><td> <code title="">specularexponent</code> </td><td> <code title="">specularExponent</code>
                   3706:     </td></tr><tr><td> <code title="">spreadmethod</code> </td><td> <code title="">spreadMethod</code>
                   3707:     </td></tr><tr><td> <code title="">startoffset</code> </td><td> <code title="">startOffset</code>
                   3708:     </td></tr><tr><td> <code title="">stddeviation</code> </td><td> <code title="">stdDeviation</code>
                   3709:     </td></tr><tr><td> <code title="">stitchtiles</code> </td><td> <code title="">stitchTiles</code>
                   3710:     </td></tr><tr><td> <code title="">surfacescale</code> </td><td> <code title="">surfaceScale</code>
                   3711:     </td></tr><tr><td> <code title="">systemlanguage</code> </td><td> <code title="">systemLanguage</code>
                   3712:     </td></tr><tr><td> <code title="">tablevalues</code> </td><td> <code title="">tableValues</code>
                   3713:     </td></tr><tr><td> <code title="">targetx</code> </td><td> <code title="">targetX</code>
                   3714:     </td></tr><tr><td> <code title="">targety</code> </td><td> <code title="">targetY</code>
                   3715:     </td></tr><tr><td> <code title="">textlength</code> </td><td> <code title="">textLength</code>
                   3716:     </td></tr><tr><td> <code title="">viewbox</code> </td><td> <code title="">viewBox</code>
                   3717:     </td></tr><tr><td> <code title="">viewtarget</code> </td><td> <code title="">viewTarget</code>
                   3718:     </td></tr><tr><td> <code title="">xchannelselector</code> </td><td> <code title="">xChannelSelector</code>
                   3719:     </td></tr><tr><td> <code title="">ychannelselector</code> </td><td> <code title="">yChannelSelector</code>
                   3720:     </td></tr><tr><td> <code title="">zoomandpan</code> </td><td> <code title="">zoomAndPan</code>
                   3721:   </td></tr></tbody></table><p>When the steps below require the user agent to <dfn id="adjust-foreign-attributes">adjust
                   3722:   foreign attributes</dfn> for a token, then, if any of the attributes
                   3723:   on the token match the strings given in the first column of the
                   3724:   following table, let the attribute be a namespaced attribute, with
                   3725:   the prefix being the string given in the corresponding cell in the
                   3726:   second column, the local name being the string given in the
                   3727:   corresponding cell in the third column, and the namespace being the
                   3728:   namespace given in the corresponding cell in the fourth
                   3729:   column. (This fixes the use of namespaced attributes, in particular
                   3730:   <a href="dom.html#attr-xml-lang" title="attr-xml-lang"><code title="">lang</code> attributes in
                   3731:   the <span>XML namespace</span></a>.)</p>
                   3732: 
                   3733:   <table><thead><tr><th> Attribute name </th><th> Prefix </th><th> Local name </th><th> Namespace
                   3734:    </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>
                   3735:     </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>
                   3736:     </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>
                   3737:     </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>
                   3738:     </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>
                   3739:     </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>
                   3740:     </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>
                   3741:     </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 -->
                   3742:     </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>
                   3743:     </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>
                   3744:     </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>
                   3745:     </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     3746:   </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     3747:   <dfn id="generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</dfn> consist of the
                   3748:   following steps. These algorithms are always invoked in response to
                   3749:   a start tag token.</p>
                   3750: 
                   3751:   <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p></li>
                   3752: 
1.91      mike     3753:    <li><p>If the algorithm that was invoked is the <a href="#generic-raw-text-element-parsing-algorithm">generic raw
                   3754:    text element parsing algorithm</a>, switch the tokenizer's
                   3755:    <a href="#content-model-flag">content model flag</a> to the RAWTEXT state; otherwise the
1.1       mike     3756:    algorithm invoked was the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing
                   3757:    algorithm</a>, switch the tokenizer's <a href="#content-model-flag">content model
                   3758:    flag</a> to the RCDATA state.</p></li>
                   3759: 
                   3760:    <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
                   3761:    <a href="#insertion-mode">insertion mode</a>.</p>
                   3762: 
1.91      mike     3763:    </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
                   3764:    RAWTEXT/RCDATA</a>".</p></li>
1.1       mike     3765: 
                   3766:   </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>
                   3767: 
                   3768:   <p>When the steps below require the UA to <dfn id="generate-implied-end-tags">generate implied end
                   3769:   tags</dfn>, then, while the <a href="#current-node">current node</a> is a
1.422     mike     3770:   <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     3771:   <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
                   3772:   <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
                   3773:   <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
                   3774:   pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   3775:   elements</a>.</p>
                   3776: 
                   3777:   <p>If a step requires the UA to generate implied end tags but lists
                   3778:   an element to exclude from the process, then the UA must perform the
                   3779:   above steps as if that element was not in the above list.</p>
                   3780: 
                   3781: 
                   3782:   <h5 id="foster-parenting"><span class="secno">9.2.5.3 </span>Foster parenting</h5>
                   3783: 
                   3784:   <p>Foster parenting happens when content is misnested in tables.</p>
                   3785: 
                   3786:   <p>When a node <var title="">node</var> is to be <dfn id="foster-parent" title="foster
                   3787:   parent">foster parented</dfn>, the node <var title="">node</var>
                   3788:   must be inserted into the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
                   3789: 
                   3790:   <p>The <dfn id="foster-parent-element">foster parent element</dfn> is the parent element of the
                   3791:   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
                   3792:   elements</a>, if there is a <code><a href="tabular-data.html#the-table-element">table</a></code> element and it has
                   3793:   such a parent element. If there is no <code><a href="tabular-data.html#the-table-element">table</a></code> element in
                   3794:   the <a href="#stack-of-open-elements">stack of open elements</a> (<a href="#fragment-case">fragment
                   3795:   case</a>), then the <i><a href="#foster-parent-element">foster parent element</a></i> is the first
                   3796:   element in the <a href="#stack-of-open-elements">stack of open elements</a> (the
1.159     mike     3797:   <code><a href="semantics.html#the-html-element-0">html</a></code> element). Otherwise, if there is a
1.1       mike     3798:   <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="#stack-of-open-elements">stack of open
                   3799:   elements</a>, but the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
                   3800:   <a href="#stack-of-open-elements">stack of open elements</a> has no parent, or its parent
                   3801:   node is not an element, then the <i><a href="#foster-parent-element">foster parent element</a></i> is
                   3802:   the element before the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
                   3803:   <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   3804: 
                   3805:   <p>If the <i><a href="#foster-parent-element">foster parent element</a></i> is the parent element of the
                   3806:   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
                   3807:   elements</a>, then <var title="">node</var> must be inserted
                   3808:   immediately <em>before</em> the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in
                   3809:   the <a href="#stack-of-open-elements">stack of open elements</a> in the <i><a href="#foster-parent-element">foster parent
                   3810:   element</a></i>; otherwise, <var title="">node</var> must be
                   3811:   <em>appended</em> to the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
                   3812: 
                   3813: 
                   3814: 
                   3815:   <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>
                   3816: 
                   3817:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-initial-insertion-mode" title="insertion
                   3818:   mode: initial">initial</a>", tokens must be handled as follows:</p>
                   3819: 
                   3820:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   3821:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   3822:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   3823:    <dd>
                   3824:     <p>Ignore the token.</p>
                   3825:    </dd>
                   3826: 
                   3827:    <dt>A comment token</dt>
                   3828:    <dd>
                   3829:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   3830:     object with the <code title="">data</code> attribute set to the
                   3831:     data given in the comment token.</p>
                   3832:    </dd>
                   3833: 
                   3834:    <dt>A DOCTYPE token</dt>
                   3835:    <dd>
                   3836: 
                   3837:     <p>If the DOCTYPE token's name is not a
                   3838:     <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
                   3839:     missing, or the token's system identifier is neither missing nor a
                   3840:     <a href="infrastructure.html#case-sensitive">case-sensitive</a> match for the string
1.465     mike     3841:     "<code><a href="infrastructure.html#about:legacy-compat">about:legacy-compat</a></code>", and none of the sets of
1.1       mike     3842:     conditions in the following list are matched, then there is a
                   3843:     <a href="#parse-error">parse error</a>. If one of the sets of conditions in the
                   3844:     following list is matched, then there is an <dfn id="obsolete-permitted-doctype">obsolete
                   3845:     permitted DOCTYPE</dfn>.</p>
                   3846: 
                   3847:     <ul><!-- only things that trigger no-quirks mode and were valid in
                   3848:      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     3849:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3850:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;HTML&#160;4.0//EN</code>", and the
                   3851:      token's system identifier is either missing or the
                   3852:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/REC-html40/strict.dtd</code>".</li>
                   3853: 
                   3854:      <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98      mike     3855:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3856:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;HTML&#160;4.01//EN</code>", and the
                   3857:      token's system identifier is either missing or the
                   3858:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/html4/strict.dtd</code>".</li>
                   3859: 
                   3860:      <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98      mike     3861:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3862:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;XHTML&#160;1.0&#160;Strict//EN</code>",
                   3863:      and the token's system identifier is the
                   3864:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</code>".</li>
                   3865: 
                   3866:      <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98      mike     3867:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3868:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;XHTML&#160;1.1//EN</code>", and the
                   3869:      token's system identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a>
                   3870:      string "<code title="">http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd</code>".</li>
                   3871: 
                   3872:     </ul><p>Conformance checkers may, based on the values (including
                   3873:     presence or lack thereof) of the DOCTYPE token's name, public
                   3874:     identifier, or system identifier, switch to a conformance checking
                   3875:     mode for another language (e.g. based on the DOCTYPE token a
                   3876:     conformance checker could recognize that the document is an
1.183     mike     3877:     HTML4-era document, and defer to an HTML4 conformance
1.1       mike     3878:     checker.)</p>
                   3879: 
                   3880:     <p>Append a <code>DocumentType</code> node to the
                   3881:     <code>Document</code> node, with the <code title="">name</code>
                   3882:     attribute set to the name given in the DOCTYPE token, or the empty
                   3883:     string if the name was missing; the <code title="">publicId</code>
                   3884:     attribute set to the public identifier given in the DOCTYPE token,
                   3885:     or the empty string if the public identifier was missing; the
                   3886:     <code title="">systemId</code> attribute set to the system
                   3887:     identifier given in the DOCTYPE token, or the empty string if the
                   3888:     system identifier was missing; and the other attributes specific
                   3889:     to <code>DocumentType</code> objects set to null and empty lists
                   3890:     as appropriate. Associate the <code>DocumentType</code> node with
                   3891:     the <code>Document</code> object so that it is returned as the
                   3892:     value of the <code title="">doctype</code> attribute of the
                   3893:     <code>Document</code> object.</p>
                   3894: 
                   3895:     <p id="quirks-mode-doctypes">Then, if the DOCTYPE token matches
                   3896:     one of the conditions in the following list, then set the
                   3897:     <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>:</p>
                   3898: 
                   3899:     <ul class="brief"><li> The <i>force-quirks flag</i> is set to <i>on</i>. </li>
                   3900:      <li> The name is set to anything other than "<code title="">HTML</code>". </li>
                   3901:      <li> The public identifier starts with: "<code title="">+//Silmaril//dtd html Pro v0r11 19970101//<!--EN--></code>" </li>
                   3902:      <li> The public identifier starts with: "<code title="">-//AdvaSoft Ltd//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
                   3903:      <li> The public identifier starts with: "<code title="">-//AS//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
                   3904:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 1//<!--EN--></code>" </li>
                   3905:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 2//<!--EN--></code>" </li>
                   3906:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 1//<!--EN--></code>" </li>
                   3907:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 2//<!--EN--></code>" </li>
                   3908:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict//<!--EN--></code>" </li>
                   3909:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0//<!--EN--></code>" </li>
                   3910:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.1E//<!--EN--></code>" </li>
                   3911:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.0//<!--EN--></code>" </li>
                   3912:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML 3.0//EN//</code>" </li>-->
                   3913:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2 Final//<!--EN--></code>" </li>
                   3914:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2//<!--EN--></code>" </li>
                   3915:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3//<!--EN--></code>" </li>
                   3916:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 0//<!--EN--></code>" </li>
                   3917:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 0//EN//2.0</code>" </li>-->
                   3918:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 1//<!--EN--></code>" </li>
                   3919:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 1//EN//2.0</code>" </li>-->
                   3920:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 2//<!--EN--></code>" </li>
                   3921:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 2//EN//2.0</code>" </li>-->
                   3922:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 3//<!--EN--></code>" </li>
                   3923:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 3//EN//3.0</code>" </li>-->
                   3924:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 0//<!--EN--></code>" </li>
                   3925:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 0//EN//2.0</code>" </li>-->
                   3926:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 1//<!--EN--></code>" </li>
                   3927:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 1//EN//2.0</code>" </li>-->
                   3928:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 2//<!--EN--></code>" </li>
                   3929:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 2//EN//2.0</code>" </li>-->
                   3930:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 3//<!--EN--></code>" </li>
                   3931:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 3//EN//3.0</code>" </li>-->
                   3932:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict//<!--EN--></code>" </li>
                   3933:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//2.0</code>" </li>-->
                   3934:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//3.0</code>" </li>-->
                   3935:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML//<!--EN--></code>" </li>
                   3936:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//2.0</code>" </li>-->
                   3937:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//3.0</code>" </li>-->
                   3938:      <li> The public identifier starts with: "<code title="">-//Metrius//DTD Metrius Presentational//<!--EN--></code>" </li>
                   3939:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML Strict//<!--EN--></code>" </li>
                   3940:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML//<!--EN--></code>" </li>
                   3941:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 Tables//<!--EN--></code>" </li>
                   3942:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML Strict//<!--EN--></code>" </li>
                   3943:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML//<!--EN--></code>" </li>
                   3944:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 Tables//<!--EN--></code>" </li>
                   3945:      <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD HTML//<!--EN--></code>" </li>
                   3946:      <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD Strict HTML//<!--EN--></code>" </li>
                   3947:      <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML 2.0//<!--EN--></code>" </li>
                   3948:      <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended 1.0//<!--EN--></code>" </li>
                   3949:      <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended Relaxed 1.0//<!--EN--></code>" </li>
                   3950:      <li> The public identifier starts with: "<code title="">-//SoftQuad Software//DTD HoTMetaL PRO 6.0::19990601::extensions to HTML 4.0//<!--EN--></code>" </li>
                   3951:      <li> The public identifier starts with: "<code title="">-//SoftQuad//DTD HoTMetaL PRO 4.0::19971010::extensions to HTML 4.0//<!--EN--></code>" </li>
                   3952:      <li> The public identifier starts with: "<code title="">-//Spyglass//DTD HTML 2.0 Extended//<!--EN--></code>" </li>
                   3953:      <li> The public identifier starts with: "<code title="">-//SQ//DTD HTML 2.0 HoTMetaL + extensions//<!--EN--></code>" </li>
                   3954:      <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava HTML//<!--EN--></code>" </li>
                   3955:      <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava Strict HTML//<!--EN--></code>" </li>
                   3956:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3 1995-03-24//<!--EN--></code>" </li>
                   3957:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Draft//<!--EN--></code>" </li>
                   3958:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Final//<!--EN--></code>" </li>
                   3959:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2//<!--EN--></code>" </li>
                   3960:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2S Draft//<!--EN--></code>" </li>
                   3961:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Frameset//<!--EN--></code>" </li>
                   3962:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Transitional//<!--EN--></code>" </li>
                   3963:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 19960712//<!--EN--></code>" </li>
                   3964:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 970421//<!--EN--></code>" </li>
                   3965:      <li> The public identifier starts with: "<code title="">-//W3C//DTD W3 HTML//<!--EN--></code>" </li>
                   3966:      <li> The public identifier starts with: "<code title="">-//W3O//DTD W3 HTML 3.0//<!--EN--></code>" </li>
                   3967:    <!--<li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML 3.0//EN//</code>" </li>-->
                   3968:      <li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML Strict 3.0//EN//</code>" </li>
                   3969:      <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML 2.0//<!--EN--></code>" </li>
                   3970:      <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML//<!--EN--></code>" </li>
                   3971:      <li> The public identifier is set to: "<code title="">-/W3C/DTD HTML 4.0 Transitional/EN</code>" </li>
                   3972:      <li> The public identifier is set to: "<code title="">HTML</code>" </li>
                   3973:      <li> The system identifier is set to: "<code title="">http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd</code>" </li>
                   3974:      <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
                   3975:      <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
                   3976:     </ul><p>Otherwise, if the DOCTYPE token matches one of the conditions
                   3977:     in the following list, then set the <code>Document</code> to
                   3978:     <a href="dom.html#limited-quirks-mode">limited quirks mode</a>:</p>
                   3979: 
                   3980:     <ul class="brief"><li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Frameset//<!--EN--></code>" </li>
                   3981:      <li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Transitional//<!--EN--></code>" </li>
                   3982:      <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
                   3983:      <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
                   3984:     </ul><p>The name, system identifier, and public identifier strings must
                   3985:     be compared to the values given in the lists above in an
                   3986:     <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> manner. A system identifier
                   3987:     whose value is the empty string is not considered missing for the
                   3988:     purposes of the conditions above.</p>
                   3989: 
                   3990:     <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>
                   3991: 
                   3992:    </dd>
                   3993: 
                   3994:    <dt>Anything else</dt>
                   3995:    <dd>
                   3996: 
                   3997:     <p><a href="#parse-error">Parse error</a>.</p>
                   3998: 
                   3999:     <p>Set the <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>.</p>
                   4000: 
                   4001:     <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
                   4002:     reprocess the current token.</p>
                   4003: 
                   4004:    </dd>
                   4005: 
                   4006:   </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>
                   4007: 
                   4008:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-html-insertion-mode" title="insertion
                   4009:   mode: before html">before html</a>", tokens must be handled as follows:</p>
                   4010: 
                   4011:   <dl class="switch"><dt>A DOCTYPE token</dt>
                   4012:    <dd>
                   4013:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4014:    </dd>
                   4015: 
                   4016:    <dt>A comment token</dt>
                   4017:    <dd>
                   4018:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   4019:     object with the <code title="">data</code> attribute set to the
                   4020:     data given in the comment token.</p>
                   4021:    </dd>
                   4022: 
                   4023:    <dt>A character token that is one of U+0009 CHARACTER
                   4024:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   4025:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   4026:    <dd>
                   4027:     <p>Ignore the token.</p>
                   4028:    </dd>
                   4029: 
                   4030:    <dt>A start tag whose tag name is "html"</dt>
                   4031:    <dd>
                   4032: 
                   4033:     <p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the <a href="#html-namespace-0">HTML
                   4034:     namespace</a>. Append it to the <code>Document</code>
                   4035:     object. Put this element in the <a href="#stack-of-open-elements">stack of open
                   4036:     elements</a>.</p>
                   4037: 
                   4038:     <p id="parser-appcache">If the <code>Document</code> is being
                   4039:     loaded as part of <a href="history.html#navigate" title="navigate">navigation</a> of a
                   4040:     <a href="browsers.html#browsing-context">browsing context</a>, then: if the newly created element
                   4041:     has a <code title="attr-html-manifest"><a href="semantics.html#attr-html-manifest">manifest</a></code> attribute,
                   4042:     then <a href="infrastructure.html#resolve-a-url" title="resolve a url">resolve</a> the value of that
                   4043:     attribute to an <a href="infrastructure.html#absolute-url">absolute URL</a>, relative to the newly
                   4044:     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     4045:     algorithm</a> with the resulting <a href="infrastructure.html#absolute-url">absolute URL</a> with
                   4046:     any <a href="infrastructure.html#url-fragment" title="url-fragment">&lt;fragment&gt;</a> component
                   4047:     removed; otherwise, if there is no such attribute or resolving it
                   4048:     fails, run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application
                   4049:     cache selection algorithm</a> with no manifest. The algorithm
                   4050:     must be passed the <code>Document</code> object.</p>
1.1       mike     4051: 
                   4052:     <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>
                   4053: 
                   4054:    </dd>
                   4055: 
1.334     mike     4056:    <dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
                   4057:    <dd>
                   4058:     <p>Act as described in the "anything else" entry below.</p>
                   4059:    </dd>
                   4060: 
                   4061:    <dt>Any other end tag</dt>
                   4062:    <dd>
                   4063:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4064:    </dd>
                   4065: 
1.1       mike     4066:    <dt>Anything else</dt>
                   4067:    <dd>
                   4068: 
1.159     mike     4069:     <p>Create an <code><a href="semantics.html#the-html-element-0">html</a></code> element. Append it to the
1.1       mike     4070:     <code>Document</code> object. Put this element in the <a href="#stack-of-open-elements">stack
                   4071:     of open elements</a>.</p>
                   4072: 
                   4073:     <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
                   4074:     context</a>, then: run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application cache selection
                   4075:     algorithm</a> with no manifest, passing it the
                   4076:     <code>Document</code> object.</p>
                   4077: 
                   4078:     <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
                   4079:     reprocess the current token.</p>
                   4080: 
                   4081:    </dd>
                   4082: 
                   4083:   </dl><p>The root element can end up being removed from the
                   4084:   <code>Document</code> object, e.g. by scripts; nothing in particular
                   4085:   happens in such cases, content continues being appended to the nodes
                   4086:   as described in the next section.</p>
                   4087: 
                   4088: 
                   4089:   <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>
                   4090: 
                   4091:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-head-insertion-mode" title="insertion
                   4092:   mode: before head">before head</a>", tokens must be handled as follows:</p>
                   4093: 
                   4094:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   4095:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   4096:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   4097:    <dd>
                   4098:     <p>Ignore the token.</p> <!-- :-( -->
                   4099:    </dd>
                   4100: 
                   4101:    <dt>A comment token</dt>
                   4102:    <dd>
                   4103:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   4104:     node</a> with the <code title="">data</code> attribute set to
                   4105:     the data given in the comment token.</p>
                   4106:    </dd>
                   4107: 
                   4108:    <dt>A DOCTYPE token</dt>
                   4109:    <dd>
                   4110:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4111:    </dd>
                   4112: 
                   4113:    <dt>A start tag whose tag name is "html"</dt>
                   4114:    <dd>
                   4115:     <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
                   4116:     mode</a>.</p>
                   4117:    </dd>
                   4118: 
                   4119:    <dt>A start tag whose tag name is "head"</dt>
                   4120:    <dd>
                   4121: 
                   4122:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4123: 
                   4124:     <p>Set the <a href="#head-element-pointer"><code title="">head</code> element pointer</a>
1.159     mike     4125:     to the newly created <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1       mike     4126: 
                   4127:     <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>
                   4128: 
                   4129:    </dd>
                   4130: 
                   4131:    <dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
                   4132:    <dd>
                   4133: 
                   4134:     <p>Act as if a start tag token with the tag name "head" and no
                   4135:     attributes had been seen, then reprocess the current token.</p>
                   4136: 
                   4137:    </dd>
                   4138: 
                   4139:    <dt>Any other end tag</dt>
                   4140:    <dd>
                   4141: 
                   4142:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4143: 
                   4144:    </dd>
                   4145: 
                   4146:    <dt>Anything else</dt>
                   4147:    <dd>
                   4148: 
                   4149:     <p>Act as if a start tag token with the tag name "head" and no
                   4150:     attributes had been seen, then reprocess the current
                   4151:     token.</p>
                   4152: 
                   4153:    </dd>
                   4154: 
                   4155:   </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>
                   4156: 
                   4157:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inhead" title="insertion
                   4158:   mode: in head">in head</a>", tokens must be handled as follows:</p>
                   4159: 
                   4160:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   4161:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   4162:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   4163:    <dd>
                   4164:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   4165:     the <a href="#current-node">current node</a>.</p>
                   4166:    </dd>
                   4167: 
                   4168:    <dt>A comment token</dt>
                   4169:    <dd>
                   4170:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   4171:     node</a> with the <code title="">data</code> attribute set to
                   4172:     the data given in the comment token.</p>
                   4173:    </dd>
                   4174: 
                   4175:    <dt>A DOCTYPE token</dt>
                   4176:    <dd>
                   4177:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4178:    </dd>
                   4179: 
                   4180:    <dt>A start tag whose tag name is "html"</dt>
                   4181:    <dd>
                   4182:     <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
                   4183:     mode</a>.</p>
                   4184:    </dd>
                   4185: 
                   4186:    <dt>A start tag whose tag name is one of: "base", "command",
                   4187:    "link"</dt>
                   4188:    <dd>
                   4189: 
                   4190:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   4191:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   4192:     elements</a>.</p>
                   4193: 
                   4194:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   4195:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   4196: 
                   4197:    </dd>
                   4198: 
                   4199:    <dt>A start tag whose tag name is "meta"</dt>
                   4200:    <dd>
                   4201: 
                   4202:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   4203:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   4204:     elements</a>.</p>
                   4205: 
                   4206:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   4207:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   4208: 
                   4209:     <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
                   4210:     value is a supported encoding, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   4211:     currently <i>tentative</i>, then <a href="#change-the-encoding">change the
                   4212:     encoding</a> to the encoding given by the value of the
                   4213:     <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">charset</a></code> attribute.</p>
                   4214: 
                   4215:     <p>Otherwise, if the element has a <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">content</a></code> attribute, and
                   4216:     applying the <a href="infrastructure.html#algorithm-for-extracting-an-encoding-from-a-content-type">algorithm for extracting an encoding from a
                   4217:     Content-Type</a> to its value returns a supported encoding
                   4218:     <var title="">encoding</var>, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   4219:     currently <i>tentative</i>, then <a href="#change-the-encoding">change the
                   4220:     encoding</a> to the encoding <var title="">encoding</var>.</p>
                   4221: 
                   4222:    </dd>
                   4223: 
                   4224:    <dt>A start tag whose tag name is "title"</dt>
                   4225:    <dd>
                   4226:     <p>Follow the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</a>.</p>
                   4227:    </dd>
                   4228: 
                   4229:    <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
                   4230:    <dt>A start tag whose tag name is one of: "noframes", "style"</dt>
                   4231:    <dd>
1.91      mike     4232:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     4233:    </dd>
                   4234: 
                   4235:    <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is disabled</dt>
                   4236:    <dd>
                   4237: 
                   4238:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4239: 
                   4240:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inheadnoscript" title="insertion mode: in head noscript">in head
                   4241:     noscript</a>".</p>
                   4242: 
                   4243:    </dd>
                   4244: 
                   4245:    <dt id="scriptTag">A start tag whose tag name is "script"</dt>
                   4246:    <dd>
                   4247: 
                   4248:     <ol><li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the
                   4249:      <a href="#html-namespace-0">HTML namespace</a>.</p></li>
                   4250: 
                   4251:      <li>
                   4252: 
                   4253:       <p>Mark the element as being <a href="semantics.html#parser-inserted">"parser-inserted"</a>.</p>
                   4254: 
                   4255:       <p class="note">This ensures that, if the script is external,
1.159     mike     4256:       any <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code>
1.1       mike     4257:       calls in the script will execute in-line, instead of blowing the
                   4258:       document away, as would happen in most other cases. It also
                   4259:       prevents the script from executing until the end tag is
                   4260:       seen.</p>
                   4261: 
                   4262:      </li>
                   4263: 
                   4264:      <li><p>If the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML
                   4265:      fragment parsing algorithm</a>, then mark the
                   4266:      <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-executed">"already
                   4267:      executed"</a>. (<a href="#fragment-case">fragment case</a>)</p></li>
                   4268: 
                   4269:      <li><p>Append the new element to the <a href="#current-node">current node</a>
                   4270:      and push it onto the <a href="#stack-of-open-elements">stack of open
                   4271:      elements</a>.</p></li>
                   4272: 
                   4273:      <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
1.91      mike     4274:      the RAWTEXT state.</p></li>
1.1       mike     4275: 
                   4276:      <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
                   4277:      <a href="#insertion-mode">insertion mode</a>.</p>
                   4278: 
1.91      mike     4279:      </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
                   4280:      RAWTEXT/RCDATA</a>".</p></li>
1.1       mike     4281: 
                   4282:     </ol></dd>
                   4283: 
                   4284:    <dt>An end tag whose tag name is "head"</dt>
                   4285:    <dd>
                   4286: 
                   4287:     <p>Pop the <a href="#current-node">current node</a> (which will be the
1.159     mike     4288:     <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     4289:     elements</a>.</p>
                   4290: 
                   4291:     <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>
                   4292: 
                   4293:    </dd>
                   4294: 
                   4295:    <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
                   4296:    <dd>
                   4297:     <p>Act as described in the "anything else" entry below.</p>
                   4298:    </dd>
                   4299: 
                   4300:    <dt>A start tag whose tag name is "head"</dt>
                   4301:    <dt>Any other end tag</dt>
                   4302:    <dd>
                   4303:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4304:    </dd>
                   4305: 
                   4306:    <dt>Anything else</dt>
                   4307:    <dd>
                   4308: 
                   4309:     <!-- can't get here with an EOF and a fragment case -->
                   4310: 
                   4311:     <p>Act as if an end tag token with the tag name "head" had
                   4312:     been seen, and reprocess the current token.</p>
                   4313: 
                   4314:    </dd>
                   4315: 
                   4316:   </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>
                   4317: 
                   4318:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inheadnoscript" title="insertion
                   4319:   mode: in head noscript">in head noscript</a>", tokens must be handled as follows:</p>
                   4320: 
                   4321:   <dl class="switch"><dt>A DOCTYPE token</dt>
                   4322:    <dd>
                   4323:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4324:    </dd>
                   4325: 
                   4326:    <dt>A start tag whose tag name is "html"</dt>
                   4327:    <dd>
                   4328:     <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
                   4329:     mode</a>.</p>
                   4330:    </dd>
                   4331: 
                   4332:    <dt>An end tag whose tag name is "noscript"</dt>
                   4333:    <dd>
                   4334: 
                   4335:     <p>Pop the <a href="#current-node">current node</a> (which will be a
                   4336:     <code><a href="semantics.html#the-noscript-element">noscript</a></code> element) from the <a href="#stack-of-open-elements">stack of open
                   4337:     elements</a>; the new <a href="#current-node">current node</a> will be a
1.159     mike     4338:     <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1       mike     4339: 
                   4340:     <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>
                   4341: 
                   4342:    </dd>
                   4343: 
                   4344:    <dt>A character token that is one of U+0009 CHARACTER
                   4345:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   4346:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   4347:    <dt>A comment token</dt>
                   4348:    <dt>A start tag whose tag name is one of: "link", "meta", "noframes", "style"</dt>
                   4349:    <dd>
                   4350:     <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
                   4351:     mode</a>.</p>
                   4352:    </dd>
                   4353: 
                   4354:    <dt>An end tag whose tag name is "br"</dt>
                   4355:    <dd>
                   4356:     <p>Act as described in the "anything else" entry below.</p>
                   4357:    </dd>
                   4358: 
                   4359:    <dt>A start tag whose tag name is one of: "head", "noscript"</dt>
                   4360:    <dt>Any other end tag</dt>
                   4361:    <dd>
                   4362:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4363:    </dd>
                   4364: 
                   4365:    <dt>Anything else</dt>
                   4366:    <dd>
                   4367: 
                   4368:     <!-- can't get here with an EOF and a fragment case -->
                   4369: 
                   4370:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
                   4371:     name "noscript" had been seen and reprocess the current
                   4372:     token.</p>
                   4373: 
                   4374:    </dd>
                   4375: 
                   4376:   </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>
                   4377: 
                   4378:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-head-insertion-mode" title="insertion
                   4379:   mode: after head">after head</a>", tokens must be handled as follows:</p>
                   4380: 
                   4381:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   4382:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   4383:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   4384:    <dd>
                   4385:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   4386:     the <a href="#current-node">current node</a>.</p>
                   4387:    </dd>
                   4388: 
                   4389:    <dt>A comment token</dt>
                   4390:    <dd>
                   4391:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   4392:     node</a> with the <code title="">data</code> attribute set to
                   4393:     the data given in the comment token.</p>
                   4394:    </dd>
                   4395: 
                   4396:    <dt>A DOCTYPE token</dt>
                   4397:    <dd>
                   4398:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4399:    </dd>
                   4400: 
                   4401:    <dt>A start tag whose tag name is "html"</dt>
                   4402:    <dd>
                   4403:     <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
                   4404:     mode</a>.</p>
                   4405:    </dd>
                   4406: 
                   4407:    <dt>A start tag whose tag name is "body"</dt>
                   4408:    <dd>
                   4409: 
                   4410:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4411: 
                   4412:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   4413: 
                   4414:     <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>
                   4415: 
                   4416:    </dd>
                   4417: 
                   4418:    <dt>A start tag whose tag name is "frameset"</dt>
                   4419:    <dd>
                   4420: 
                   4421:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4422: 
                   4423:     <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>
                   4424: 
                   4425:    </dd>
                   4426: 
                   4427:    <dt>A start tag token whose tag name is one of: "base", "link",
                   4428:    "meta", "noframes", "script", "style", "title"</dt>
                   4429:    <dd>
                   4430: 
                   4431:     <p><a href="#parse-error">Parse error</a>.</p>
                   4432: 
                   4433:     <p>Push the node pointed to by the <a href="#head-element-pointer"><code title="">head</code> element pointer</a> onto the
                   4434:     <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   4435: 
                   4436:     <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
                   4437:     mode</a>.</p>
                   4438: 
                   4439:     <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
                   4440:     of open elements</a>.</p>
                   4441: 
                   4442:     <p class="note">The <a href="#head-element-pointer"><code title="">head</code> element
                   4443:     pointer</a> cannot be null at this point.</p>
                   4444: 
                   4445:    </dd>
                   4446: 
                   4447:    <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
                   4448:    <dd>
                   4449:     <p>Act as described in the "anything else" entry below.</p>
                   4450:    </dd>
                   4451: 
                   4452:    <dt>A start tag whose tag name is "head"</dt>
                   4453:    <dt>Any other end tag</dt>
                   4454:    <dd>
                   4455:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4456:    </dd>
                   4457: 
                   4458:    <dt>Anything else</dt>
                   4459:    <dd>
                   4460:     <p>Act as if a start tag token with the tag name "body" and no
                   4461:     attributes had been seen, then set the <a href="#frameset-ok-flag">frameset-ok
                   4462:     flag</a> back to "ok", and then reprocess the current
                   4463:     token.</p>
                   4464:    </dd>
                   4465: 
                   4466:   </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>
                   4467: 
                   4468:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inbody" title="insertion
                   4469:   mode: in body">in body</a>", tokens must be handled as follows:</p>
                   4470: 
                   4471:   <dl class="switch"><dt>A character token</dt>
                   4472:    <dd>
                   4473: 
                   4474:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4475:     any.</p>
                   4476: 
                   4477:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   4478:     character</a> into the <a href="#current-node">current node</a>.</p>
                   4479: 
                   4480:     <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
                   4481:     LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
                   4482:     (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
                   4483:     flag</a> to "not ok".</p>
                   4484: 
                   4485:    </dd>
                   4486: 
                   4487:    <dt>A comment token</dt>
                   4488:    <dd>
                   4489:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   4490:     node</a> with the <code title="">data</code> attribute set to
                   4491:     the data given in the comment token.</p>
                   4492:    </dd>
                   4493: 
                   4494:    <dt>A DOCTYPE token</dt>
                   4495:    <dd>
                   4496:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4497:    </dd>
                   4498: 
                   4499:    <dt>A start tag whose tag name is "html"</dt>
                   4500:    <dd>
                   4501:     <p><a href="#parse-error">Parse error</a>. For each attribute on the token,
                   4502:     check to see if the attribute is already present on the top
                   4503:     element of the <a href="#stack-of-open-elements">stack of open elements</a>. If it is not,
                   4504:     add the attribute and its corresponding value to that element.</p>
                   4505:    </dd>
                   4506: 
                   4507:    <dt>A start tag token whose tag name is one of: "base", "command",
                   4508:    "link", "meta", "noframes", "script", "style", "title"</dt>
                   4509:    <dd>
                   4510:     <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
                   4511:     mode</a>.</p>
                   4512:    </dd>
                   4513: 
                   4514:    <dt>A start tag whose tag name is "body"</dt>
                   4515:    <dd>
                   4516: 
                   4517:     <p><a href="#parse-error">Parse error</a>.</p>
                   4518: 
                   4519:     <p>If the second element on the <a href="#stack-of-open-elements">stack of open
1.159     mike     4520:     elements</a> is not a <code><a href="semantics.html#the-body-element-0">body</a></code> element, or, if the
1.1       mike     4521:     <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
                   4522:     then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
                   4523: 
                   4524:     <p>Otherwise, for each attribute on the token, check to see if
1.159     mike     4525:     the attribute is already present on the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1       mike     4526:     element (the second element) on the <a href="#stack-of-open-elements">stack of open
                   4527:     elements</a>. If it is not, add the attribute and its
                   4528:     corresponding value to that element.</p>
                   4529: 
                   4530:    </dd>
                   4531: 
                   4532:    <dt>A start tag whose tag name is "frameset"</dt>
                   4533:    <dd>
                   4534: 
                   4535:     <p><a href="#parse-error">Parse error</a>.</p>
                   4536: 
                   4537:     <p>If the second element on the <a href="#stack-of-open-elements">stack of open
1.159     mike     4538:     elements</a> is not a <code><a href="semantics.html#the-body-element-0">body</a></code> element, or, if the
1.1       mike     4539:     <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
                   4540:     then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
                   4541: 
                   4542:     <p>If the <a href="#frameset-ok-flag">frameset-ok flag</a> is set to "not ok", ignore
                   4543:     the token.</p>
                   4544: 
                   4545:     <p>Otherwise, run the following steps:</p>
                   4546: 
                   4547:     <ol><li><p>Remove the second element on the <a href="#stack-of-open-elements">stack of open
                   4548:      elements</a> from its parent node, if it has one.</p></li>
                   4549: 
                   4550:      <li><p>Pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of
                   4551:      open elements</a>, from the <a href="#current-node">current node</a> up to,
1.159     mike     4552:      but not including, the root <code><a href="semantics.html#the-html-element-0">html</a></code> element.</p>
1.1       mike     4553: 
                   4554:      </li><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
                   4555:      token.</p></li>
                   4556: 
                   4557:      <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>
                   4558: 
                   4559:     </li></ol></dd>
                   4560: 
                   4561:    <dt>An end-of-file token</dt>
                   4562:    <dd>
                   4563: 
                   4564:     <p>If there is a node in the <a href="#stack-of-open-elements">stack of open elements</a>
1.422     mike     4565:     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>
                   4566:     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     4567:     <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
                   4568:     <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
                   4569:     <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     4570:     <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     4571:     this is a <a href="#parse-error">parse error</a>.</p> <!-- (some of those are
1.422     mike     4572:     fragment cases) -->
1.1       mike     4573: 
                   4574:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   4575: 
                   4576:    </dd>
                   4577: 
                   4578:    <dt>An end tag whose tag name is "body"</dt>
                   4579:    <dd>
                   4580: 
                   4581:     <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
                   4582:     in scope</a>, this is a <a href="#parse-error">parse error</a>; ignore the
                   4583:     token.</p>
                   4584: 
                   4585:     <!-- if we get here, the insertion mode here is forcibly "in
                   4586:     body". -->
                   4587: 
                   4588:     <p>Otherwise, if there is a node in the <a href="#stack-of-open-elements">stack of open
1.422     mike     4589:     elements</a> that is not either a <code><a href="semantics.html#the-dd-element">dd</a></code> element, a
1.1       mike     4590:     <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
                   4591:     <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
                   4592:     <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
                   4593:     <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
                   4594:     <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
                   4595:     <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     4596:     <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
                   4597:     <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     4598:     error</a>.</p> <!-- (some of those are fragment cases, e.g. for
                   4599:     <tbody> you'd have hit the first paragraph since the <body>
1.422     mike     4600:     wouldn't be in scope, unless it was a fragment case) -->
1.1       mike     4601: 
                   4602:     <!-- If we ever change the frameset-ok flag to an insertion mode,
                   4603:     then we'd have to somehow keep track of its state when we switch
                   4604:     to after-body. -->
                   4605: 
                   4606:     <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>
                   4607: 
                   4608:    </dd>
                   4609: 
                   4610:    <dt>An end tag whose tag name is "html"</dt>
                   4611:    <dd>
                   4612: 
                   4613:     <p>Act as if an end tag with tag name "body" had been seen,
                   4614:     then, if that token wasn't ignored, reprocess the current
                   4615:     token.</p>
                   4616: 
                   4617:     <p class="note">The fake end tag token here can only be
                   4618:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   4619: 
                   4620:    </dd>
                   4621: 
                   4622:    <!-- start tags for non-phrasing flow content elements -->
                   4623: 
                   4624:    <!-- the normal ones -->
                   4625:    <dt>A start tag whose tag name is one of: "address", "article",
1.86      mike     4626:    "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
1.305     mike     4627:    "details", "dir", "div", "dl", "fieldset", "figure", "footer",
                   4628:    "header", "hgroup", "menu", "nav", "ol", "p", "section", "ul"</dt>
1.1       mike     4629:    <dd>
                   4630: 
                   4631:     <!-- As of May 2008 this doesn't match any browser exactly, but is
                   4632:     as close to what IE does as I can get without doing the non-tree
                   4633:     DOM nonsense, and thus should actually afford better compatibility
                   4634:     when implemented by the other browsers. -->
                   4635: 
                   4636:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4637:     an element in scope">has a <code>p</code> element in
                   4638:     scope</a>, then act as if an end tag with the tag name
                   4639:     "p" had been seen.</p>
                   4640: 
                   4641:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4642: 
                   4643:    </dd>
                   4644: 
                   4645:    <!-- as normal, but close h1-h6 if it's the current node -->
                   4646:    <dt>A start tag whose tag name is one of: "h1", "h2", "h3", "h4",
                   4647:    "h5", "h6"</dt>
                   4648:    <dd>
                   4649: 
                   4650:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4651:     an element in scope">has a <code>p</code> element in
                   4652:     scope</a>, then act as if an end tag with the tag name
                   4653:     "p" had been seen.</p>
                   4654: 
                   4655:     <p>If the <a href="#current-node">current node</a> is an element whose tag name
                   4656:     is one of "h1", "h2", "h3", "h4", "h5", or "h6", then this is a
                   4657:     <a href="#parse-error">parse error</a>; pop the <a href="#current-node">current node</a> off
                   4658:     the <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   4659:     <!-- See https://bugs.webkit.org/show_bug.cgi?id=12646 -->
                   4660: 
                   4661:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4662: 
                   4663:    </dd>
                   4664: 
                   4665:    <!-- as normal, but drops leading newline -->
                   4666:    <dt>A start tag whose tag name is one of: "pre", "listing"</dt>
                   4667:    <dd>
                   4668: 
                   4669:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4670:     an element in scope">has a <code>p</code> element in
                   4671:     scope</a>, then act as if an end tag with the tag name
                   4672:     "p" had been seen.</p>
                   4673: 
                   4674:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4675: 
                   4676:     <p>If the next token is a U+000A LINE FEED (LF) character
                   4677:     token, then ignore that token and move on to the next
                   4678:     one. (Newlines at the start of <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are
                   4679:     ignored as an authoring convenience.)</p>
                   4680: 
                   4681:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   4682: 
                   4683:    </dd>
                   4684: 
                   4685:    <!-- as normal, but interacts with the form element pointer -->
                   4686:    <dt>A start tag whose tag name is "form"</dt>
                   4687:    <dd>
                   4688: 
                   4689:     <p>If the <a href="#form-element-pointer"><code title="form">form</code> element
                   4690:     pointer</a> is not null, then this is a <a href="#parse-error">parse
                   4691:     error</a>; ignore the token.</p>
                   4692: 
                   4693:     <p>Otherwise:</p>
                   4694: 
                   4695:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4696:     an element in scope">has a <code>p</code> element in
                   4697:     scope</a>, then act as if an end tag with the tag name
                   4698:     "p" had been seen.</p>
                   4699: 
                   4700:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, and set the
                   4701:     <a href="#form-element-pointer"><code title="form">form</code> element pointer</a> to
                   4702:     point to the element created.</p>
                   4703: 
                   4704:    </dd>
                   4705: 
                   4706:    <!-- as normal, but imply </li> when there's another <li> open in weird cases -->
                   4707:    <dt>A start tag whose tag name is "li"</dt>
                   4708:    <dd>
                   4709: 
                   4710:     <p>Run the following algorithm:</p>
                   4711: 
                   4712:     <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
                   4713: 
                   4714:      <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   4715:      node</a> (the bottommost node of the stack).</p></li>
                   4716: 
                   4717:      <li><p>If <var title="">node</var> is an <code><a href="semantics.html#the-li-element">li</a></code> element,
                   4718:      then act as if an end tag with the tag name "li" had
                   4719:      been seen, then jump to the last step.</p></li>
                   4720: 
                   4721:      <li><p><i>Loop</i>: If <var title="">node</var> is not in the
                   4722:      <a href="#formatting">formatting</a> category, and is not in the
                   4723:      <a href="#phrasing">phrasing</a> category, and is not an
1.306     mike     4724:      <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     4725:      element, then jump to the last step.</p></li> <!-- an element
                   4726:      <foo> is in this list if the following markup:
                   4727: 
                   4728:          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><ol><li><foo><li>
                   4729: 
                   4730:      ...results in the second <li> not being (in any way) a descendant
                   4731:      of the first <li>, or if <foo> is a formatting element that gets
                   4732:      reopened later. -->
                   4733: 
                   4734:      <li><p>Otherwise, set <var title="">node</var> to the previous
                   4735:      entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
                   4736:      the step labeled <i>loop</i>.</p></li>
                   4737: 
                   4738:      <li>
                   4739: 
                   4740:       <p>This is the last step.</p>
                   4741: 
                   4742:       <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4743:       an element in scope">has a <code>p</code> element in
                   4744:       scope</a>, then act as if an end tag with the tag name
                   4745:       "p" had been seen.</p>
                   4746: 
                   4747:       <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
                   4748:       token.</p>
                   4749: 
                   4750:      </li>
                   4751: 
                   4752:     </ol></dd>
                   4753: 
                   4754:    <!-- as normal, but imply </dt> or </dd> when there's another <dt> or <dd> open in weird cases  -->
1.422     mike     4755:    <dt>A start tag whose tag name is one of: "dd", "dt"</dt>
1.1       mike     4756:    <dd>
                   4757: 
                   4758:     <p>Run the following algorithm:</p>
                   4759: 
                   4760:     <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
                   4761: 
                   4762:      <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   4763:      node</a> (the bottommost node of the stack).</p></li>
                   4764: 
                   4765:      <li><p><i>Loop</i>: If <var title="">node</var> is a
1.422     mike     4766:      <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
                   4767:      tag with the same tag name as <var title="">node</var> had been
                   4768:      seen, then jump to the last step.</p></li>
1.1       mike     4769: 
                   4770:      <li><p>If <var title="">node</var> is not in the
                   4771:      <a href="#formatting">formatting</a> category, and is not in the
                   4772:      <a href="#phrasing">phrasing</a> category, and is not an
1.306     mike     4773:      <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     4774:      element, then jump to the last step.</p></li> <!-- an element
                   4775:      <foo> is in this list if the following markup:
                   4776: 
                   4777:          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><dl><dt><foo><dt>
                   4778: 
                   4779:      ...results in the second <dt> not being (in any way) a descendant
                   4780:      of the first <dt>, or if <foo> is a formatting element that gets
                   4781:      reopened later. -->
                   4782: 
                   4783:      <li><p>Otherwise, set <var title="">node</var> to the previous
                   4784:      entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
                   4785:      the step labeled <i>loop</i>.</p></li>
                   4786: 
                   4787:      <li>
                   4788: 
                   4789:       <p>This is the last step.</p>
                   4790: 
                   4791:       <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4792:       an element in scope">has a <code>p</code> element in
                   4793:       scope</a>, then act as if an end tag with the tag name
                   4794:       "p" had been seen.</p>
                   4795: 
                   4796:       <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
                   4797:       token.</p>
                   4798: 
                   4799:      </li>
                   4800: 
                   4801:     </ol></dd>
                   4802: 
                   4803:    <!-- same as normal, but effectively ends parsing -->
                   4804:    <dt>A start tag whose tag name is "plaintext"</dt>
                   4805:    <dd>
                   4806: 
                   4807:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4808:     an element in scope">has a <code>p</code> element in
                   4809:     scope</a>, then act as if an end tag with the tag name
                   4810:     "p" had been seen.</p>
                   4811: 
                   4812:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4813: 
                   4814:     <p>Switch the <a href="#content-model-flag">content model flag</a> to the PLAINTEXT
                   4815:     state.</p>
                   4816: 
                   4817:     <p class="note">Once a start tag with the tag name "plaintext"
                   4818:     has been seen, that will be the last token ever seen other
                   4819:     than character tokens (and the end-of-file token), because
                   4820:     there is no way to switch the <a href="#content-model-flag">content model flag</a>
                   4821:     out of the PLAINTEXT state.</p>
                   4822: 
                   4823:    </dd>
                   4824: 
                   4825:    <!-- end tags for non-phrasing flow content elements -->
                   4826: 
                   4827:    <!-- the normal ones -->
                   4828:    <dt>An end tag whose tag name is one of: "address", "article",
1.86      mike     4829:    "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
1.305     mike     4830:    "details", "dir", "div", "dl", "fieldset", "figure", "footer",
                   4831:    "header", "hgroup", "listing", "menu", "nav", "ol", "pre",
                   4832:    "section", "ul"</dt>
1.1       mike     4833:    <dd>
                   4834: 
                   4835:     <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>
                   4836:     with the same tag name as that of the token, then this is a
                   4837:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4838: 
                   4839:     <p>Otherwise, run these steps:</p>
                   4840: 
                   4841:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   4842: 
                   4843:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4844:      the same tag name as that of the token, then this is a
                   4845:      <a href="#parse-error">parse error</a>.</p></li>
                   4846: 
                   4847:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4848:      until an element with the same tag name as the token has been
                   4849:      popped from the stack.</p></li>
                   4850: 
                   4851:     </ol></dd>
                   4852: 
                   4853:    <!-- removes the form element pointer instead of the matching node -->
                   4854:    <dt>An end tag whose tag name is "form"</dt>
                   4855:    <dd>
                   4856: 
                   4857:     <p>Let <var title="">node</var> be the element that the
                   4858:     <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is set
                   4859:     to.</p>
                   4860: 
                   4861:     <p>Set the <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
                   4862:     to null.</p>
                   4863: 
                   4864:     <p>If <var title="">node</var> is null or the <a href="#stack-of-open-elements">stack of open
                   4865:     elements</a> does not <a href="#has-an-element-in-scope" title="has an element in
                   4866:     scope">have <var title="">node</var> in scope</a>, then this is
                   4867:     a <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4868: 
                   4869:     <p>Otherwise, run these steps:</p>
                   4870: 
                   4871:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   4872: 
                   4873:      <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
                   4874:      error</a>.</p></li>
                   4875: 
                   4876:      <li><p>Remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of
                   4877:      open elements</a>.</p></li>
                   4878: 
                   4879:     </ol></dd>
                   4880: 
                   4881:    <!-- as normal, except </p> implies <p> if there's no <p> in scope, and needs care as the elements have optional tags -->
                   4882:    <dt>An end tag whose tag name is "p"</dt>
                   4883:    <dd>
                   4884: 
                   4885:     <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>
                   4886:     with the same tag name as that of the token, then this is a
                   4887:     <a href="#parse-error">parse error</a>; act as if a start tag with the tag name
                   4888:     "p" had been seen, then reprocess the current token.</p>
                   4889: 
                   4890:     <p>Otherwise, run these steps:</p>
                   4891: 
                   4892:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
                   4893:      for elements with the same tag name as the token.</p></li>
                   4894: 
                   4895:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4896:      the same tag name as that of the token, then this is a
                   4897:      <a href="#parse-error">parse error</a>.</p></li>
                   4898: 
                   4899:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4900:      until an element with the same tag name as the token has been
                   4901:      popped from the stack.</p></li>
                   4902: 
                   4903:     </ol></dd>
                   4904: 
1.234     mike     4905:    <!-- as normal, but needs care as the elements have optional tags, and are further scoped by <ol>/<ul> -->
                   4906:    <dt>An end tag whose tag name is "li"</dt>
                   4907:    <dd>
                   4908: 
                   4909:     <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
                   4910:     item scope</a> with the same tag name as that of the token,
                   4911:     then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4912: 
                   4913:     <p>Otherwise, run these steps:</p>
                   4914: 
                   4915:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
                   4916:      for elements with the same tag name as the token.</p></li>
                   4917: 
                   4918:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4919:      the same tag name as that of the token, then this is a
                   4920:      <a href="#parse-error">parse error</a>.</p></li>
                   4921: 
                   4922:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4923:      until an element with the same tag name as the token has been
                   4924:      popped from the stack.</p></li>
                   4925: 
                   4926:     </ol></dd>
                   4927: 
1.1       mike     4928:    <!-- as normal, but needs care as the elements have optional tags -->
1.422     mike     4929:    <dt>An end tag whose tag name is one of: "dd", "dt"</dt>
1.1       mike     4930:    <dd>
                   4931: 
                   4932:     <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>
                   4933:     with the same tag name as that of the token, then this is a
                   4934:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4935: 
                   4936:     <p>Otherwise, run these steps:</p>
                   4937: 
                   4938:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
                   4939:      for elements with the same tag name as the token.</p></li>
                   4940: 
                   4941:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4942:      the same tag name as that of the token, then this is a
                   4943:      <a href="#parse-error">parse error</a>.</p></li>
                   4944: 
                   4945:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4946:      until an element with the same tag name as the token has been
                   4947:      popped from the stack.</p></li>
                   4948: 
                   4949:     </ol></dd>
                   4950: 
                   4951:    <!-- as normal, except acts as a closer for any of the h1-h6 elements -->
                   4952:    <dt>An end tag whose tag name is one of: "h1", "h2", "h3", "h4", "h5", "h6"</dt>
                   4953:    <dd>
                   4954: 
                   4955:     <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>
                   4956:     whose tag name is one of "h1", "h2", "h3", "h4", "h5", or "h6",
                   4957:     then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4958: 
                   4959:     <p>Otherwise, run these steps:</p>
                   4960: 
                   4961:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   4962: 
                   4963:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4964:      the same tag name as that of the token, then this is a
                   4965:      <a href="#parse-error">parse error</a>.</p></li>
                   4966: 
                   4967:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4968:      until an element whose tag name is one of "h1", "h2", "h3", "h4",
                   4969:      "h5", or "h6" has been popped from the stack.</p></li>
                   4970: 
                   4971:     </ol></dd>
                   4972: 
                   4973:    <dt>An end tag whose tag name is "sarcasm"</dt>
                   4974:    <dd>
                   4975:     <p>Take a deep breath, then act as described in the "any other end
                   4976:     tag" entry below.</p>
                   4977:    </dd>
                   4978: 
                   4979:    <!-- ADOPTION AGENCY ELEMENTS
                   4980:         Mozilla-only: bdo blink del ins sub sup q
                   4981:         Safari-only: code dfn kbd nobr samp var wbr
                   4982:         Both: a b big em font i s small strike strong tt u -->
                   4983: 
                   4984:    <dt>A start tag whose tag name is "a"</dt>
                   4985:    <dd>
                   4986: 
                   4987:     <p>If the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>
                   4988:     contains an element whose tag name is "a" between the end of
                   4989:     the list and the last marker on the list (or the start of the
                   4990:     list if there is no marker on the list), then this is a
                   4991:     <a href="#parse-error">parse error</a>; act as if an end tag with the tag
                   4992:     name "a" had been seen, then remove that element from the
                   4993:     <a href="#list-of-active-formatting-elements">list of active formatting elements</a> and the
                   4994:     <a href="#stack-of-open-elements">stack of open elements</a> if the end tag didn't
                   4995:     already remove it (it might not have if the element is not
                   4996:     <a href="#has-an-element-in-table-scope" title="has an element in table scope">in table
                   4997:     scope</a>).</p>
                   4998: 
                   4999:     <p class="example">In the non-conforming stream
                   5000:     <code>&lt;a&#160;href="a"&gt;a&lt;table&gt;&lt;a&#160;href="b"&gt;b&lt;/table&gt;x</code>,
                   5001:     the first <code><a href="text-level-semantics.html#the-a-element">a</a></code> element would be closed upon seeing
                   5002:     the second one, and the "x" character would be inside a link
                   5003:     to "b", not to "a". This is despite the fact that the outer
                   5004:     <code><a href="text-level-semantics.html#the-a-element">a</a></code> element is not in table scope (meaning that a
                   5005:     regular <code>&lt;/a&gt;</code> end tag at the start of the table
                   5006:     wouldn't close the outer <code><a href="text-level-semantics.html#the-a-element">a</a></code> element).</p>
                   5007: 
                   5008:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5009:     any.</p>
                   5010: 
                   5011:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
                   5012:     element to the <a href="#list-of-active-formatting-elements">list of active formatting
                   5013:     elements</a>.</p>
                   5014: 
                   5015:    </dd>
                   5016: 
                   5017:    <dt>A start tag whose tag name is one of: "b", "big", "code", "em",
                   5018:    "font", "i", "s", "small", "strike", "strong", "tt", "u"</dt>
                   5019:    <dd>
                   5020: 
                   5021:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5022:     any.</p>
                   5023: 
                   5024:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
                   5025:     element to the <a href="#list-of-active-formatting-elements">list of active formatting
                   5026:     elements</a>.</p>
                   5027: 
                   5028:    </dd>
                   5029: 
                   5030:    <dt>A start tag whose tag name is "nobr"</dt>
                   5031:    <dd>
                   5032: 
                   5033:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5034:     any.</p>
                   5035: 
                   5036:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
                   5037:     element in scope">has a <code>nobr</code> element in scope</a>,
                   5038:     then this is a <a href="#parse-error">parse error</a>; act as if an end tag with
                   5039:     the tag name "nobr" had been seen, then once again
                   5040:     <a href="#reconstruct-the-active-formatting-elements">reconstruct the active formatting elements</a>, if
                   5041:     any.</p>
                   5042: 
                   5043:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
                   5044:     element to the <a href="#list-of-active-formatting-elements">list of active formatting
                   5045:     elements</a>.</p>
                   5046: 
                   5047:    </dd>
                   5048: 
                   5049:    <dt id="adoptionAgency">An end tag whose tag name is one of: "a",
                   5050:    "b", "big", "code", "em", "font", "i", "nobr", "s", "small",
                   5051:    "strike", "strong", "tt", "u"</dt>
                   5052:    <dd>
                   5053: 
                   5054:     <p>Follow these steps:</p>
                   5055: 
                   5056:     <ol><li>
                   5057: 
                   5058:       <p>Let the <var title="">formatting element</var> be the
                   5059:       last element in the <a href="#list-of-active-formatting-elements">list of active formatting
                   5060:       elements</a> that:</p>
                   5061: 
                   5062:       <ul><li>is between the end of the list and the last scope
                   5063:        marker in the list, if any, or the start of the list
                   5064:        otherwise, and</li>
                   5065: 
                   5066:        <li>has the same tag name as the token.</li>
                   5067: 
                   5068:       </ul><p>If there is no such node, or, if that node is also in the
                   5069:       <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
                   5070:       <a href="#parse-error">parse error</a>; ignore the token, and abort these
                   5071:       steps.</p>
                   5072: 
                   5073:       <p>Otherwise, if there is such a node, but that node is not
                   5074:       in the <a href="#stack-of-open-elements">stack of open elements</a>, then this is a
                   5075:       <a href="#parse-error">parse error</a>; remove the element from the list,
                   5076:       and abort these steps.</p>
                   5077: 
                   5078:       <p>Otherwise, there is a <var title="">formatting
                   5079:       element</var> and that element is in <a href="#stack-of-open-elements" title="stack of
                   5080:       open elements">the stack</a> and is <a href="#has-an-element-in-scope" title="has an
                   5081:       element in scope">in scope</a>. If the element is not the
                   5082:       <a href="#current-node">current node</a>, this is a <a href="#parse-error">parse
                   5083:       error</a>. In any case, proceed with the algorithm as
                   5084:       written in the following steps.</p>
                   5085: 
                   5086:      </li>
                   5087: 
                   5088:      <li><p>Let the <var title="">furthest block</var> be the
                   5089:      topmost node in the <a href="#stack-of-open-elements">stack of open elements</a> that
                   5090:      is lower in the stack than the <var title="">formatting
                   5091:      element</var>, and is not an element in the
                   5092:      <a href="#phrasing">phrasing</a> or <a href="#formatting">formatting</a>
                   5093:      categories. There might not be one.</p></li>
                   5094: 
                   5095:      <li><p>If there is no <var title="">furthest block</var>,
                   5096:      then the UA must skip the subsequent steps and instead just
                   5097:      pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of open
                   5098:      elements</a>, from the <a href="#current-node">current node</a> up to and
                   5099:      including the <var title="">formatting element</var>, and
                   5100:      remove the <var title="">formatting element</var> from the
                   5101:      <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</p></li>
                   5102: 
                   5103:      <li><p>Let the <var title="">common ancestor</var> be the element
                   5104:      immediately above the <var title="">formatting element</var> in the
                   5105:      <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
                   5106: 
                   5107:      <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
                   5108:      formatting elements</a> relative to the elements on either
                   5109:      side of it in the list.</p></li>
                   5110: 
                   5111:      <li>
                   5112: 
                   5113:       <p>Let <var title="">node</var> and <var title="">last node</var> be the
                   5114:       <var title="">furthest block</var>. Follow these steps:</p>
                   5115: 
                   5116:       <ol><li>Let <var title="">node</var> be the element immediately
                   5117:        above <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
1.436     mike     5118:        elements</a>, or if <var title="">node</var> is no longer in
                   5119:        the <a href="#stack-of-open-elements">stack of open elements</a> (e.g. because it got
                   5120:        removed by the next step), the element that was immediately
                   5121:        above <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
                   5122:        elements</a> before <var title="">node</var> was
                   5123:        removed.</li>
1.1       mike     5124: 
                   5125:        <li>If <var title="">node</var> is not in the <a href="#list-of-active-formatting-elements">list of
                   5126:        active formatting elements</a>, then remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of open
                   5127:        elements</a> and then go back to step 1.</li>
                   5128: 
                   5129:        <li>Otherwise, if <var title="">node</var> is the <var title="">formatting element</var>, then go to the next step
                   5130:        in the overall algorithm.</li>
                   5131: 
                   5132:        <li>Otherwise, if <var title="">last node</var> is the <var title="">furthest block</var>, then move the aforementioned
                   5133:        bookmark to be immediately after the <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
                   5134:        elements</a>.</li>
                   5135: 
                   5136:        <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
                   5137:        element <var title="">node</var> was created, replace the entry
                   5138:        for <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active
                   5139:        formatting elements</a> with an entry for the new element,
                   5140:        replace the entry for <var title="">node</var> in the
                   5141:        <a href="#stack-of-open-elements">stack of open elements</a> with an entry for the new
                   5142:        element, and let <var title="">node</var> be the new
                   5143:        element.</li>
                   5144: 
                   5145:        <li>Insert <var title="">last node</var> into <var title="">node</var>, first removing it from its previous
                   5146:        parent node if any.</li>
                   5147: 
                   5148:        <li>Let <var title="">last node</var> be <var title="">node</var>.</li>
                   5149: 
                   5150:        <li>Return to step 1 of this inner set of steps.</li>
                   5151: 
                   5152:       </ol></li>
                   5153: 
                   5154:      <li>
                   5155: 
                   5156:       <p>If the <var title="">common ancestor</var> node is a
                   5157:       <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>,
                   5158:       <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,
                   5159:       <a href="#foster-parent">foster parent</a> whatever <var title="">last
                   5160:       node</var> ended up being in the previous step, first removing
                   5161:       it from its previous parent node if any.</p>
                   5162: 
                   5163:       <p>Otherwise, append whatever <var title="">last node</var>
                   5164:       ended up being in the previous step to the <var title="">common
                   5165:       ancestor</var> node, first removing it from its previous parent
                   5166:       node if any.</p>
                   5167: 
                   5168:      </li>
                   5169: 
                   5170:      <li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
                   5171:      <var title="">formatting element</var> was created.</p></li>
                   5172: 
                   5173:      <li><p>Take all of the child nodes of the <var title="">furthest
                   5174:      block</var> and append them to the element created in the last
                   5175:      step.</p></li>
                   5176: 
                   5177:      <li><p>Append that new element to the <var title="">furthest
                   5178:      block</var>.</p></li>
                   5179: 
                   5180:      <li><p>Remove the <var title="">formatting element</var> from the
                   5181:      <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, and insert the
                   5182:      new element into the <a href="#list-of-active-formatting-elements">list of active formatting
                   5183:      elements</a> at the position of the aforementioned
                   5184:      bookmark.</p></li>
                   5185: 
                   5186:      <li><p>Remove the <var title="">formatting element</var> from the
                   5187:      <a href="#stack-of-open-elements">stack of open elements</a>, and insert the new element
                   5188:      into the <a href="#stack-of-open-elements">stack of open elements</a> immediately below
                   5189:      the position of the <var title="">furthest block</var> in that
                   5190:      stack.</p></li>
                   5191: 
                   5192:      <li><p>Jump back to step 1 in this series of steps.</p></li>
                   5193: 
1.334     mike     5194:     </ol><p class="note">Because of the way this algorithm causes elements
1.304     mike     5195:     to change parents, it has been dubbed the "adoption agency
                   5196:     algorithm" (in contrast with other possible algorithms for dealing
                   5197:     with misnested content, which included the "incest algorithm", the
1.1       mike     5198:     "secret affair algorithm", and the "Heisenberg algorithm").</p>
                   5199: 
                   5200:    </dd>
                   5201: 
                   5202:    <dt>A start tag whose tag name is "button"</dt>
                   5203:    <dd>
                   5204: 
                   5205:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   5206:     an element in scope">has a <code>button</code> element in
                   5207:     scope</a>, then this is a <a href="#parse-error">parse error</a>;
                   5208:     act as if an end tag with the tag name "button" had been seen,
                   5209:     then reprocess the token.</p>
                   5210: 
                   5211:     <p>Otherwise:</p>
                   5212: 
                   5213:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5214:     any.</p>
                   5215: 
                   5216:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5217: 
                   5218:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   5219:     formatting elements</a>.</p>
                   5220: 
                   5221:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5222: 
                   5223:    </dd>
                   5224: 
                   5225:    <dt>A start tag token whose tag name is one of: "applet",
                   5226:    "marquee", "object"</dt>
                   5227:    <dd>
                   5228: 
                   5229:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5230:     any.</p>
                   5231: 
                   5232:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5233: 
                   5234:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   5235:     formatting elements</a>.</p>
                   5236: 
                   5237:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5238: 
                   5239:    </dd>
                   5240: 
                   5241:    <dt>An end tag token whose tag name is one of: "applet", "button",
                   5242:    "marquee", "object"</dt>
                   5243:    <dd>
                   5244: 
                   5245:     <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>
                   5246:     with the same tag name as that of the token, then this is a
                   5247:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   5248: 
                   5249:     <p>Otherwise, run these steps:</p>
                   5250: 
                   5251:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   5252: 
                   5253:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   5254:      the same tag name as that of the token, then this is a
                   5255:      <a href="#parse-error">parse error</a>.</p></li>
                   5256: 
                   5257:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   5258:      until an element with the same tag name as the token has been
                   5259:      popped from the stack.</p></li>
                   5260: 
                   5261:      <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
                   5262:      last marker</a>.</li>
                   5263: 
                   5264:     </ol></dd>
                   5265: 
                   5266:    <dt>A start tag whose tag name is "table"</dt>
                   5267:    <dd>
                   5268: 
                   5269:     <p>If the <code>Document</code> is <em>not</em> set to
                   5270:     <a href="dom.html#quirks-mode">quirks mode</a>, and the <a href="#stack-of-open-elements">stack of open
                   5271:     elements</a> <a href="#has-an-element-in-scope" title="has an element in scope">has a
                   5272:     <code>p</code> element in scope</a>, then act as if an end tag
                   5273:     with the tag name "p" had been seen.</p> <!-- i hate myself (this
                   5274:     quirk was basically caused by acid2; if i'd realised we could
                   5275:     change the specs when i wrote acid2, we could have avoided having
                   5276:     any parsing-mode quirks) -Hixie -->
                   5277: 
                   5278:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5279: 
                   5280:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5281: 
                   5282:     <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>
                   5283: 
                   5284:    </dd>
                   5285: 
                   5286:    <dt>A start tag whose tag name is one of: "area", "basefont",
                   5287:    "bgsound", "br", "embed", "img", "input", "keygen", "spacer",
                   5288:    "wbr"</dt>
                   5289:    <dd>
                   5290: 
                   5291:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5292:     any.</p>
                   5293: 
                   5294:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5295:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5296:     elements</a>.</p>
                   5297: 
                   5298:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5299:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5300: 
                   5301:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p> <!--
                   5302:     shouldn't really do it for <area>, <basefont>, <bgsound>, and
                   5303:     <spacer> -->
                   5304: 
                   5305:    </dd>
                   5306: 
                   5307:    <dt>A start tag whose tag name is one of: "param", "source"</dt>
                   5308:    <dd>
                   5309: 
                   5310:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5311:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5312:     elements</a>.</p>
                   5313: 
                   5314:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5315:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5316: 
                   5317:    </dd>
                   5318: 
                   5319:    <dt>A start tag whose tag name is "hr"</dt>
                   5320:    <dd>
                   5321: 
                   5322:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   5323:     an element in scope">has a <code>p</code> element in
                   5324:     scope</a>, then act as if an end tag with the tag name
                   5325:     "p" had been seen.</p>
                   5326: 
                   5327:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5328:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5329:     elements</a>.</p>
                   5330: 
                   5331:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5332:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5333: 
                   5334:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5335: 
                   5336:    </dd>
                   5337: 
                   5338:    <dt>A start tag whose tag name is "image"</dt>
                   5339:    <dd>
                   5340:     <p><a href="#parse-error">Parse error</a>. Change the token's tag name
                   5341:     to "img" and reprocess it. (Don't ask.)</p> <!-- As of
                   5342:     2005-12, studies showed that around 0.2% of pages used the
                   5343:     <image> element. -->
                   5344:    </dd>
                   5345: 
                   5346:    <dt id="isindex">A start tag whose tag name is "isindex"</dt>
                   5347:    <dd>
                   5348: 
                   5349:     <p><a href="#parse-error">Parse error</a>.</p>
                   5350: 
                   5351:     <p>If the <a href="#form-element-pointer"><code title="">form</code> element
                   5352:     pointer</a> is not null, then ignore the token.</p>
                   5353: 
                   5354:     <p>Otherwise:</p>
                   5355: 
                   5356:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5357:     token's <i>self-closing flag</i></a>, if it is set.</p> <!--
                   5358:     purely to reduce the number of errors (we don't care if they
                   5359:     included the /, they're not supposed to be including the tag at
                   5360:     all! -->
                   5361: 
                   5362:     <p>Act as if a start tag token with the tag name "form" had been seen.</p>
                   5363: 
                   5364:     <p>If the token has an attribute called "action", set the
                   5365:     <code title="attr-form-action">action</code> attribute on the
                   5366:     resulting <code><a href="forms.html#the-form-element">form</a></code> element to the value of the
                   5367:     "action" attribute of the token.</p>
                   5368: 
                   5369:     <p>Act as if a start tag token with the tag name "hr" had been
                   5370:     seen.</p>
                   5371: 
                   5372:     <p>Act as if a start tag token with the tag name "label" had been
                   5373:     seen.</p>
                   5374: 
                   5375:     <p>Act as if a stream of character tokens had been seen (see below
                   5376:     for what they should say).</p>
                   5377: 
                   5378:     <p>Act as if a start tag token with the tag name "input" had been
                   5379:     seen, with all the attributes from the "isindex" token except
                   5380:     "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
                   5381:     <code><a href="forms.html#the-input-element">input</a></code> element to the value "<code title="">isindex</code>".</p>
                   5382: 
                   5383:     <p>Act as if a stream of character tokens had been seen (see
                   5384:     below for what they should say).</p>
                   5385: 
                   5386:     <p>Act as if an end tag token with the tag name "label" had been
                   5387:     seen.</p>
                   5388: 
                   5389:     <p>Act as if a start tag token with the tag name "hr" had been
                   5390:     seen.</p>
                   5391: 
                   5392:     <p>Act as if an end tag token with the tag name "form" had been
                   5393:     seen.</p>
                   5394: 
                   5395:     <p>If the token has an attribute with the name "prompt", then the
                   5396:     first stream of characters must be the same string as given in
                   5397:     that attribute, and the second stream of characters must be
                   5398:     empty. Otherwise, the two streams of character tokens together
                   5399:     should, together with the <code><a href="forms.html#the-input-element">input</a></code> element, express the
                   5400:     equivalent of "This is a searchable index. Insert your search
                   5401:     keywords here: (input field)" in the user's preferred
                   5402:     language.</p>
                   5403: 
                   5404:    </dd>
                   5405: 
                   5406:    <dt>A start tag whose tag name is "textarea"</dt>
                   5407:    <dd>
                   5408: 
                   5409:     <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
                   5410:      token.</p></li>
                   5411: 
                   5412:      <li><p>If the next token is a U+000A LINE FEED (LF) character
                   5413:      token, then ignore that token and move on to the next
                   5414:      one. (Newlines at the start of <code><a href="forms.html#the-textarea-element">textarea</a></code> elements are
                   5415:      ignored as an authoring convenience.)</p></li>
                   5416: 
                   5417:      <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
                   5418:      the RCDATA state.</p></li>
                   5419: 
                   5420:      <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the
                   5421:      current <a href="#insertion-mode">insertion mode</a>.</p>
                   5422: 
                   5423:      </li><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not
                   5424:      ok".</p></li>
                   5425: 
1.91      mike     5426:      <li><p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: in RAWTEXT/RCDATA">in
                   5427:      RAWTEXT/RCDATA</a>".</p></li>
1.1       mike     5428: 
                   5429:     </ol></dd>
                   5430: 
                   5431:    <dt>A start tag whose tag name is "xmp"</dt>
                   5432:    <dd>
                   5433: 
1.233     mike     5434:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   5435:     an element in scope">has a <code>p</code> element in
                   5436:     scope</a>, then act as if an end tag with the tag name
                   5437:     "p" had been seen.</p>
                   5438: 
1.1       mike     5439:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5440:     any.</p>
                   5441: 
                   5442:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5443: 
1.91      mike     5444:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     5445: 
                   5446:    </dd>
                   5447: 
                   5448:    <dt>A start tag whose tag name is "iframe"</dt>
                   5449:    <dd>
                   5450: 
                   5451:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5452: 
1.91      mike     5453:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     5454: 
                   5455:    </dd>
                   5456: 
                   5457:    <dt>A start tag whose tag name is "noembed"</dt>
                   5458:    <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
                   5459:    <dd>
                   5460: 
1.91      mike     5461:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     5462: 
                   5463:    </dd>
                   5464: 
                   5465:    <dt>A start tag whose tag name is "select"</dt>
                   5466:    <dd>
                   5467: 
                   5468:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5469:     any.</p>
                   5470: 
                   5471:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5472: 
                   5473:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5474: 
                   5475:     <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>",
                   5476:     "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   5477:     body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in
                   5478:     row</a>", or "<a href="#parsing-main-intd" title="insertion mode: in cell">in
                   5479:     cell</a>", then switch the <a href="#insertion-mode">insertion mode</a> to
                   5480:     "<a href="#parsing-main-inselectintable" title="insertion mode: in select in table">in select in
                   5481:     table</a>". Otherwise, switch the <a href="#insertion-mode">insertion mode</a>
                   5482:     to "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>".</p>
                   5483: 
                   5484:    </dd>
                   5485: 
                   5486:    <dt>A start tag whose tag name is one of: "optgroup", "option"</dt>
                   5487:    <dd>
                   5488: 
                   5489:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
                   5490:     element in scope">has an <code>option</code> element in
                   5491:     scope</a>, then act as if an end tag with the tag name "option"
                   5492:     had been seen.</p>
                   5493: 
                   5494:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5495:     any.</p>
                   5496: 
                   5497:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5498: 
                   5499:    </dd>
                   5500: 
                   5501:    <dt>A start tag whose tag name is one of: "rp", "rt"</dt>
                   5502:    <dd>
                   5503: 
                   5504:     <!-- the parsing rules for ruby really don't match IE much at all,
                   5505:          but in practice the markup used is very simple and so strict
                   5506:          compatibility with IE isn't required. For example, as defined
                   5507:          here we get very, very different behaviour than IE for
                   5508:          pathological cases like:
                   5509: 
                   5510:            <ruby><ol><li><p>a<rt>b
                   5511:            <ruby>a<rt>b<p>c
                   5512: 
                   5513:          But in practice most ruby markup falls into these cases:
                   5514: 
                   5515:            <ruby>a<rt>b</ruby>
                   5516:            <ruby>a<rp>b<rt>c<rp>d</ruby>
                   5517:            <ruby>a<rt>b</rt></ruby>
                   5518:            <ruby>a<rp>b</rp><rt>c</rt><rp>d</rp></ruby>
                   5519: 
                   5520:     -->
                   5521: 
                   5522:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
                   5523:     element in scope">has a <code>ruby</code> element in scope</a>,
                   5524:     then <a href="#generate-implied-end-tags">generate implied end tags</a>. If the <a href="#current-node">current
                   5525:     node</a> is not then a <code><a href="text-level-semantics.html#the-ruby-element">ruby</a></code> element, this is a
                   5526:     <a href="#parse-error">parse error</a>; pop all the nodes from the <a href="#current-node">current
                   5527:     node</a> up to the node immediately before the bottommost
                   5528:     <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
                   5529:     elements</a>.</p>
                   5530: 
                   5531:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5532: 
                   5533:    </dd>
                   5534: 
                   5535:    <dt>An end tag whose tag name is "br"</dt>
                   5536:    <dd>
                   5537:     <p><a href="#parse-error">Parse error</a>. Act as if a start tag token with
                   5538:     the tag name "br" had been seen. Ignore the end tag token.</p>
                   5539:    </dd>
                   5540: 
                   5541:    <dt>A start tag whose tag name is "math"</dt>
                   5542:    <dd>
                   5543: 
                   5544:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5545:     any.</p>
                   5546: 
                   5547:     <p><a href="#adjust-mathml-attributes">Adjust MathML attributes</a> for the token. (This
                   5548:     fixes the case of MathML attributes that are not all
                   5549:     lowercase.)</p>
                   5550: 
                   5551:     <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
                   5552:     fixes the use of namespaced attributes, in particular XLink.)</p>
                   5553: 
                   5554:     <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
                   5555:     <a href="#mathml-namespace">MathML namespace</a>.</p>
                   5556: 
                   5557:     <!-- If we ever change the frameset-ok flag to an insertion mode,
                   5558:     the following change would be implied, except we'd have to do it
                   5559:     even in the face of a self-closed tag:
                   5560:     <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
                   5561:     -->
                   5562: 
                   5563:     <p>If the token has its <i>self-closing flag</i> set, pop the
                   5564:     <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5565:     elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
                   5566:     flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
                   5567: 
                   5568:     <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
                   5569:     "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
                   5570:     content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
                   5571:     the current <a href="#insertion-mode">insertion mode</a>, and then switch the
                   5572:     <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
                   5573:     foreign content">in foreign content</a>".</p>
                   5574: 
                   5575:    </dd>
                   5576: 
                   5577:    <dt>A start tag whose tag name is "svg"</dt>
                   5578:    <dd>
                   5579: 
                   5580:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5581:     any.</p>
                   5582: 
                   5583:     <p><a href="#adjust-svg-attributes">Adjust SVG attributes</a> for the token. (This fixes
                   5584:     the case of SVG attributes that are not all lowercase.)</p>
                   5585: 
                   5586:     <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
                   5587:     fixes the use of namespaced attributes, in particular XLink in
                   5588:     SVG.)</p>
                   5589: 
                   5590:     <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
                   5591:     <a href="#svg-namespace">SVG namespace</a>.</p>
                   5592: 
                   5593:     <!-- If we ever change the frameset-ok flag to an insertion mode,
                   5594:     the following change would be implied, except we'd have to do it
                   5595:     even in the face of a self-closed tag:
                   5596:     <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
                   5597:     -->
                   5598: 
                   5599:     <p>If the token has its <i>self-closing flag</i> set, pop the
                   5600:     <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5601:     elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
                   5602:     flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
                   5603: 
                   5604:     <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
                   5605:     "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
                   5606:     content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
                   5607:     the current <a href="#insertion-mode">insertion mode</a>, and then switch the
                   5608:     <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
                   5609:     foreign content">in foreign content</a>".</p>
                   5610: 
                   5611:    </dd>
                   5612: 
                   5613:    <dt>A start <!--or end--> tag whose tag name is one of: "caption",
                   5614:    "col", "colgroup", "frame", "head", "tbody", "td", "tfoot", "th",
                   5615:    "thead", "tr"</dt>
                   5616:    <!--<dt>An end tag whose tag name is one of: "area", "base",
                   5617:    "basefont", "bgsound", "command", "embed", "hr", "iframe", "image",
                   5618:    "img", "input", "isindex", "keygen", "link", "meta", "noembed",
                   5619:    "noframes", "param", "script", "select", "source", "spacer",
                   5620:    "style", "table", "textarea", "title", "wbr"</dt>-->
                   5621:    <!--<dt>An end tag whose tag name is "noscript", if the
                   5622:    <span>scripting flag</span> is enabled</dt>-->
                   5623:    <dd>
                   5624:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5625:     <!-- end tags are commented out because since they can never end
                   5626:     up on the stack anyway, the default end tag clause will
                   5627:     automatically handle them. we don't want to have text in the spec
                   5628:     that is just an optimisation, as that detracts from the spec
                   5629:     itself -->
                   5630:    </dd>
                   5631: 
                   5632:    <dt>Any other start tag</dt>
                   5633:    <dd>
                   5634: 
                   5635:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5636:     any.</p>
                   5637: 
                   5638:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5639: 
                   5640:     <p class="note">This element will be a <a href="#phrasing">phrasing</a>
                   5641:     element.</p>
                   5642: 
                   5643:    </dd>
                   5644: 
                   5645:    <dt>Any other end tag</dt>
                   5646:    <dd>
                   5647: 
                   5648:     <p>Run the following steps:</p>
                   5649: 
                   5650:     <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   5651:      node</a> (the bottommost node of the stack).</p></li>
                   5652: 
                   5653:      <li><p>If <var title="">node</var> has the same tag name as
                   5654:      the end tag token, then:</p>
                   5655: 
                   5656:       <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   5657: 
                   5658:        <li><p>If the tag name of the end tag token does not match
                   5659:        the tag name of the <a href="#current-node">current node</a>, this is a
                   5660:        <a href="#parse-error">parse error</a>.</p></li>
                   5661: 
                   5662:        <li><p>Pop all the nodes from the <a href="#current-node">current node</a> up
                   5663:        to <var title="">node</var>, including <var title="">node</var>, then stop these steps.</p></li>
                   5664: 
                   5665:       </ol></li>
                   5666: 
                   5667:      <li><p>Otherwise, if <var title="">node</var> is in neither the
                   5668:      <a href="#formatting">formatting</a> category nor the <a href="#phrasing">phrasing</a>
                   5669:      category, then this is a <a href="#parse-error">parse error</a>; ignore the
                   5670:      token, and abort these steps.</p></li>
                   5671: 
                   5672:      <li><p>Set <var title="">node</var> to the previous entry in the
                   5673:      <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
                   5674: 
                   5675:      <li><p>Return to step 2.</p></li>
                   5676: 
                   5677:     </ol></dd>
                   5678: 
1.91      mike     5679:   </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     5680: 
                   5681:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incdata" title="insertion
1.91      mike     5682:   mode: in RAWTEXT/RCDATA">in RAWTEXT/RCDATA</a>", tokens must be
1.1       mike     5683:   handled as follows:</p>
                   5684: 
                   5685:   <dl class="switch"><dt>A character token</dt>
                   5686:    <dd>
                   5687: 
                   5688:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   5689:     character</a> into the <a href="#current-node">current node</a>.</p>
                   5690: 
                   5691:    </dd>
                   5692: 
                   5693:    <dt>An end-of-file token</dt>
                   5694:    <dd>
                   5695: 
                   5696:     <!-- can't be the fragment case -->
                   5697:     <p><a href="#parse-error">Parse error</a>.</p>
                   5698: 
                   5699:     <p>If the <a href="#current-node">current node</a> is a <code><a href="semantics.html#script">script</a></code>
                   5700:     element, mark the <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-executed">"already
                   5701:     executed"</a>.</p>
                   5702: 
                   5703:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5704:     elements</a>.</p>
                   5705: 
                   5706:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5707:     insertion mode</a> and reprocess the current token.</p>
                   5708: 
                   5709:    </dd>
                   5710: 
                   5711:    <dt>An end tag whose tag name is "script"</dt>
                   5712:    <dd>
                   5713: 
                   5714:     <p>Let <var title="">script</var> be the <a href="#current-node">current node</a>
                   5715:     (which will be a <code><a href="semantics.html#script">script</a></code> element).</p>
                   5716: 
                   5717:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5718:     elements</a>.</p>
                   5719: 
                   5720:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5721:     insertion mode</a>.</p>
                   5722: 
                   5723:     <p>Let the <var title="">old insertion point</var> have the
                   5724:     same value as the current <a href="#insertion-point">insertion point</a>. Let
                   5725:     the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
                   5726:     input character</a>.</p>
                   5727: 
                   5728:     <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
                   5729:     one.</p>
                   5730: 
                   5731:     <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     5732:     which might cause <a href="embedded-content-0.html#dom-document-write" title="dom-document-write">new characters
1.1       mike     5733:     to be inserted into the tokenizer</a>, and might cause the
                   5734:     tokenizer to output more tokens, resulting in a <a href="#nestedParsing">reentrant invocation of the parser</a>.</p>
                   5735: 
                   5736:     <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
                   5737:     one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
                   5738:     then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
                   5739: 
                   5740:     <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
                   5741:     <a href="#insertion-point">insertion point</a> to its previous value. This value
                   5742:     might be the "undefined" value.)</p>
                   5743: 
                   5744:     <p id="scriptTagParserResumes">At this stage, if there is a
                   5745:     <a href="semantics.html#pending-external-script">pending external script</a>, then:</p>
                   5746: 
                   5747:     <dl class="switch"><dt>If the <a href="#script-nesting-level">script nesting level</a> is not zero:</dt>
                   5748: 
                   5749:      <dd>
                   5750: 
                   5751:       <p>Set the <a href="#parser-pause-flag">parser pause flag</a> to true, and abort the
                   5752:       processing of any nested invocations of the tokenizer, yielding
                   5753:       control back to the caller. (Tokenization will resume when the
                   5754:       caller returns to the "outer" tree construction stage.)</p>
                   5755: 
                   5756:       <p class="note">The tree construction stage of this particular
                   5757:       parser is <a href="#nestedParsing">being called reentrantly</a>,
1.159     mike     5758:       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     5759: 
                   5760:      </dd>
                   5761: 
                   5762: 
                   5763:      <dt>Otherwise:</dt>
                   5764: 
                   5765:      <dd>
                   5766: 
                   5767:       <p>Follow these steps:</p>
                   5768: 
                   5769:       <ol><li><p>Let <var title="">the script</var> be the <a href="semantics.html#pending-external-script">pending
                   5770:        external script</a>. There is no longer a <a href="semantics.html#pending-external-script">pending
                   5771:        external script</a>.</p></li>
                   5772: 
                   5773:        <li><p><a href="browsers.html#pause">Pause</a> until the script has <a href="semantics.html#completed-loading">completed
                   5774:        loading</a>.</p></li>
                   5775: 
                   5776:        <li><p>Let the <a href="#insertion-point">insertion point</a> be just before the
                   5777:        <a href="#next-input-character">next input character</a>.</p></li>
                   5778: 
                   5779:        <li><p>Increment the parser's <a href="#script-nesting-level">script nesting level</a>
                   5780:        by one (it should be zero before this step, so this sets it to
                   5781:        one).</p></li>
                   5782: 
                   5783:        <li><p><a href="semantics.html#executing-a-script-block" title="executing a script block">Execute the
                   5784:        script</a>.</p></li>
                   5785: 
                   5786:        <li><p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a>
                   5787:        by one. If the parser's <a href="#script-nesting-level">script nesting level</a> is
                   5788:        zero (which it always should be at this point), then set the
                   5789:        <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
                   5790: 
                   5791:        </li><li><p>Let the <a href="#insertion-point">insertion point</a> be undefined
                   5792:        again.</p></li>
                   5793: 
                   5794:        <li><p>If there is once again a <a href="semantics.html#pending-external-script">pending external
                   5795:        script</a>, then repeat these steps from step 1.</p></li>
                   5796: 
                   5797:       </ol></dd>
                   5798: 
                   5799:     </dl></dd>
                   5800: 
                   5801:    <dt>Any other end tag</dt>
                   5802:    <dd>
                   5803: 
                   5804:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5805:     elements</a>.</p>
                   5806: 
                   5807:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5808:     insertion mode</a>.</p>
                   5809: 
                   5810:    </dd>
                   5811: 
                   5812:   </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>
                   5813: 
                   5814:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion
                   5815:   mode: in table">in table</a>", tokens must be handled as follows:</p>
                   5816: 
                   5817:   <dl class="switch"><dt>A character token</dt>
                   5818:    <dd>
                   5819: 
                   5820:      <p>Let the <dfn id="pending-table-character-tokens"><var>pending table character tokens</var></dfn>
                   5821:      be an empty list of tokens.</p>
                   5822: 
                   5823:      <p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
                   5824:      <a href="#insertion-mode">insertion mode</a>.</p>
                   5825: 
                   5826:      <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
                   5827:      reprocess the token.</p>
                   5828: 
                   5829:    </dd>
                   5830: 
                   5831:    <dt>A comment token</dt>
                   5832:    <dd>
                   5833:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   5834:     node</a> with the <code title="">data</code> attribute set to
                   5835:     the data given in the comment token.</p>
                   5836:    </dd>
                   5837: 
                   5838:    <dt>A DOCTYPE token</dt>
                   5839:    <dd>
                   5840:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5841:    </dd>
                   5842: 
                   5843:    <dt>A start tag whose tag name is "caption"</dt>
                   5844:    <dd>
                   5845: 
                   5846:     <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
                   5847:     below.)</p>
                   5848: 
                   5849:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   5850:     formatting elements</a>.</p>
                   5851: 
                   5852:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
                   5853:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>".</p>
                   5854: 
                   5855:    </dd>
                   5856: 
                   5857:    <dt>A start tag whose tag name is "colgroup"</dt>
                   5858:    <dd>
                   5859: 
                   5860:     <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
                   5861:     below.)</p>
                   5862: 
                   5863:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
                   5864:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column
                   5865:     group</a>".</p>
                   5866: 
                   5867:    </dd>
                   5868: 
                   5869:    <dt>A start tag whose tag name is "col"</dt>
                   5870:    <dd>
                   5871:     <p>Act as if a start tag token with the tag name "colgroup"
                   5872:     had been seen, then reprocess the current token.</p>
                   5873:    </dd>
                   5874: 
                   5875:    <dt>A start tag whose tag name is one of: "tbody", "tfoot", "thead"</dt>
                   5876:    <dd>
                   5877: 
                   5878:     <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
                   5879:     below.)</p>
                   5880: 
                   5881:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
                   5882:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   5883:     body</a>".</p>
                   5884: 
                   5885:    </dd>
                   5886: 
                   5887:    <dt>A start tag whose tag name is one of: "td", "th", "tr"</dt>
                   5888:    <dd>
                   5889:     <p>Act as if a start tag token with the tag name "tbody" had
                   5890:     been seen, then reprocess the current token.</p>
                   5891:    </dd>
                   5892: 
                   5893:    <dt>A start tag whose tag name is "table"</dt>
                   5894:    <dd>
                   5895: 
                   5896:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag token with
                   5897:     the tag name "table" had been seen, then, if that token wasn't
                   5898:     ignored, reprocess the current token.</p>
                   5899: 
                   5900:     <p class="note">The fake end tag token here can only be
                   5901:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   5902: 
                   5903:    </dd>
                   5904: 
                   5905:    <dt>An end tag whose tag name is "table"</dt>
                   5906:    <dd>
                   5907: 
                   5908:     <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
                   5909:     scope</a> with the same tag name as the token, this is a
                   5910:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   5911:     case</a>)</p>
                   5912: 
                   5913:     <p>Otherwise:</p>
                   5914: 
                   5915:     <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-table-element">table</a></code>
                   5916:     element has been popped from the stack.</p>
                   5917: 
                   5918:     <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
                   5919: 
                   5920:    </dd>
                   5921: 
                   5922:    <dt>An end tag whose tag name is one of: "body", "caption",
                   5923:    "col", "colgroup", "html", "tbody", "td", "tfoot", "th",
                   5924:    "thead", "tr"</dt>
                   5925:    <dd>
                   5926:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5927:    </dd>
                   5928: 
                   5929:    <dt>A start tag whose tag name is one of: "style", "script"</dt>
                   5930:    <dd>
                   5931: 
                   5932:     <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
                   5933:     mode</a>.</p>
                   5934: 
                   5935:    </dd>
                   5936: 
                   5937:    <dt>A start tag whose tag name is "input"</dt>
                   5938:    <dd>
                   5939: 
                   5940:     <p>If the token does not have an attribute with the name "type",
                   5941:     or if it does, but that attribute's value is not an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   5942:     case-insensitive</a> match for the string "<code title="">hidden</code>", then: act as described in the "anything
                   5943:     else" entry below.</p>
                   5944: 
                   5945:     <p>Otherwise:</p>
                   5946: 
                   5947:     <p><a href="#parse-error">Parse error</a>.</p>
                   5948: 
                   5949:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5950: 
                   5951:     <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
                   5952:     open elements</a>.</p>
                   5953: 
                   5954:    </dd>
                   5955: 
                   5956:    <dt>An end-of-file token</dt>
                   5957:    <dd>
                   5958: 
                   5959:     <p>If the <a href="#current-node">current node</a> is not the root
1.159     mike     5960:     <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     5961:     error</a>.</p>
                   5962: 
                   5963:     <p class="note">It can only be the <a href="#current-node">current node</a> in
                   5964:     the <a href="#fragment-case">fragment case</a>.</p>
                   5965: 
                   5966:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   5967: 
                   5968:    </dd>
                   5969: 
                   5970:    <dt>Anything else</dt>
                   5971:    <dd>
                   5972: 
                   5973:     <p><a href="#parse-error">Parse error</a>. Process the token <a href="#using-the-rules-for">using the
                   5974:     rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   5975:     body</a>" <a href="#insertion-mode">insertion mode</a>, except that if the
                   5976:     <a href="#current-node">current node</a> is a <code><a href="tabular-data.html#the-table-element">table</a></code>,
                   5977:     <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
                   5978:     <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then, whenever a node would be inserted
                   5979:     into the <a href="#current-node">current node</a>, it must instead be <a href="#foster-parent" title="foster parent">foster parented</a>.</p>
                   5980: 
                   5981:    </dd>
                   5982: 
                   5983:   </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-context">clear the stack
                   5984:   back to a table context</dfn>, it means that the UA must, while
                   5985:   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     5986:   element or an <code><a href="semantics.html#the-html-element-0">html</a></code> element, pop elements from the
1.1       mike     5987:   <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   5988: 
                   5989:   <p class="note">The <a href="#current-node">current node</a> being an
1.159     mike     5990:   <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     5991:   case</a>.</p>
                   5992: 
                   5993: 
                   5994: 
                   5995:   <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>
                   5996: 
                   5997:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intabletext" title="insertion
                   5998:   mode: in table text">in table text</a>", tokens must be handled
                   5999:   as follows:</p>
                   6000: 
                   6001:   <dl class="switch"><dt>A character token</dt>
                   6002:    <dd>
                   6003: 
                   6004:     <p>Append the character token to the <var><a href="#pending-table-character-tokens">pending table character
                   6005:     tokens</a></var> list.</p>
                   6006: 
                   6007:    </dd>
                   6008: 
                   6009: 
                   6010:    <dt>Anything else</dt>
                   6011:    <dd>
                   6012: 
                   6013:     <p>If any of the tokens in the <var><a href="#pending-table-character-tokens">pending table character
                   6014:     tokens</a></var> list are character tokens that are not one of U+0009
                   6015:     CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED
                   6016:     (FF), <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE, then
                   6017:     reprocess those character tokens using the rules given in the
                   6018:     "anything else" entry in the <a href="#parsing-main-intable" title="insertion mode: in
                   6019:     table">in table</a>" insertion mode.</p>
                   6020: 
                   6021:     <p>Otherwise, <a href="#insert-a-character" title="insert a character">insert the
                   6022:     characters</a> given by the <var><a href="#pending-table-character-tokens">pending table character
                   6023:     tokens</a></var> list into the <a href="#current-node">current node</a>.</p>
                   6024: 
                   6025:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   6026:     insertion mode</a> and reprocess the token.</p>
                   6027: 
                   6028:    </dd>
                   6029: 
                   6030:   </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>
                   6031: 
                   6032:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incaption" title="insertion
                   6033:   mode: in caption">in caption</a>", tokens must be handled as follows:</p>
                   6034: 
                   6035:   <dl class="switch"><dt>An end tag whose tag name is "caption"</dt>
                   6036:    <dd>
                   6037: 
                   6038:     <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
                   6039:     scope</a> with the same tag name as the token, this is a
                   6040:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   6041:     case</a>)</p>
                   6042: 
                   6043:     <p>Otherwise:</p>
                   6044: 
                   6045:     <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
                   6046: 
                   6047:     <p>Now, if the <a href="#current-node">current node</a> is not a
                   6048:     <code><a href="tabular-data.html#the-caption-element">caption</a></code> element, then this is a <a href="#parse-error">parse
                   6049:     error</a>.</p>
                   6050: 
                   6051:     <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-caption-element">caption</a></code>
                   6052:     element has been popped from the stack.</p>
                   6053: 
                   6054:     <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
                   6055:     the last marker</a>.</p>
                   6056: 
                   6057:     <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>
                   6058: 
                   6059:    </dd>
                   6060: 
                   6061:    <dt>A start tag whose tag name is one of: "caption", "col",
                   6062:    "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
                   6063:    <dt>An end tag whose tag name is "table"</dt>
                   6064:    <dd>
                   6065: 
                   6066:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
                   6067:     name "caption" had been seen, then, if that token wasn't
                   6068:     ignored, reprocess the current token.</p>
                   6069: 
                   6070:     <p class="note">The fake end tag token here can only be
                   6071:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   6072: 
                   6073:    </dd>
                   6074: 
                   6075:    <dt>An end tag whose tag name is one of: "body", "col",
                   6076:    "colgroup", "html", "tbody", "td", "tfoot", "th", "thead",
                   6077:    "tr"</dt>
                   6078:    <dd>
                   6079:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6080:    </dd>
                   6081: 
                   6082:    <dt>Anything else</dt>
                   6083:    <dd>
                   6084:     <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
                   6085:     mode</a>.</p>
                   6086:    </dd>
                   6087: 
                   6088:   </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>
                   6089: 
                   6090:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incolgroup" title="insertion
                   6091:   mode: in column group">in column group</a>", tokens must be handled as follows:</p>
                   6092: 
                   6093:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   6094:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6095:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6096:    <dd>
                   6097:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   6098:     the <a href="#current-node">current node</a>.</p>
                   6099:    </dd>
                   6100: 
                   6101:    <dt>A comment token</dt>
                   6102:    <dd>
                   6103:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6104:     node</a> with the <code title="">data</code> attribute set to
                   6105:     the data given in the comment token.</p>
                   6106:    </dd>
                   6107: 
                   6108:    <dt>A DOCTYPE token</dt>
                   6109:    <dd>
                   6110:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6111:    </dd>
                   6112: 
                   6113:    <dt>A start tag whose tag name is "html"</dt>
                   6114:    <dd>
                   6115:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
                   6116:     mode</a>.</p>
                   6117:    </dd>
                   6118: 
                   6119:    <dt>A start tag whose tag name is "col"</dt>
                   6120:    <dd>
                   6121: 
                   6122:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   6123:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   6124:     elements</a>.</p>
                   6125: 
                   6126:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   6127:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   6128: 
                   6129:    </dd>
                   6130: 
                   6131:    <dt>An end tag whose tag name is "colgroup"</dt>
                   6132:    <dd>
                   6133: 
                   6134:     <p>If the <a href="#current-node">current node</a> is the root
1.159     mike     6135:     <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     6136:     error</a>; ignore the token. (<a href="#fragment-case">fragment
                   6137:     case</a>)</p>
                   6138: 
                   6139:     <p>Otherwise, pop the <a href="#current-node">current node</a> (which will be
                   6140:     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
                   6141:     elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
                   6142:     "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
                   6143: 
                   6144:    </dd>
                   6145: 
                   6146:    <dt>An end tag whose tag name is "col"</dt>
                   6147:    <dd>
                   6148:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6149:    </dd>
                   6150: 
                   6151:    <dt>An end-of-file token</dt>
                   6152:    <dd>
                   6153: 
1.159     mike     6154:     <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     6155:     element, then <a href="#stop-parsing">stop parsing</a>. (<a href="#fragment-case">fragment
                   6156:     case</a>)</p>
                   6157: 
                   6158:     <p>Otherwise, act as described in the "anything else" entry
                   6159:     below.</p>
                   6160: 
                   6161:    </dd>
                   6162: 
                   6163:    <dt>Anything else</dt>
                   6164:    <dd>
                   6165: 
                   6166:     <p>Act as if an end tag with the tag name "colgroup" had been
                   6167:     seen, and then, if that token wasn't ignored, reprocess the
                   6168:     current token.</p>
                   6169: 
                   6170:     <p class="note">The fake end tag token here can only be
                   6171:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   6172: 
                   6173:    </dd>
                   6174: 
                   6175:   </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>
                   6176: 
                   6177:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion
                   6178:   mode: in table body">in table body</a>", tokens must be handled as follows:</p>
                   6179: 
                   6180:   <dl class="switch"><dt>A start tag whose tag name is "tr"</dt>
                   6181:    <dd>
                   6182: 
                   6183:     <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
                   6184:     context</a>. (See below.)</p>
                   6185: 
                   6186:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
                   6187:     the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion mode:
                   6188:     in row">in row</a>".</p>
                   6189: 
                   6190:    </dd>
                   6191: 
                   6192:    <dt>A start tag whose tag name is one of: "th", "td"</dt>
                   6193:    <dd>
                   6194:     <p><a href="#parse-error">Parse error</a>. Act as if a start tag with
                   6195:     the tag name "tr" had been seen, then reprocess the current
                   6196:     token.</p>
                   6197:    </dd>
                   6198: 
                   6199:    <dt>An end tag whose tag name is one of: "tbody", "tfoot",
                   6200:    "thead"</dt>
                   6201:    <dd>
                   6202: 
                   6203:     <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
                   6204:     scope</a> with the same tag name as the token, this is a
                   6205:     <a href="#parse-error">parse error</a>. Ignore the token.</p>
                   6206: 
                   6207:     <p>Otherwise:</p>
                   6208: 
                   6209:     <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
                   6210:     context</a>. (See below.)</p>
                   6211: 
                   6212:     <p>Pop the <a href="#current-node">current node</a> from the <a href="#stack-of-open-elements">stack of
                   6213:     open elements</a>. Switch the <a href="#insertion-mode">insertion mode</a>
                   6214:     to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
                   6215: 
                   6216:    </dd>
                   6217: 
                   6218:    <dt>A start tag whose tag name is one of: "caption", "col",
                   6219:    "colgroup", "tbody", "tfoot", "thead"</dt>
                   6220:    <dt>An end tag whose tag name is "table"</dt>
                   6221:    <dd>
                   6222: 
                   6223:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-table-scope" title="has an element in table scope">have a
                   6224:     <code>tbody</code>, <code>thead</code>, or <code>tfoot</code>
                   6225:     element in table scope</a>, this is a <a href="#parse-error">parse
                   6226:     error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   6227:     case</a>)</p>
                   6228: 
                   6229:     <p>Otherwise:</p>
                   6230: 
                   6231:     <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
                   6232:     context</a>. (See below.)</p>
                   6233: 
                   6234:     <p>Act as if an end tag with the same tag name as the
                   6235:     <a href="#current-node">current node</a> ("tbody", "tfoot", or "thead") had
                   6236:     been seen, then reprocess the current token.</p>
                   6237: 
                   6238:    </dd>
                   6239: 
                   6240:    <dt>An end tag whose tag name is one of: "body", "caption",
                   6241:    "col", "colgroup", "html", "td", "th", "tr"</dt>
                   6242:    <dd>
                   6243:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6244:    </dd>
                   6245: 
                   6246:    <dt>Anything else</dt>
                   6247:    <dd>
                   6248:     <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
                   6249:     mode</a>.</p>
                   6250:    </dd>
                   6251: 
                   6252:   </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-body-context">clear the stack
                   6253:   back to a table body context</dfn>, it means that the UA must,
                   6254:   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     6255:   <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     6256:   element, pop elements from the <a href="#stack-of-open-elements">stack of open
                   6257:   elements</a>.</p>
                   6258: 
                   6259:   <p class="note">The <a href="#current-node">current node</a> being an
1.159     mike     6260:   <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     6261:   case</a>.</p>
                   6262: 
                   6263: 
                   6264:   <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>
                   6265: 
                   6266:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
                   6267:   mode: in row">in row</a>", tokens must be handled as follows:</p>
                   6268: 
                   6269:   <dl class="switch"><dt>A start tag whose tag name is one of: "th", "td"</dt>
                   6270:    <dd>
                   6271: 
                   6272:     <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
                   6273:     context</a>. (See below.)</p>
                   6274: 
                   6275:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
                   6276:     the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion mode:
                   6277:     in cell">in cell</a>".</p>
                   6278: 
                   6279:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   6280:     formatting elements</a>.</p>
                   6281: 
                   6282:    </dd>
                   6283: 
                   6284:    <dt>An end tag whose tag name is "tr"</dt>
                   6285:    <dd>
                   6286: 
                   6287:     <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
                   6288:     scope</a> with the same tag name as the token, this is a
                   6289:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   6290:     case</a>)</p>
                   6291: 
                   6292:     <p>Otherwise:</p>
                   6293: 
                   6294:     <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
                   6295:     context</a>. (See below.)</p>
                   6296: 
                   6297:     <p>Pop the <a href="#current-node">current node</a> (which will be a
                   6298:     <code><a href="tabular-data.html#the-tr-element">tr</a></code> element) from the <a href="#stack-of-open-elements">stack of open
                   6299:     elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
                   6300:     "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   6301:     body</a>".</p>
                   6302: 
                   6303:    </dd>
                   6304: 
                   6305:    <dt>A start tag whose tag name is one of: "caption", "col",
                   6306:    "colgroup", "tbody", "tfoot", "thead", "tr"</dt>
                   6307:    <dt>An end tag whose tag name is "table"</dt>
                   6308:    <dd>
                   6309: 
                   6310:     <p>Act as if an end tag with the tag name "tr" had been seen,
                   6311:     then, if that token wasn't ignored, reprocess the current
                   6312:     token.</p>
                   6313: 
                   6314:     <p class="note">The fake end tag token here can only be
                   6315:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   6316: 
                   6317:    </dd>
                   6318: 
                   6319:    <dt>An end tag whose tag name is one of: "tbody", "tfoot",
                   6320:    "thead"</dt>
                   6321:    <dd>
                   6322: 
                   6323:     <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
                   6324:     scope</a> with the same tag name as the token, this is a
                   6325:     <a href="#parse-error">parse error</a>. Ignore the token.</p>
                   6326: 
                   6327:     <p>Otherwise, act as if an end tag with the tag name "tr" had
                   6328:     been seen, then reprocess the current token.</p>
                   6329: 
                   6330:    </dd>
                   6331: 
                   6332:    <dt>An end tag whose tag name is one of: "body", "caption",
                   6333:    "col", "colgroup", "html", "td", "th"</dt>
                   6334:    <dd>
                   6335:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6336:    </dd>
                   6337: 
                   6338:    <dt>Anything else</dt>
                   6339:    <dd>
                   6340:     <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
                   6341:     mode</a>.</p>
                   6342:    </dd>
                   6343: 
                   6344:   </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-row-context">clear the stack
                   6345:   back to a table row context</dfn>, it means that the UA must,
                   6346:   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     6347:   element or an <code><a href="semantics.html#the-html-element-0">html</a></code> element, pop elements from the
1.1       mike     6348:   <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   6349: 
                   6350:   <p class="note">The <a href="#current-node">current node</a> being an
1.159     mike     6351:   <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     6352:   case</a>.</p>
                   6353: 
                   6354: 
                   6355:   <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>
                   6356: 
                   6357:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intd" title="insertion
                   6358:   mode: in cell">in cell</a>", tokens must be handled as follows:</p>
                   6359: 
                   6360:   <dl class="switch"><dt>An end tag whose tag name is one of: "td", "th"</dt>
                   6361:    <dd>
                   6362: 
                   6363:     <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
                   6364:     scope</a> with the same tag name as that of the token, then
                   6365:     this is a <a href="#parse-error">parse error</a> and the token must be
                   6366:     ignored.</p>
                   6367: 
                   6368:     <p>Otherwise:</p>
                   6369: 
                   6370:     <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
                   6371: 
                   6372:     <p>Now, if the <a href="#current-node">current node</a> is not an element
                   6373:     with the same tag name as the token, then this is a
                   6374:     <a href="#parse-error">parse error</a>.</p>
                   6375: 
                   6376:     <p>Pop elements from this stack until an element with the same
                   6377:     tag name as the token has been popped from the stack.</p>
                   6378: 
                   6379:     <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
                   6380:     the last marker</a>.</p>
                   6381: 
                   6382:     <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
                   6383:     <a href="#current-node">current node</a> will be a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element at
                   6384:     this point.)</p>
                   6385: 
                   6386:    </dd>
                   6387: 
                   6388:    <dt>A start tag whose tag name is one of: "caption", "col",
                   6389:    "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
                   6390:    <dd>
                   6391: 
                   6392:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does
                   6393:     <em>not</em> <a href="#has-an-element-in-table-scope" title="has an element in table scope">have
                   6394:     a <code>td</code> or <code>th</code> element in table
                   6395:     scope</a>, then this is a <a href="#parse-error">parse error</a>; ignore
                   6396:     the token. (<a href="#fragment-case">fragment case</a>)</p>
                   6397: 
                   6398:     <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
                   6399:     reprocess the current token.</p>
                   6400: 
                   6401:    </dd>
                   6402: 
                   6403:    <dt>An end tag whose tag name is one of: "body", "caption",
                   6404:    "col", "colgroup", "html"</dt>
                   6405:    <dd>
                   6406:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6407:    </dd>
                   6408: 
                   6409:    <dt>An end tag whose tag name is one of: "table", "tbody",
                   6410:    "tfoot", "thead", "tr"</dt>
                   6411:    <dd>
                   6412: 
                   6413:     <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
                   6414:     scope</a> with the same tag name as that of the token
                   6415:     (which can only happen for "tbody", "tfoot" and "thead", or,
                   6416:     in the <a href="#fragment-case">fragment case</a>), then this is a <a href="#parse-error">parse
                   6417:     error</a> and the token must be ignored.</p>
                   6418: 
                   6419:     <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
                   6420:     reprocess the current token.</p>
                   6421: 
                   6422:    </dd>
                   6423: 
                   6424:    <dt>Anything else</dt>
                   6425:    <dd>
                   6426:     <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
                   6427:     mode</a>.</p>
                   6428:    </dd>
                   6429: 
                   6430:   </dl><p>Where the steps above say to <dfn id="close-the-cell">close the cell</dfn>, they
                   6431:   mean to run the following algorithm:</p>
                   6432: 
                   6433:   <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>
                   6434:    element in table scope</a>, then act as if an end tag token
                   6435:    with the tag name "td" had been seen.</p></li>
                   6436: 
                   6437:    <li><p>Otherwise, the <a href="#stack-of-open-elements">stack of open elements</a> will
                   6438:    <a href="#has-an-element-in-table-scope" title="has an element in table scope">have a
                   6439:    <code>th</code> element in table scope</a>; act as if an end
                   6440:    tag token with the tag name "th" had been seen.</p></li>
                   6441: 
                   6442:   </ol><p class="note">The <a href="#stack-of-open-elements">stack of open elements</a> cannot
                   6443:   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
                   6444:   the same time, nor can it have neither when the <a href="#insertion-mode">insertion
                   6445:   mode</a> is "<a href="#parsing-main-intd" title="insertion mode: in cell">in
                   6446:   cell</a>".</p>
                   6447: 
                   6448: 
                   6449:   <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>
                   6450: 
                   6451:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselect" title="insertion
                   6452:   mode: in select">in select</a>", tokens must be handled as follows:</p>
                   6453: 
                   6454:   <dl class="switch"><dt>A character token</dt>
                   6455:    <dd>
                   6456:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   6457:     character</a> into the <a href="#current-node">current node</a>.</p>
                   6458:    </dd>
                   6459: 
                   6460:    <dt>A comment token</dt>
                   6461:    <dd>
                   6462:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6463:     node</a> with the <code title="">data</code> attribute set to
                   6464:     the data given in the comment token.</p>
                   6465:    </dd>
                   6466: 
                   6467:    <dt>A DOCTYPE token</dt>
                   6468:    <dd>
                   6469:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6470:    </dd>
                   6471: 
                   6472:    <dt>A start tag whose tag name is "html"</dt>
                   6473:    <dd>
                   6474:     <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
                   6475:     mode</a>.</p>
                   6476:    </dd>
                   6477: 
                   6478:    <dt>A start tag whose tag name is "option"</dt>
                   6479:    <dd>
                   6480: 
                   6481:     <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
                   6482:     element, act as if an end tag with the tag name "option" had
                   6483:     been seen.</p>
                   6484: 
                   6485:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   6486: 
                   6487:    </dd>
                   6488: 
                   6489:    <dt>A start tag whose tag name is "optgroup"</dt>
                   6490:    <dd>
                   6491: 
                   6492:     <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
                   6493:     element, act as if an end tag with the tag name "option" had
                   6494:     been seen.</p>
                   6495: 
                   6496:     <p>If the <a href="#current-node">current node</a> is an
                   6497:     <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, act as if an end tag with the
                   6498:     tag name "optgroup" had been seen.</p>
                   6499: 
                   6500:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   6501: 
                   6502:    </dd>
                   6503: 
                   6504:    <dt>An end tag whose tag name is "optgroup"</dt>
                   6505:    <dd>
                   6506: 
                   6507:     <p>First, if the <a href="#current-node">current node</a> is an
                   6508:     <code><a href="forms.html#the-option-element">option</a></code> element, and the node immediately before
                   6509:     it in the <a href="#stack-of-open-elements">stack of open elements</a> is an
                   6510:     <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then act as if an end tag with
                   6511:     the tag name "option" had been seen.</p>
                   6512: 
                   6513:     <p>If the <a href="#current-node">current node</a> is an
                   6514:     <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then pop that node from the
                   6515:     <a href="#stack-of-open-elements">stack of open elements</a>. Otherwise, this is a
                   6516:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   6517: 
                   6518:    </dd>
                   6519: 
                   6520:    <dt>An end tag whose tag name is "option"</dt>
                   6521:    <dd>
                   6522: 
                   6523:     <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
                   6524:     element, then pop that node from the <a href="#stack-of-open-elements">stack of open
                   6525:     elements</a>. Otherwise, this is a <a href="#parse-error">parse
                   6526:     error</a>; ignore the token.</p>
                   6527: 
                   6528:    </dd>
                   6529: 
                   6530:    <dt>An end tag whose tag name is "select"</dt>
                   6531:    <dd>
                   6532: 
                   6533:     <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
                   6534:     scope</a> with the same tag name as the token, this is a
                   6535:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   6536:     case</a>)</p>
                   6537: 
                   6538:     <p>Otherwise:</p>
                   6539: 
                   6540:     <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   6541:     until a <code><a href="forms.html#the-select-element">select</a></code> element has been popped from the
                   6542:     stack.</p>
                   6543: 
                   6544:     <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
                   6545: 
                   6546:    </dd>
                   6547: 
                   6548:    <dt>A start tag whose tag name is "select"</dt>
                   6549:    <dd>
                   6550: 
                   6551:     <p><a href="#parse-error">Parse error</a>. Act as if the token had been
                   6552:     an end tag with the tag name "select" instead.</p>
                   6553: 
                   6554:    </dd>
                   6555: 
                   6556:    <dt>A start tag whose tag name is one of: "input", "keygen", "textarea"</dt>
                   6557:    <dd>
1.73      mike     6558: 
                   6559:     <p><a href="#parse-error">Parse error</a>.</p>
                   6560: 
1.124     mike     6561:     <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>
                   6562:     element in table scope</a>, ignore the token. (<a href="#fragment-case">fragment
                   6563:     case</a>)</p>
1.73      mike     6564: 
                   6565:     <p>Otherwise, act as if an end tag with the tag name "select" had
                   6566:     been seen, and reprocess the token.</p>
                   6567: 
1.1       mike     6568:    </dd>
                   6569: 
                   6570:    <dt>A start tag token whose tag name is "script"</dt>
                   6571:    <dd>
                   6572:     <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
                   6573:     mode</a>.</p>
                   6574:    </dd>
                   6575: 
                   6576:    <dt>An end-of-file token</dt>
                   6577:    <dd>
                   6578: 
                   6579:     <p>If the <a href="#current-node">current node</a> is not the root
1.159     mike     6580:     <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     6581:     error</a>.</p>
                   6582: 
                   6583:     <p class="note">It can only be the <a href="#current-node">current node</a> in
                   6584:     the <a href="#fragment-case">fragment case</a>.</p>
                   6585: 
                   6586:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6587: 
                   6588:    </dd>
                   6589: 
                   6590:    <dt>Anything else</dt>
                   6591:    <dd>
                   6592:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6593:    </dd>
                   6594: 
                   6595:   </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>
                   6596: 
                   6597:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselectintable" title="insertion
                   6598:   mode: in select in table">in select in table</a>", tokens must be handled as follows:</p>
                   6599: 
                   6600:   <dl class="switch"><dt>A start tag whose tag name is one of: "caption", "table",
                   6601:    "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
                   6602:    <dd>
                   6603:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
                   6604:     name "select" had been seen, and reprocess the token.</p>
                   6605:    </dd>
                   6606: 
                   6607:    <dt>An end tag whose tag name is one of: "caption", "table",
                   6608:    "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
                   6609:    <dd>
                   6610: 
                   6611:     <p><a href="#parse-error">Parse error</a>.</p>
                   6612: 
                   6613:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-table-scope">has an
                   6614:     element in table scope</a> with the same tag name as that
                   6615:     of the token, then act as if an end tag with the tag name
                   6616:     "select" had been seen, and reprocess the token. Otherwise,
                   6617:     ignore the token.</p>
                   6618: 
                   6619:    </dd>
                   6620: 
                   6621:    <dt>Anything else</dt>
                   6622:    <dd>
                   6623:     <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
                   6624:     mode</a>.</p>
                   6625:    </dd>
                   6626: 
1.168     mike     6627:   </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     6628: 
                   6629:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inforeign" title="insertion
                   6630:   mode: in foreign content">in foreign content</a>", tokens must be
                   6631:   handled as follows:</p>
                   6632: 
                   6633:   <dl class="switch"><dt>A character token</dt>
                   6634:    <dd>
                   6635: 
                   6636:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   6637:     character</a> into the <a href="#current-node">current node</a>.</p>
                   6638: 
                   6639:     <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
                   6640:     LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
                   6641:     (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
                   6642:     flag</a> to "not ok".</p>
                   6643: 
                   6644:    </dd>
                   6645: 
                   6646:    <dt>A comment token</dt>
                   6647:    <dd>
                   6648:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6649:     node</a> with the <code title="">data</code> attribute set to
                   6650:     the data given in the comment token.</p>
                   6651:    </dd>
                   6652: 
                   6653:    <dt>A DOCTYPE token</dt>
                   6654:    <dd>
                   6655:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6656:    </dd>
                   6657: 
                   6658:    <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>
                   6659:    <dd>
                   6660: 
                   6661:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   6662:     elements</a>.</p>
                   6663: 
                   6664:     <p>Let the <var title="">old insertion point</var> have the
                   6665:     same value as the current <a href="#insertion-point">insertion point</a>. Let
                   6666:     the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
                   6667:     input character</a>.</p>
                   6668: 
                   6669:     <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
                   6670:     one. Set the <a href="#parser-pause-flag">parser pause flag</a> to true.</p>
                   6671: 
                   6672:     <p><a href="http://www.w3.org/TR/SVGMobile12/script.html#ScriptContentProcessing">Process
                   6673:     the <code title="">script</code> element</a> according to the SVG
1.187     mike     6674:     rules, if the user agent supports SVG. <a href="references.html#refsSVG">[SVG]</a></p>
1.1       mike     6675: 
1.159     mike     6676:     <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     6677:     tokenizer</a>, the parser will not be executed reentrantly,
                   6678:     since the <a href="#parser-pause-flag">parser pause flag</a> is true.</p>
                   6679: 
                   6680:     <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
                   6681:     one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
                   6682:     then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
                   6683: 
                   6684:     <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
                   6685:     <a href="#insertion-point">insertion point</a> to its previous value. This value
                   6686:     might be the "undefined" value.)</p>
                   6687: 
                   6688:    </dd>
                   6689: 
                   6690:    <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>
                   6691:    <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>
                   6692:    <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>
                   6693:    <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>
                   6694:    <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>
                   6695:    <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>
                   6696:    <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>
                   6697:    <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>
                   6698:    <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>
                   6699:    <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>
                   6700:    <dt>An end tag</dt>
                   6701:    <dd>
                   6702: 
                   6703:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the
                   6704:     <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
                   6705: 
                   6706:     <p>If, after doing so, the <a href="#insertion-mode">insertion mode</a> is still
                   6707:     "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
1.336     mike     6708:     content</a>", but there is no element <a href="#has-an-element-in-scope" title="has an
                   6709:     element in scope">in scope</a> that has a namespace other than
                   6710:     the <a href="#html-namespace-0">HTML namespace</a>, switch the <a href="#insertion-mode">insertion
1.1       mike     6711:     mode</a> to the <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
                   6712: 
                   6713:    </dd>
                   6714: 
                   6715:    <dt>A start tag whose tag name is one of: <!--"a",--> "b", "big",
                   6716:    "blockquote", "body"<!--by inspection-->, "br", "center", "code",
1.422     mike     6717:    "dd", "div", "dl", "dt"<!-- so that dd and dt can be handled
                   6718:    uniformly throughout the parser -->, "em", "embed", "h1", "h2",
                   6719:    "h3", "h4"<!--for completeness-->, "h5", "h6"<!--for
1.1       mike     6720:    completeness-->, "head"<!--by inspection-->, "hr", "i", "img",
                   6721:    "li", "listing"<!-- so that pre and listing can be handled
                   6722:    uniformly throughout the parser -->, "menu", "meta", "nobr",
                   6723:    "ol"<!-- so that dl, ul, and ol can be handled uniformly throughout
                   6724:    the parser -->, "p", "pre", "ruby", "s", <!--"script",--> "small",
                   6725:    "span", "strong", "strike"<!-- so that s and strike can be handled
                   6726:    uniformly throughout the parser -->, <!--"style",--> "sub", "sup",
1.305     mike     6727:    "table"<!--by inspection-->, "tt", "u", "ul", "var"</dt> <!-- this
                   6728:    list was determined empirically by studying over 6,000,000,000
1.422     mike     6729:    pages that were specifically not XML pages -->
                   6730:    <dt>A start tag whose tag name is "font", if the token has any
                   6731:    attributes named "color", "face", or "size"</dt> <!-- the
                   6732:    attributes here are required so that SVG <font> will go through as
                   6733:    SVG but legacy <font>s won't -->
                   6734:    <dt>An end-of-file token</dt> <dd>
1.1       mike     6735: 
                   6736:     <p><a href="#parse-error">Parse error</a>.</p>
                   6737: 
                   6738:     <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a> until
                   6739:     the <a href="#current-node">current node</a> is in the <a href="#html-namespace-0">HTML
                   6740:     namespace</a>.</p>
                   6741: 
                   6742:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#secondary-insertion-mode">secondary
                   6743:     insertion mode</a>, and reprocess the token.</p>
                   6744: 
                   6745:    </dd>
                   6746: 
                   6747:    <dt>Any other start tag</dt>
                   6748:    <dd>
                   6749: 
                   6750:     <p>If the <a href="#current-node">current node</a> is an element in the
                   6751:     <a href="#mathml-namespace">MathML namespace</a>, <a href="#adjust-mathml-attributes">adjust MathML
                   6752:     attributes</a> for the token. (This fixes the case of MathML
                   6753:     attributes that are not all lowercase.)</p>
                   6754: 
                   6755:     <p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
                   6756:     namespace</a>, and the token's tag name is one of the ones in
                   6757:     the first column of the following table, change the tag name to
                   6758:     the name given in the corresponding cell in the second
                   6759:     column. (This fixes the case of SVG elements that are not all
                   6760:     lowercase.)</p>
                   6761: 
                   6762:     <table><thead><tr><th> Tag name </th><th> Element name
                   6763:      </th></tr></thead><tbody><tr><td> <code title="">altglyph</code> </td><td> <code title="">altGlyph</code>
                   6764:       </td></tr><tr><td> <code title="">altglyphdef</code> </td><td> <code title="">altGlyphDef</code>
                   6765:       </td></tr><tr><td> <code title="">altglyphitem</code> </td><td> <code title="">altGlyphItem</code>
                   6766:       </td></tr><tr><td> <code title="">animatecolor</code> </td><td> <code title="">animateColor</code>
                   6767:       </td></tr><tr><td> <code title="">animatemotion</code> </td><td> <code title="">animateMotion</code>
                   6768:       </td></tr><tr><td> <code title="">animatetransform</code> </td><td> <code title="">animateTransform</code>
                   6769:       </td></tr><tr><td> <code title="">clippath</code> </td><td> <code title="">clipPath</code>
                   6770:       </td></tr><tr><td> <code title="">feblend</code> </td><td> <code title="">feBlend</code>
                   6771:       </td></tr><tr><td> <code title="">fecolormatrix</code> </td><td> <code title="">feColorMatrix</code>
                   6772:       </td></tr><tr><td> <code title="">fecomponenttransfer</code> </td><td> <code title="">feComponentTransfer</code>
                   6773:       </td></tr><tr><td> <code title="">fecomposite</code> </td><td> <code title="">feComposite</code>
                   6774:       </td></tr><tr><td> <code title="">feconvolvematrix</code> </td><td> <code title="">feConvolveMatrix</code>
                   6775:       </td></tr><tr><td> <code title="">fediffuselighting</code> </td><td> <code title="">feDiffuseLighting</code>
                   6776:       </td></tr><tr><td> <code title="">fedisplacementmap</code> </td><td> <code title="">feDisplacementMap</code>
                   6777:       </td></tr><tr><td> <code title="">fedistantlight</code> </td><td> <code title="">feDistantLight</code>
                   6778:       </td></tr><tr><td> <code title="">feflood</code> </td><td> <code title="">feFlood</code>
                   6779:       </td></tr><tr><td> <code title="">fefunca</code> </td><td> <code title="">feFuncA</code>
                   6780:       </td></tr><tr><td> <code title="">fefuncb</code> </td><td> <code title="">feFuncB</code>
                   6781:       </td></tr><tr><td> <code title="">fefuncg</code> </td><td> <code title="">feFuncG</code>
                   6782:       </td></tr><tr><td> <code title="">fefuncr</code> </td><td> <code title="">feFuncR</code>
                   6783:       </td></tr><tr><td> <code title="">fegaussianblur</code> </td><td> <code title="">feGaussianBlur</code>
                   6784:       </td></tr><tr><td> <code title="">feimage</code> </td><td> <code title="">feImage</code>
                   6785:       </td></tr><tr><td> <code title="">femerge</code> </td><td> <code title="">feMerge</code>
                   6786:       </td></tr><tr><td> <code title="">femergenode</code> </td><td> <code title="">feMergeNode</code>
                   6787:       </td></tr><tr><td> <code title="">femorphology</code> </td><td> <code title="">feMorphology</code>
                   6788:       </td></tr><tr><td> <code title="">feoffset</code> </td><td> <code title="">feOffset</code>
                   6789:       </td></tr><tr><td> <code title="">fepointlight</code> </td><td> <code title="">fePointLight</code>
                   6790:       </td></tr><tr><td> <code title="">fespecularlighting</code> </td><td> <code title="">feSpecularLighting</code>
                   6791:       </td></tr><tr><td> <code title="">fespotlight</code> </td><td> <code title="">feSpotLight</code>
                   6792:       </td></tr><tr><td> <code title="">fetile</code> </td><td> <code title="">feTile</code>
                   6793:       </td></tr><tr><td> <code title="">feturbulence</code> </td><td> <code title="">feTurbulence</code>
                   6794:       </td></tr><tr><td> <code title="">foreignobject</code> </td><td> <code title="">foreignObject</code>
                   6795:       </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
                   6796:       </td></tr><tr><td> <code title="">lineargradient</code> </td><td> <code title="">linearGradient</code>
                   6797:       </td></tr><tr><td> <code title="">radialgradient</code> </td><td> <code title="">radialGradient</code>
                   6798:       <!--<tr> <td> <code title="">solidcolor</code> <td> <code title="">solidColor</code> (SVG 1.2)-->
                   6799:       </td></tr><tr><td> <code title="">textpath</code> </td><td> <code title="">textPath</code>
                   6800:     </td></tr></tbody></table><p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
                   6801:     namespace</a>, <a href="#adjust-svg-attributes">adjust SVG attributes</a> for the
                   6802:     token. (This fixes the case of SVG attributes that are not all
                   6803:     lowercase.)</p>
                   6804: 
                   6805:     <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
                   6806:     fixes the use of namespaced attributes, in particular XLink in
                   6807:     SVG.)</p>
                   6808: 
                   6809:     <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
                   6810:     same namespace as the <a href="#current-node">current node</a>.</p>
                   6811: 
                   6812:     <p>If the token has its <i>self-closing flag</i> set, pop the
                   6813:     <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   6814:     elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
                   6815:     flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
                   6816: 
                   6817:    </dd>
                   6818: 
                   6819:   </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>
                   6820: 
                   6821:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterbody" title="insertion
                   6822:   mode: after body">after body</a>", tokens must be handled as follows:</p>
                   6823: 
                   6824:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   6825:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6826:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6827:    <dd>
                   6828:     <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
                   6829:     mode</a>.</p>
                   6830:    </dd>
                   6831: 
                   6832:    <dt>A comment token</dt>
                   6833:    <dd>
                   6834:     <p>Append a <code>Comment</code> node to the first element in
1.159     mike     6835:     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     6836:     element), with the <code title="">data</code> attribute set to
                   6837:     the data given in the comment token.</p>
                   6838:    </dd>
                   6839: 
                   6840:    <dt>A DOCTYPE token</dt>
                   6841:    <dd>
                   6842:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6843:    </dd>
                   6844: 
                   6845:    <dt>A start tag whose tag name is "html"</dt>
                   6846:    <dd>
                   6847:     <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
                   6848:     mode</a>.</p>
                   6849:    </dd>
                   6850: 
                   6851:    <dt>An end tag whose tag name is "html"</dt>
                   6852:    <dd>
                   6853: 
                   6854:     <p>If the parser was originally created as part of the <a href="#html-fragment-parsing-algorithm">HTML
                   6855:     fragment parsing algorithm</a>, this is a <a href="#parse-error">parse
                   6856:     error</a>; ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
                   6857: 
                   6858:     <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
                   6859:     body</a>".</p>
                   6860: 
                   6861:    </dd>
                   6862: 
                   6863:    <dt>An end-of-file token</dt>
                   6864:    <dd>
                   6865:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6866:    </dd>
                   6867: 
                   6868:    <dt>Anything else</dt>
                   6869:    <dd>
                   6870: 
                   6871:     <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion
                   6872:     mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   6873:     body</a>" and reprocess the token.</p>
                   6874: 
                   6875:    </dd>
                   6876: 
                   6877:   </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>
                   6878: 
                   6879:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inframeset" title="insertion
                   6880:   mode: in frameset">in frameset</a>", tokens must be handled as follows:</p>
                   6881: 
                   6882:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   6883:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6884:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6885:    <dd>
                   6886:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   6887:     the <a href="#current-node">current node</a>.</p>
                   6888:    </dd>
                   6889: 
                   6890:    <dt>A comment token</dt>
                   6891:    <dd>
                   6892:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6893:     node</a> with the <code title="">data</code> attribute set to
                   6894:     the data given in the comment token.</p>
                   6895:    </dd>
                   6896: 
                   6897:    <dt>A DOCTYPE token</dt>
                   6898:    <dd>
                   6899:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6900:    </dd>
                   6901: 
                   6902:    <dt>A start tag whose tag name is "html"</dt>
                   6903:    <dd>
                   6904:     <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
                   6905:     mode</a>.</p>
                   6906:    </dd>
                   6907: 
                   6908:    <dt>A start tag whose tag name is "frameset"</dt>
                   6909:    <dd>
                   6910:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   6911:    </dd>
                   6912: 
                   6913:    <dt>An end tag whose tag name is "frameset"</dt>
                   6914:    <dd>
                   6915: 
                   6916:     <p>If the <a href="#current-node">current node</a> is the root
1.159     mike     6917:     <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     6918:     error</a>; ignore the token. (<a href="#fragment-case">fragment
                   6919:     case</a>)</p>
                   6920: 
                   6921:     <p>Otherwise, pop the <a href="#current-node">current node</a> from the
                   6922:     <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   6923: 
                   6924:     <p>If the parser was <em>not</em> originally created as part
                   6925:     of the <a href="#html-fragment-parsing-algorithm">HTML fragment parsing algorithm</a>
                   6926:     (<a href="#fragment-case">fragment case</a>), and the <a href="#current-node">current
1.5       mike     6927:     node</a> is no longer a <code><a href="obsolete.html#frameset">frameset</a></code> element, then
1.1       mike     6928:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-afterframeset" title="insertion mode: after frameset">after
                   6929:     frameset</a>".</p>
                   6930: 
                   6931:    </dd>
                   6932: 
                   6933:    <dt>A start tag whose tag name is "frame"</dt>
                   6934:    <dd>
                   6935: 
                   6936:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.
                   6937:     Immediately pop the <a href="#current-node">current node</a> off the
                   6938:     <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   6939: 
                   6940:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   6941:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   6942: 
                   6943:    </dd>
                   6944: 
                   6945:    <dt>A start tag whose tag name is "noframes"</dt>
                   6946:    <dd>
                   6947:     <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
                   6948:     mode</a>.</p>
                   6949:    </dd>
                   6950: 
                   6951:    <dt>An end-of-file token</dt>
                   6952:    <dd>
                   6953: 
                   6954:     <p>If the <a href="#current-node">current node</a> is not the root
1.159     mike     6955:     <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     6956:     error</a>.</p>
                   6957: 
                   6958:     <p class="note">It can only be the <a href="#current-node">current node</a> in
                   6959:     the <a href="#fragment-case">fragment case</a>.</p>
                   6960: 
                   6961:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6962: 
                   6963:    </dd>
                   6964: 
                   6965:    <dt>Anything else</dt>
                   6966:    <dd>
                   6967:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6968:    </dd>
                   6969: 
                   6970:   </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>
                   6971: 
                   6972:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterframeset" title="insertion
                   6973:   mode: after frameset">after frameset</a>", tokens must be handled as follows:</p>
                   6974: 
                   6975:   <!-- due to rules in the "in frameset" mode, this can't be entered in the fragment case -->
                   6976:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   6977:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6978:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6979:    <dd>
                   6980:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   6981:     the <a href="#current-node">current node</a>.</p>
                   6982:    </dd>
                   6983: 
                   6984:    <dt>A comment token</dt>
                   6985:    <dd>
                   6986:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6987:     node</a> with the <code title="">data</code> attribute set to
                   6988:     the data given in the comment token.</p>
                   6989:    </dd>
                   6990: 
                   6991:    <dt>A DOCTYPE token</dt>
                   6992:    <dd>
                   6993:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6994:    </dd>
                   6995: 
                   6996:    <dt>A start tag whose tag name is "html"</dt>
                   6997:    <dd>
                   6998:     <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
                   6999:     mode</a>.</p>
                   7000:    </dd>
                   7001: 
                   7002:    <dt>An end tag whose tag name is "html"</dt>
                   7003:    <dd>
                   7004:     <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
                   7005:     frameset</a>".</p>
                   7006:    </dd>
                   7007: 
                   7008:    <dt>A start tag whose tag name is "noframes"</dt>
                   7009:    <dd>
                   7010:     <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
                   7011:     mode</a>.</p>
                   7012:    </dd>
                   7013: 
                   7014:    <dt>An end-of-file token</dt>
                   7015:    <dd>
                   7016:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   7017:    </dd>
                   7018: 
                   7019:    <dt>Anything else</dt>
                   7020:    <dd>
                   7021:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   7022:    </dd>
                   7023: 
1.336     mike     7024:   </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     7025: 
                   7026:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-body-insertion-mode" title="insertion
                   7027:   mode: after after body">after after body</a>", tokens must be handled as follows:</p>
                   7028: 
                   7029:   <dl class="switch"><dt>A comment token</dt>
                   7030:    <dd>
                   7031:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   7032:     object with the <code title="">data</code> attribute set to the
                   7033:     data given in the comment token.</p>
                   7034:    </dd>
                   7035: 
                   7036:    <dt>A DOCTYPE token</dt>
                   7037:    <dt>A character token that is one of U+0009 CHARACTER
                   7038:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   7039:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   7040:    <dt>A start tag whose tag name is "html"</dt>
                   7041:    <dd>
                   7042:     <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
                   7043:     mode</a>.</p>
                   7044:    </dd>
                   7045: 
                   7046:    <dt>An end-of-file token</dt>
                   7047:    <dd>
                   7048:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   7049:    </dd>
                   7050: 
                   7051:    <dt>Anything else</dt>
                   7052:    <dd>
                   7053:     <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion mode</a>
                   7054:     to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" and
                   7055:     reprocess the token.</p>
                   7056:    </dd>
                   7057: 
                   7058:   </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>
                   7059: 
                   7060:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-frameset-insertion-mode" title="insertion
                   7061:   mode: after after frameset">after after frameset</a>", tokens must be handled as follows:</p>
                   7062: 
                   7063:   <dl class="switch"><dt>A comment token</dt>
                   7064:    <dd>
                   7065:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   7066:     object with the <code title="">data</code> attribute set to the
                   7067:     data given in the comment token.</p>
                   7068:    </dd>
                   7069: 
                   7070:    <dt>A DOCTYPE token</dt>
                   7071:    <dt>A character token that is one of U+0009 CHARACTER
                   7072:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   7073:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   7074:    <dt>A start tag whose tag name is "html"</dt>
                   7075:    <dd>
                   7076:     <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
                   7077:     mode</a>.</p>
                   7078:    </dd>
                   7079: 
                   7080:    <dt>An end-of-file token</dt>
                   7081:    <dd>
                   7082:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   7083:    </dd>
                   7084: 
                   7085:    <dt>A start tag whose tag name is "noframes"</dt>
                   7086:    <dd>
                   7087:     <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
                   7088:     mode</a>.</p>
                   7089:    </dd>
                   7090: 
                   7091:    <dt>Anything else</dt>
                   7092:    <dd>
                   7093:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   7094:    </dd>
                   7095: 
1.266     mike     7096:   </dl></div><div class="impl">
                   7097: 
                   7098:   <h4 id="the-end"><span class="secno">9.2.6 </span>The end</h4>
1.1       mike     7099: 
                   7100:   <p>Once the user agent <dfn id="stop-parsing" title="stop parsing">stops parsing</dfn>
                   7101:   the document, the user agent must follow the steps in this
                   7102:   section.</p>
                   7103: 
1.10      mike     7104:   <!-- this happens as part of one of the tasks that runs the parser -->
1.1       mike     7105: 
1.10      mike     7106:   <p>First, the user agent must set the <a href="dom.html#current-document-readiness">current document
                   7107:   readiness</a> to "interactive" and the <a href="#insertion-point">insertion
                   7108:   point</a> to undefined.</p>
                   7109: 
                   7110:   <p>Then, the user agent must then make a list of all the scripts
                   7111:   that are in the <a href="semantics.html#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of scripts that will execute when the
                   7112:   document has finished parsing</a>, the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts that
                   7113:   will execute asynchronously</a>, and the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts
                   7114:   that will execute as soon as possible</a>. This is the <dfn id="list-of-scripts-pending-after-the-parser-stopped">list
                   7115:   of scripts pending after the parser stopped</dfn>.</p>
                   7116: 
                   7117:   <p>The rules for <a href="semantics.html#when-a-script-completes-loading">when a script completes loading</a> start
                   7118:   applying (script execution is no longer managed by the parser).</p>
1.1       mike     7119: 
                   7120:   <p>If any of the scripts in the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts that will
                   7121:   execute as soon as possible</a> have <a href="semantics.html#completed-loading">completed
                   7122:   loading</a>, or if the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts that will execute
                   7123:   asynchronously</a> is not empty and the first script in that list
                   7124:   has <a href="semantics.html#completed-loading">completed loading</a>, then the user agent must act as
                   7125:   if those scripts just completed loading, following the rules given
                   7126:   for that in the <code><a href="semantics.html#script">script</a></code> element definition.</p>
                   7127: 
1.10      mike     7128:   <p>If the <a href="semantics.html#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of scripts that will execute when the document
                   7129:   has finished parsing</a> is not empty, and the first item in this
                   7130:   list has already <a href="semantics.html#completed-loading">completed loading</a>, then the user agent
                   7131:   must act as if that script just finished loading.</p>
                   7132: 
                   7133:   <p class="note">By this point, there will be no scripts that have
                   7134:   loaded but have not yet been executed.</p>
                   7135: 
                   7136:   <hr><!-- async --><p>Once all the scripts on the <a href="#list-of-scripts-pending-after-the-parser-stopped">list of scripts pending after
                   7137:   the parser stopped</a> have <a href="semantics.html#completed-loading">completed loading</a> and
                   7138:   been <a href="semantics.html#executing-a-script-block" title="executing a script block">executed</a>, the
                   7139:   user agent must <a href="browsers.html#queue-a-task">queue a task</a> to <a href="browsers.html#fire-a-simple-event">fire a simple
1.460     mike     7140:   event</a> named <code title="event-DOMContentLoaded">DOMContentLoaded</code> at the
1.10      mike     7141:   <code>Document</code>. (If the list is empty, this happens
                   7142:   immediately.)</p>
1.1       mike     7143: 
1.10      mike     7144:   <hr><!-- async --><p>Once everything that <dfn id="delay-the-load-event" title="delay the load event">delays the
1.1       mike     7145:   load event</dfn> of the document has completed, the user agent must
                   7146:   run the following steps:</p>
                   7147: 
                   7148:   <ol><li><a href="browsers.html#queue-a-task">Queue a task</a> to set the <a href="dom.html#current-document-readiness">current document
                   7149:    readiness</a> to "complete".</li>
                   7150: 
                   7151:    <li>If the <code>Document</code> is in a <a href="browsers.html#browsing-context">browsing
                   7152:    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     7153:    simple event</a> named <code title="event-load">load</code> at
1.1       mike     7154:    the <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object, but with
                   7155:    its <code title="dom-event-target">target</code> set to the
                   7156:    <code>Document</code> object (and the <code title="dom-event-currentTarget">currentTarget</code> set to the
                   7157:    <code><a href="browsers.html#window">Window</a></code> object).</li>
                   7158: 
                   7159:    <li>If the <code>Document</code> has a <a href="history.html#pending-state-object">pending state
                   7160:    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
                   7161:    <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object using the
                   7162:    <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
                   7163:    current value of the <a href="history.html#pending-state-object">pending state object</a>. This event
                   7164:    must bubble but not be cancelable and has no default action.</li>
                   7165: 
1.407     mike     7166:   </ol><p>The <a href="browsers.html#task-source">task source</a> for these <a href="browsers.html#concept-task" title="concept-task">tasks</a> is the <a href="browsers.html#dom-manipulation-task-source">DOM manipulation
1.228     mike     7167:   task source</a>.</p>
1.1       mike     7168: 
1.266     mike     7169:   </div><div class="impl">
1.1       mike     7170: 
                   7171:   <h4 id="coercing-an-html-dom-into-an-infoset"><span class="secno">9.2.7 </span>Coercing an HTML DOM into an infoset</h4>
                   7172: 
                   7173:   <p>When an application uses an <a href="#html-parser">HTML parser</a> in
                   7174:   conjunction with an XML pipeline, it is possible that the
                   7175:   constructed DOM is not compatible with the XML tool chain in certain
                   7176:   subtle ways. For example, an XML toolchain might not be able to
                   7177:   represent attributes with the name <code title="">xmlns</code>,
                   7178:   since they conflict with the Namespaces in XML syntax. There is also
                   7179:   some data that the <a href="#html-parser">HTML parser</a> generates that isn't
                   7180:   included in the DOM itself. This section specifies some rules for
                   7181:   handling these issues.</p>
                   7182: 
                   7183:   <p>If the XML API being used doesn't support DOCTYPEs, the tool may
                   7184:   drop DOCTYPEs altogether.</p>
                   7185: 
                   7186:   <p>If the XML API doesn't support attributes in no namespace that
                   7187:   are named "<code title="">xmlns</code>", attributes whose names
                   7188:   start with "<code title="">xmlns:</code>", or attributes in the
                   7189:   <a href="#xmlns-namespace">XMLNS namespace</a>, then the tool may drop such
                   7190:   attributes.</p>
                   7191: 
                   7192:   <p>The tool may annotate the output with any namespace declarations
                   7193:   required for proper operation.</p>
                   7194: 
                   7195:   <p>If the XML API being used restricts the allowable characters in
                   7196:   the local names of elements and attributes, then the tool may map
                   7197:   all element and attribute local names that the API wouldn't support
                   7198:   to a set of names that <em>are</em> allowed, by replacing any
                   7199:   character that isn't supported with the uppercase letter U and the
                   7200:   six digits of the character's Unicode code point when expressed in
                   7201:   hexadecimal, using digits 0-9 and capital letters A-F as the
                   7202:   symbols, in increasing numeric order.</p>
                   7203: 
                   7204:   <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
                   7205:   parser</a>, though it is neither a legal HTML element name nor a
                   7206:   well-formed XML element name, would be converted into <code title="">fooU00003Cbar</code>, which <em>is</em> a well-formed XML
                   7207:   element name (though it's still not legal in HTML by any means).</p>
                   7208: 
                   7209:   <p class="example">As another example, consider the attribute
                   7210:   <code>xlink:href</code>. Used on a MathML element, it becomes, after
                   7211:   being <a href="#adjust-foreign-attributes" title="adjust foreign attributes">adjusted</a>, an
                   7212:   attribute with a prefix "<code title="">xlink</code>" and a local
                   7213:   name "<code title="">href</code>". However, used on an HTML element,
                   7214:   it becomes an attribute with no prefix and the local name "<code title="">xlink:href</code>", which is not a valid NCName, and thus
                   7215:   might not be accepted by an XML API. It could thus get converted,
                   7216:   becoming "<code title="">xlinkU00003Ahref</code>".</p>
                   7217: 
                   7218:   <p class="note">The resulting names from this conversion
                   7219:   conveniently can't clash with any attribute generated by the
                   7220:   <a href="#html-parser">HTML parser</a>, since those are all either lowercase or
                   7221:   those listed in the <a href="#adjust-foreign-attributes">adjust foreign attributes</a>
                   7222:   algorithm's table.</p>
                   7223: 
                   7224:   <p>If the XML API restricts comments from having two consecutive
                   7225:   U+002D HYPHEN-MINUS characters (--), the tool may insert a single
                   7226:   U+0020 SPACE character between any such offending characters.</p>
                   7227: 
                   7228:   <p>If the XML API restricts comments from ending in a
                   7229:   U+002D HYPHEN-MINUS character (-), the tool may insert a single
                   7230:   U+0020 SPACE character at the end of such comments.</p>
                   7231: 
                   7232:   <p>If the XML API restricts allowed characters in character data,
1.439     mike     7233:   attribute values, or comments, the tool may replace any U+000C FORM
                   7234:   FEED (FF) character with a U+0020 SPACE character, and any other
                   7235:   literal non-XML character with a U+FFFD REPLACEMENT CHARACTER.</p>
1.1       mike     7236: 
                   7237:   <p>If the tool has no way to convey out-of-band information, then
                   7238:   the tool may drop the following information:</p>
                   7239: 
                   7240:   <ul><li>Whether the document is set to <i><a href="dom.html#no-quirks-mode">no quirks mode</a></i>,
                   7241:    <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>
                   7242: 
                   7243:    <li>The association between form controls and forms that aren't
                   7244:    their nearest <code><a href="forms.html#the-form-element">form</a></code> element ancestor (use of the
                   7245:    <a href="#form-element-pointer"><code>form</code> element pointer</a> in the parser)</li>
                   7246: 
                   7247:   </ul><p class="note">The mutations allowed by this section apply
                   7248:   <em>after</em> the <a href="#html-parser">HTML parser</a>'s rules have been
                   7249:   applied. For example, a <code title="">&lt;a::&gt;</code> start tag
                   7250:   will be closed by a <code title="">&lt;/a::&gt;</code> end tag, and
                   7251:   never by a <code title="">&lt;/aU00003AU00003A&gt;</code> end tag, even
                   7252:   if the user agent is using the rules above to then generate an
                   7253:   actual element in the DOM with the name <code title="">aU00003AU00003A</code> for that start tag.</p>
                   7254: 
1.266     mike     7255:   </div><div class="impl">
1.1       mike     7256: 
1.35      mike     7257:   <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     7258: 
                   7259:   <p><i>This section is non-normative.</i></p>
                   7260: 
                   7261:   <p>This section examines some erroneous markup and discusses how
                   7262:   the <a href="#html-parser">HTML parser</a> handles these cases.</p>
                   7263: 
                   7264: 
                   7265:   <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>
                   7266: 
                   7267:   <p><i>This section is non-normative.</i></p>
                   7268: 
                   7269:   <p>The most-often discussed example of erroneous markup is as
                   7270:   follows:</p>
                   7271: 
                   7272:   <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>
                   7273: 
                   7274:   <p>The parsing of this markup is straightforward up to the "3". At
                   7275:   this point, the DOM looks like this:</p>
                   7276: 
1.159     mike     7277:   <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
                   7278:   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     7279:   <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
                   7280:   formatting elements</a> just has two: <code><a href="text-level-semantics.html#the-b-element">b</a></code> and
                   7281:   <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>
                   7282: 
                   7283:   <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is
                   7284:   invoked. This is a simple case, in that the <var title="">formatting
                   7285:   element</var> is the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element, and there is no
                   7286:   <var title="">furthest block</var>. Thus, the <a href="#stack-of-open-elements">stack of open
1.159     mike     7287:   elements</a> ends up with just three elements: <code><a href="semantics.html#the-html-element-0">html</a></code>,
                   7288:   <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     7289:   active formatting elements</a> has just one: <code><a href="text-level-semantics.html#the-i-element">i</a></code>. The
                   7290:   DOM tree is unmodified at this point.</p>
                   7291: 
                   7292:   <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
                   7293:   the active formatting elements</a>, in this case just the
                   7294:   <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
                   7295:   for the "4" text node. After the end tag token for the "i" is also
                   7296:   received, and the "5" text node is inserted, the DOM looks as
                   7297:   follows:</p>
                   7298: 
1.159     mike     7299:   <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     7300: 
                   7301:   <p><i>This section is non-normative.</i></p>
                   7302: 
                   7303:   <p>A case similar to the previous one is the following:</p>
                   7304: 
                   7305:   <pre>&lt;b&gt;1&lt;p&gt;2&lt;/b&gt;3&lt;/p&gt;</pre>
                   7306: 
                   7307:   <p>Up to the "2" the parsing here is straightforward:</p>
                   7308: 
1.159     mike     7309:   <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     7310:   "b" is parsed.</p>
                   7311: 
                   7312:   <p>Before that token is seen, the <a href="#stack-of-open-elements">stack of open
1.159     mike     7313:   elements</a> has four elements on it: <code><a href="semantics.html#the-html-element-0">html</a></code>,
                   7314:   <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     7315:   <a href="#list-of-active-formatting-elements">list of active formatting elements</a> just has the one:
                   7316:   <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>
                   7317: 
                   7318:   <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is invoked, as
                   7319:   in the previous example. However, in this case, there <em>is</em> a
                   7320:   <var title="">furthest block</var>, namely the <code><a href="semantics.html#the-p-element">p</a></code> element. Thus,
                   7321:   this time the adoption agency algorithm isn't skipped over.</p>
                   7322: 
1.159     mike     7323:   <p>The <var title="">common ancestor</var> is the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1       mike     7324:   element. A conceptual "bookmark" marks the position of the
                   7325:   <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
                   7326:   elements</a>, but since that list has only one element in it,
                   7327:   it won't have much effect.</p>
                   7328: 
                   7329:   <p>As the algorithm progresses, <var title="">node</var> ends up set
                   7330:   to the formatting element (<code><a href="text-level-semantics.html#the-b-element">b</a></code>), and <var title="">last
                   7331:   node</var> ends up set to the <var title="">furthest block</var>
                   7332:   (<code><a href="semantics.html#the-p-element">p</a></code>).</p>
                   7333: 
                   7334:   <p>The <var title="">last node</var> gets appended (moved) to the
                   7335:   <var title="">common ancestor</var>, so that the DOM looks like:</p>
                   7336: 
1.159     mike     7337:   <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     7338:   <code><a href="semantics.html#the-p-element">p</a></code> element are moved to it:</p>
                   7339: 
1.159     mike     7340:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><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     7341:   <code><a href="semantics.html#the-p-element">p</a></code> element, so that the DOM looks like:</p>
                   7342: 
1.159     mike     7343:   <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     7344:   active formatting elements</a> and the <a href="#stack-of-open-elements">stack of open
                   7345:   elements</a>, so that when the "3" is parsed, it is appended to
                   7346:   the <code><a href="semantics.html#the-p-element">p</a></code> element:</p>
                   7347: 
1.159     mike     7348:   <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     7349: 
                   7350:   <p><i>This section is non-normative.</i></p>
                   7351: 
                   7352:   <p>Error handling in tables is, for historical reasons, especially
                   7353:   strange. For example, consider the following markup:</p>
                   7354: 
                   7355:   <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>
                   7356: 
                   7357:   <p>The highlighted <code><a href="text-level-semantics.html#the-b-element">b</a></code> element start tag is not allowed
                   7358:   directly inside a table like that, and the parser handles this case
                   7359:   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
                   7360:   examining the DOM tree as it stands just after the
                   7361:   <code><a href="tabular-data.html#the-table-element">table</a></code> element's start tag has been seen:</p>
                   7362: 
1.159     mike     7363:   <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     7364:   tag has been seen:</p>
                   7365: 
1.159     mike     7366:   <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
                   7367:   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     7368:   <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
                   7369:   resulting DOM tree); the <a href="#list-of-active-formatting-elements">list of active formatting
                   7370:   elements</a> just has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it; and the
                   7371:   <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion mode: in
                   7372:   table">in table</a>".</p>
                   7373: 
                   7374:   <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
                   7375:   to be popped off the stack and a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> start tag to be
                   7376:   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
                   7377:   then handled in a rather straight-forward manner, taking the parser
                   7378:   through the "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   7379:   body</a>" and "<a href="#parsing-main-intr" title="insertion mode: in row">in
                   7380:   row</a>" insertion modes, after which the DOM looks as
                   7381:   follows:</p>
                   7382: 
1.159     mike     7383:   <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
                   7384:   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     7385:   <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
                   7386:   formatting elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in
                   7387:   it; and the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
                   7388:   mode: in row">in row</a>".</p>
                   7389: 
                   7390:   <p>The <code><a href="tabular-data.html#the-td-element">td</a></code> element start tag token, after putting a
                   7391:   <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
                   7392:   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
                   7393:   mode</a>).</p>
                   7394: 
1.159     mike     7395:   <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     7396:   no <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created to hold the resulting text
                   7397:   node:</p>
                   7398: 
1.159     mike     7399:   <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     7400:   handling them, the <a href="#stack-of-open-elements">stack of open elements</a> has on it the
1.159     mike     7401:   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     7402:   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
                   7403:   elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it (the
                   7404:   marker having been removed by the "td" end tag token); and the
                   7405:   <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion mode: in
                   7406:   table body">in table body</a>".</p>
                   7407: 
                   7408:   <p>Thus it is that the "bbb" character tokens are found. These
                   7409:   trigger the "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table
                   7410:   text</a>" insertion mode to be used (with the <a href="#original-insertion-mode">original
                   7411:   insertion mode</a> set to "<a href="#parsing-main-intbody" title="insertion mode: in table
                   7412:   body">in table body</a>"). The character tokens are collected,
                   7413:   and when the next token (the <code><a href="tabular-data.html#the-table-element">table</a></code> element end tag) is
                   7414:   seen, they are processed as a group. Since they are not all spaces,
                   7415:   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,
                   7416:   which defer to the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   7417:   body</a>" insertion mode but with <a href="#foster-parent" title="foster
                   7418:   parent">foster parenting</a>.</p>
                   7419: 
                   7420:   <p>When <a href="#reconstruct-the-active-formatting-elements" title="reconstruct the active formatting elements">the
                   7421:   active formatting elements are reconstructed</a>, a
                   7422:   <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created and <a href="#foster-parent" title="foster
                   7423:   parent">foster parented</a>, and then the "bbb" text node is
                   7424:   appended to it:</p>
                   7425: 
1.159     mike     7426:   <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
                   7427:   <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     7428:   <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
                   7429:   this doesn't match the resulting tree!); the <a href="#list-of-active-formatting-elements">list of active
                   7430:   formatting elements</a> has the new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it;
                   7431:   and the <a href="#insertion-mode">insertion mode</a> is still "<a href="#parsing-main-intbody" title="insertion
                   7432:   mode: in table body">in table body</a>".</p>
                   7433: 
                   7434:   <p>Had the character tokens been only <a href="infrastructure.html#space-character" title="space
                   7435:   character">space characters</a> instead of "bbb", then those
                   7436:   <a href="infrastructure.html#space-character" title="space character">space characters</a> would just be
                   7437:   appended to the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element.</p>
                   7438: 
                   7439:   <p>Finally, the <code><a href="tabular-data.html#the-table-element">table</a></code> is closed by a "table" end
                   7440:   tag. This pops all the nodes from the <a href="#stack-of-open-elements">stack of open
                   7441:   elements</a> up to and including the <code><a href="tabular-data.html#the-table-element">table</a></code> element,
                   7442:   but it doesn't affect the <a href="#list-of-active-formatting-elements">list of active formatting
                   7443:   elements</a>, so the "ccc" character tokens after the table
                   7444:   result in yet another <code><a href="text-level-semantics.html#the-b-element">b</a></code> element being created, this
                   7445:   time after the table:</p>
                   7446: 
1.159     mike     7447:   <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     7448: 
                   7449:   <p><i>This section is non-normative.</i></p>
                   7450: 
                   7451:   <p>Consider the following markup, which for this example we will
                   7452:   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     7453:   content of an <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code> in another document with the
1.1       mike     7454:   <a href="infrastructure.html#url">URL</a> <code title="">http://example.com/outer</code>:</p>
                   7455: 
                   7456:   <pre>&lt;div id=a&gt;
                   7457:  &lt;script&gt;
                   7458:   var div = document.getElementById('a');
                   7459:   parent.document.body.appendChild(div);
                   7460:  &lt;/script&gt;
                   7461:  &lt;script&gt;
                   7462:   alert(document.URL);
                   7463:  &lt;/script&gt;
                   7464: &lt;/div&gt;
                   7465: &lt;script&gt;
                   7466:  alert(document.URL);
                   7467: &lt;/script&gt;</pre>
                   7468: 
                   7469:   <p>Up to the first "script" end tag, before the script is parsed,
                   7470:   the result is relatively straightforward:</p>
                   7471: 
1.306     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="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="">
                   7473:  </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     7474:   and its child <code><a href="semantics.html#script">script</a></code> element are gone:</p>
                   7475: 
1.159     mike     7476:   <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     7477:   aforementioned outer <a href="browsers.html#browsing-context">browsing context</a>. However, the
                   7478:   <a href="#stack-of-open-elements">stack of open elements</a> <em>still contains the
1.306     mike     7479:   <code><a href="semantics.html#the-div-element">div</a></code> element</em>.</p>
1.1       mike     7480: 
                   7481:   <p>Thus, when the second <code><a href="semantics.html#script">script</a></code> element is parsed, it
                   7482:   is inserted <em>into the outer <code>Document</code>
                   7483:   object</em>.</p>
                   7484: 
                   7485:   <p>This also means that the <a href="browsers.html#script-s-global-object">script's global object</a> is
                   7486:   the outer <a href="browsers.html#browsing-context">browsing context</a>'s <code><a href="browsers.html#window">Window</a></code>
                   7487:   object, <em>not</em> the <code><a href="browsers.html#window">Window</a></code> object inside the
1.159     mike     7488:   <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>.</p>
1.1       mike     7489: 
                   7490:   <p class="note">This isn't a security problem since the script that
1.306     mike     7491:   moves the <code><a href="semantics.html#the-div-element">div</a></code> into the outer <code>Document</code> can
1.1       mike     7492:   only do so because they have the two <code>Document</code> object
1.159     mike     7493:   have the same <a href="browsers.html#origin">origin</a>.</p>
1.1       mike     7494: 
                   7495:   <p>Thus, the first alert says "http://example.com/outer".</p>
                   7496: 
1.306     mike     7497:   <p>Once the <code><a href="semantics.html#the-div-element">div</a></code> element's end tag is parsed, the
                   7498:   <code><a href="semantics.html#the-div-element">div</a></code> element is popped off the stack, and so the next
1.1       mike     7499:   <code><a href="semantics.html#script">script</a></code> element is in the inner <code>Document</code>:</p>
                   7500: 
1.159     mike     7501:   <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     7502: 
                   7503: 
                   7504: 
1.215     mike     7505:   <h3 id="namespaces"><span class="secno">9.3 </span>Namespaces</h3>
1.1       mike     7506: 
                   7507:   <p>The <dfn id="html-namespace-0">HTML namespace</dfn> is: <code>http://www.w3.org/1999/xhtml</code></p>
                   7508: 
                   7509:   <p>The <dfn id="mathml-namespace">MathML namespace</dfn> is: <code>http://www.w3.org/1998/Math/MathML</code></p>
                   7510: 
                   7511:   <p>The <dfn id="svg-namespace">SVG namespace</dfn> is: <code>http://www.w3.org/2000/svg</code></p>
                   7512: 
                   7513:   <p>The <dfn id="xlink-namespace">XLink namespace</dfn> is: <code>http://www.w3.org/1999/xlink</code></p>
                   7514: 
                   7515:   <p>The <dfn id="xml-namespace">XML namespace</dfn> is: <code>http://www.w3.org/XML/1998/namespace</code></p>
                   7516: 
                   7517:   <p>The <dfn id="xmlns-namespace">XMLNS namespace</dfn> is: <code>http://www.w3.org/2000/xmlns/</code></p>
                   7518: 
                   7519:   <hr><p>Data mining tools and other user agents that perform operations
1.83      mike     7520:   on <code><a href="iana-considerations.html#text-html">text/html</a></code> content without running scripts,
1.1       mike     7521:   evaluating CSS or XPath expressions, or otherwise exposing the
                   7522:   resulting DOM to arbitrary content, may "support namespaces" by just
                   7523:   asserting that their DOM node analogues are in certain namespaces,
                   7524:   without actually exposing the above strings.</p>
                   7525: 
                   7526: 
                   7527: 
                   7528: 
                   7529:   <h3 id="serializing-html-fragments"><span class="secno">9.4 </span>Serializing HTML fragments</h3>
                   7530: 
                   7531:   <p>The following steps form the <dfn id="html-fragment-serialization-algorithm">HTML fragment serialization
                   7532:   algorithm</dfn>. The algorithm takes as input a DOM
                   7533:   <code>Element</code> or <code>Document</code>, referred to as <var title="">the node</var>, and either returns a string or raises an
                   7534:   exception.</p>
                   7535: 
                   7536:   <p class="note">This algorithm serializes the <em>children</em> of
                   7537:   the node being serialized, not the node itself.</p>
                   7538: 
                   7539:   <ol><li><p>Let <var title="">s</var> be a string, and initialize it to
                   7540:    the empty string.</p></li>
                   7541: 
                   7542:    <li>
                   7543: 
                   7544:     <p>For each child node of <var title="">the node</var>, in
                   7545:     <a href="infrastructure.html#tree-order">tree order</a>, run the following steps:
                   7546: 
                   7547:     </p><ol><li><p>Let <var title="">current node</var> be the child node
                   7548:      being processed.</p></li>
                   7549: 
                   7550:      <li>
                   7551: 
                   7552:       <p>Append the appropriate string from the following list to
                   7553:       <var title="">s</var>:</p>
                   7554: 
                   7555:       <dl class="switch"><dt>If <var title="">current node</var> is an <code title="">Element</code></dt>
                   7556: 
                   7557:        <dd>
                   7558: 
                   7559:         <p>Append a U+003C LESS-THAN SIGN (<code title="">&lt;</code>)
                   7560:         character, followed by the element's tag name. (For nodes
                   7561:         created by the <a href="#html-parser">HTML parser</a> or <code title="">Document.createElement()</code>, the tag name will be
                   7562:         lowercase.)</p>
                   7563: 
                   7564:         <p>For each attribute that the element has, append a U+0020
                   7565:         SPACE character, the attribute's name (which, for attributes
                   7566:         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
                   7567:         U+003D EQUALS SIGN (<code title="">=</code>) character, a
                   7568:         U+0022 QUOTATION MARK (<code title="">"</code>)
                   7569:         character, the attribute's value, <a href="#escapingString" title="escaping a
                   7570:         string">escaped as described below</a> in <i>attribute
                   7571:         mode</i>, and a second U+0022 QUOTATION MARK (<code title="">"</code>) character.</p>
                   7572: 
                   7573:         <p>While the exact order of attributes is UA-defined, and may
                   7574:         depend on factors such as the order that the attributes were
                   7575:         given in the original markup, the sort order must be stable,
                   7576:         such that consecutive invocations of this algorithm serialize an
                   7577:         element's attributes in the same order.</p>
                   7578: 
                   7579:         <p>Append a U+003E GREATER-THAN SIGN (<code title="">&gt;</code>)
                   7580:         character.</p>
                   7581: 
                   7582:         <p>If <var title="">current node</var> is an
1.5       mike     7583:         <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     7584:         <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     7585:         <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>,
                   7586:         <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>,
                   7587:         <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     7588:         <code><a href="obsolete.html#spacer">spacer</a></code>, or <code>wbr</code> element, then
1.1       mike     7589:         continue on to the next child node at this point.</p> <!--
                   7590:         also, i guess: image and isindex, but we don't list those
                   7591:         because we don't consider those "elements", more "macros", and
                   7592:         thus we should never serialize them -->
                   7593: 
                   7594:         <p>If <var title="">current node</var> is a <code><a href="semantics.html#the-pre-element">pre</a></code>,
1.42      mike     7595:         <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     7596:         a U+000A LINE FEED (LF) character.</p>
                   7597: 
                   7598:         <p>Append the value of running the <a href="#html-fragment-serialization-algorithm">HTML fragment
                   7599:         serialization algorithm</a> on the <var title="">current
                   7600:         node</var> element (thus recursing into this algorithm for
                   7601:         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,
                   7602:         and finally a U+003E GREATER-THAN SIGN (<code title="">&gt;</code>) character.</p>
                   7603: 
                   7604:        </dd>
                   7605: 
                   7606: 
                   7607:        <dt>If <var title="">current node</var> is a <code title="">Text</code> or <code title="">CDATASection</code>
                   7608:        node</dt>
                   7609: 
                   7610:        <dd>
                   7611: 
1.19      mike     7612:         <p>If the parent of <var title="">current node</var> is a
1.42      mike     7613:         <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     7614:         <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     7615:         <code><a href="obsolete.html#noframes">noframes</a></code>, or <code><a href="obsolete.html#plaintext">plaintext</a></code> element, or
                   7616:         if the parent of <var title="">current node</var> is
                   7617:         <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
                   7618:         node, then append the value of <var title="">current
                   7619:         node</var>'s <code title="">data</code> IDL attribute
                   7620:         literally.</p>
1.1       mike     7621: 
                   7622:         <p>Otherwise, append the value of <var title="">current
1.192     mike     7623:         node</var>'s <code title="">data</code> IDL attribute, <a href="#escapingString" title="escaping a string">escaped as described
1.1       mike     7624:         below</a>.</p>
                   7625: 
                   7626:        </dd>
                   7627: 
                   7628: 
                   7629:        <dt>If <var title="">current node</var> is a <code title="">Comment</code></dt>
                   7630: 
                   7631:        <dd>
                   7632: 
                   7633:         <p>Append the literal string <code>&lt;!--</code> (U+003C
                   7634:         LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS,
1.192     mike     7635:         U+002D HYPHEN-MINUS), followed by the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1       mike     7636:         attribute, followed by the literal string <code>--&gt;</code>
                   7637:         (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN
                   7638:         SIGN).</p>
                   7639: 
                   7640:        </dd>
                   7641: 
                   7642: 
                   7643:        <dt>If <var title="">current node</var> is a <code title="">ProcessingInstruction</code></dt>
                   7644: 
                   7645:        <dd>
                   7646: 
                   7647:         <p>Append the literal string <code>&lt;?</code> (U+003C
                   7648:         LESS-THAN SIGN, U+003F QUESTION MARK), followed by the value
1.192     mike     7649:         of <var title="">current node</var>'s <code title="">target</code> IDL attribute, followed by a single
                   7650:         U+0020 SPACE character, followed by the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1       mike     7651:         attribute, followed by a single U+003E GREATER-THAN SIGN
1.464     mike     7652:         character (&gt;).</p>
1.1       mike     7653: 
                   7654:        </dd>
                   7655: 
                   7656: 
                   7657:        <dt>If <var title="">current node</var> is a <code title="">DocumentType</code></dt>
                   7658: 
                   7659:        <dd>
                   7660: 
                   7661:         <p>Append the literal string <code>&lt;!DOCTYPE</code> (U+003C
                   7662:         LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+0044 LATIN CAPITAL
                   7663:         LETTER D, U+004F LATIN CAPITAL LETTER O, U+0043 LATIN CAPITAL
                   7664:         LETTER C, U+0054 LATIN CAPITAL LETTER T, U+0059 LATIN CAPITAL
                   7665:         LETTER Y, U+0050 LATIN CAPITAL LETTER P, U+0045 LATIN CAPITAL
                   7666:         LETTER E), followed by a space (U+0020 SPACE), followed by the
1.192     mike     7667:         value of <var title="">current node</var>'s <code title="">name</code> IDL attribute, followed by the literal
1.1       mike     7668:         string <code>&gt;</code> (U+003E GREATER-THAN SIGN).</p>
                   7669: 
                   7670:        </dd>
                   7671: 
                   7672: 
                   7673:       </dl><p>Other node types (e.g. <code title="">Attr</code>) cannot
                   7674:       occur as children of elements. If, despite this, they somehow do
                   7675:       occur, this algorithm must raise an
                   7676:       <code><a href="infrastructure.html#invalid_state_err">INVALID_STATE_ERR</a></code> exception.</p>
                   7677: 
                   7678:      </li>
                   7679: 
                   7680:     </ol></li>
                   7681: 
                   7682:    <li><p>The result of the algorithm is the string <var title="">s</var>.</p></li>
                   7683: 
                   7684:   </ol><p><dfn id="escapingString">Escaping a string</dfn> (for the
                   7685:   purposes of the algorithm above) consists of replacing any
                   7686:   occurrences of the "<code title="">&amp;</code>" character by the
                   7687:   string "<code title="">&amp;amp;</code>", any occurrences of the
                   7688:   U+00A0 NO-BREAK SPACE character by the string "<code title="">&amp;nbsp;</code>", and, if the algorithm was invoked in
                   7689:   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
                   7690:   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>
                   7691: 
                   7692:   <p class="note">Entity reference nodes are <a href="infrastructure.html#entity-references">assumed to be expanded</a> by the user
                   7693:   agent, and are therefore not covered in the algorithm above.</p>
                   7694: 
                   7695:   <p class="note">It is possible that the output of this algorithm, if
                   7696:   parsed with an <a href="#html-parser">HTML parser</a>, will not return the
                   7697:   original tree structure. For instance, if a <code><a href="forms.html#the-textarea-element">textarea</a></code>
                   7698:   element to which a <code title="">Comment</code> node has been
                   7699:   appended is serialized and the output is then reparsed, the comment
                   7700:   will end up being displayed in the text field. Similarly, if, as a
                   7701:   result of DOM manipulation, an element contains a comment that
                   7702:   contains the literal string "<code title="">--&gt;</code>", then
                   7703:   when the result of serializing the element is parsed, the comment
                   7704:   will be truncated at that point and the rest of the comment will be
                   7705:   interpreted as markup. More examples would be making a
                   7706:   <code><a href="semantics.html#script">script</a></code> element contain a text node with the text string
                   7707:   "<code>&lt;/script&gt;</code>", or having a <code><a href="semantics.html#the-p-element">p</a></code> element that
                   7708:   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
                   7709:   <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> would imply the end
                   7710:   tag for the <code><a href="semantics.html#the-p-element">p</a></code>).</p>
                   7711: 
                   7712: 
                   7713:   <h3 id="parsing-html-fragments"><span class="secno">9.5 </span>Parsing HTML fragments</h3>
                   7714: 
                   7715:   <p>The following steps form the <dfn id="html-fragment-parsing-algorithm">HTML fragment parsing
                   7716:   algorithm</dfn>. The algorithm optionally takes as input an
                   7717:   <code>Element</code> node, referred to as the <var title="">context</var> element, which gives the context for the
                   7718:   parser, as well as <var title="">input</var>, a string to parse, and
                   7719:   returns a list of zero or more nodes.</p>
                   7720: 
                   7721:   <p class="note">Parts marked <dfn id="fragment-case">fragment case</dfn> in algorithms
                   7722:   in the parser section are parts that only occur if the parser was
                   7723:   created for the purposes of this algorithm (and with a <var title="">context</var> element). The algorithms have been annotated
                   7724:   with such markings for informational purposes only; such markings
                   7725:   have no normative weight. If it is possible for a condition
                   7726:   described as a <a href="#fragment-case">fragment case</a> to occur even when the
                   7727:   parser wasn't created for the purposes of handling this algorithm,
                   7728:   then that is an error in the specification.</p>
                   7729: 
                   7730:   <ol><li>
                   7731: 
                   7732:     <p>Create a new <code>Document</code> node, and mark it as being
                   7733:     an <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
                   7734: 
                   7735:    </li>
                   7736: 
                   7737:    <li>
                   7738: 
                   7739:     <p>If there is a <var title="">context</var> element, and the
                   7740:     <code>Document</code> of the <var title="">context</var> element
                   7741:     is in <a href="dom.html#quirks-mode">quirks mode</a>, then let the <code>Document</code>
                   7742:     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
                   7743:     the <var title="">context</var> element is in <a href="dom.html#limited-quirks-mode">limited quirks
                   7744:     mode</a>, then let the <code>Document</code> be in
                   7745:     <a href="dom.html#limited-quirks-mode">limited quirks mode</a>. Otherwise, leave the
                   7746:     <code>Document</code> in <a href="dom.html#no-quirks-mode">no quirks mode</a>.</p>
                   7747: 
                   7748:    </li>
                   7749: 
                   7750:    <li>
                   7751: 
                   7752:     <p>Create a new <a href="#html-parser">HTML parser</a>, and associate it with
                   7753:     the just created <code>Document</code> node.</p>
                   7754: 
                   7755:    </li>
                   7756: 
                   7757:    <li>
                   7758: 
                   7759:     <p>If there is a <var title="">context</var> element, run these
                   7760:     substeps:</p>
                   7761: 
                   7762:     <ol><li>
                   7763: 
                   7764:       <p>Set the <a href="#html-parser">HTML parser</a>'s <a href="#tokenization">tokenization</a>
                   7765:       stage's <a href="#content-model-flag">content model flag</a> according to the <var title="">context</var> element, as follows:</p>
                   7766: 
1.159     mike     7767:       <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     7768:        element</dt>
                   7769: 
                   7770:        <dd>Set the <a href="#content-model-flag">content model flag</a> to
                   7771:        the RCDATA state.</dd>
                   7772: 
                   7773: 
                   7774:        <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     7775:        <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     7776:        <code><a href="obsolete.html#noframes">noframes</a></code> element</dt>
1.1       mike     7777: 
                   7778:        <dd>Set the <a href="#content-model-flag">content model flag</a> to
1.91      mike     7779:        the RAWTEXT state.</dd>
1.1       mike     7780: 
                   7781: 
                   7782:        <dt>If it is a <code><a href="semantics.html#the-noscript-element">noscript</a></code> element</dt>
                   7783: 
                   7784:        <dd>If the <a href="#scripting-flag">scripting flag</a> is enabled, set the
1.91      mike     7785:        <a href="#content-model-flag">content model flag</a> to the RAWTEXT
1.1       mike     7786:        state. Otherwise, set the <a href="#content-model-flag">content model flag</a> to the
                   7787:        PCDATA state.</dd>
                   7788: 
                   7789: 
1.42      mike     7790:        <dt>If it is a <code><a href="obsolete.html#plaintext">plaintext</a></code> element</dt>
1.1       mike     7791: 
                   7792:        <dd>Set the <a href="#content-model-flag">content model flag</a> to
                   7793:        PLAINTEXT.</dd>
                   7794: 
                   7795: 
                   7796:        <dt>Otherwise</dt>
                   7797: 
                   7798:        <dd>Leave the <a href="#content-model-flag">content model flag</a> in the PCDATA
                   7799:        state.</dd>
                   7800: 
                   7801:       </dl></li>
                   7802: 
                   7803:      <li>
                   7804: 
1.159     mike     7805:       <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     7806:       with no attributes.</p>
                   7807: 
                   7808:      </li>
                   7809: 
                   7810:      <li>
                   7811: 
                   7812:       <p>Append the element <var title="">root</var> to the
                   7813:       <code>Document</code> node created above.</p>
                   7814: 
                   7815:      </li>
                   7816: 
                   7817:      <li>
                   7818: 
                   7819:       <p>Set up the parser's <a href="#stack-of-open-elements">stack of open elements</a> so that
                   7820:       it contains just the single element <var title="">root</var>.</p>
                   7821: 
                   7822:      </li>
                   7823: 
                   7824:      <li>
                   7825: 
                   7826:       <p><a href="#reset-the-insertion-mode-appropriately" title="reset the insertion mode appropriately">Reset the
                   7827:       parser's insertion mode appropriately</a>.</p>
                   7828: 
                   7829:       <p class="note">The parser will reference the <var title="">context</var> element as part of that algorithm.</p>
                   7830: 
                   7831:      </li>
                   7832: 
                   7833:      <li>
                   7834: 
                   7835:       <p>Set the parser's <a href="#form-element-pointer"><code>form</code> element pointer</a>
                   7836:       to the nearest node to the <var title="">context</var> element
                   7837:       that is a <code><a href="forms.html#the-form-element">form</a></code> element (going straight up the
                   7838:       ancestor chain, and including the element itself, if it is a
                   7839:       <code><a href="forms.html#the-form-element">form</a></code> element), or, if there is no such
                   7840:       <code><a href="forms.html#the-form-element">form</a></code> element, to null.</p>
                   7841: 
                   7842:      </li>
                   7843: 
                   7844:     </ol></li>
                   7845: 
                   7846:    <li>
                   7847: 
                   7848:     <p>Place into the <a href="#the-input-stream">input stream</a> for the <a href="#html-parser">HTML
                   7849:     parser</a> just created the <var title="">input</var>. The
                   7850:     encoding <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   7851:     <i>irrelevant</i>.</p>
                   7852: 
                   7853:    </li>
                   7854: 
                   7855:    <li>
                   7856: 
                   7857:     <p>Start the parser and let it run until it has consumed all the
                   7858:     characters just inserted into the input stream.</p>
                   7859: 
                   7860:    </li>
                   7861: 
                   7862:    <li>
                   7863: 
                   7864:     <p>If there is a <var title="">context</var> element, return the
                   7865:     child nodes of <var title="">root</var>, in <a href="infrastructure.html#tree-order">tree
                   7866:     order</a>.</p>
                   7867: 
                   7868:     <p>Otherwise, return the children of the <code>Document</code>
                   7869:     object, in <a href="infrastructure.html#tree-order">tree order</a>.</p>
                   7870: 
                   7871:    </li>
                   7872: 
1.123     mike     7873:   </ol></div></body></html>

Webmaster