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

1.2       mike        1: <!DOCTYPE HTML>
1.12      mike        2: <html lang="en-US-x-Hixie"><head><title>9 The HTML syntax &#8212; HTML 5</title><style type="text/css">
1.1       mike        3:    pre { margin-left: 2em; white-space: pre-wrap; }
                      4:    h2 { margin: 3em 0 1em 0; }
                      5:    h3 { margin: 2.5em 0 1em 0; }
                      6:    h4 { margin: 2.5em 0 0.75em 0; }
                      7:    h5, h6 { margin: 2.5em 0 1em; }
                      8:    h1 + h2, h1 + h2 + h2 { margin: 0.75em 0 0.75em; }
                      9:    h2 + h3, h3 + h4, h4 + h5, h5 + h6 { margin-top: 0.5em; }
                     10:    p { margin: 1em 0; }
                     11:    hr:not(.top) { display: block; background: none; border: none; padding: 0; margin: 2em 0; height: auto; }
                     12:    dl, dd { margin-top: 0; margin-bottom: 0; }
                     13:    dt { margin-top: 0.75em; margin-bottom: 0.25em; clear: left; }
                     14:    dt + dt { margin-top: 0; }
                     15:    dd dt { margin-top: 0.25em; margin-bottom: 0; }
                     16:    dd p { margin-top: 0; }
                     17:    dd dl + p { margin-top: 1em; }
                     18:    dd table + p { margin-top: 1em; }
                     19:    p + * > li, dd li { margin: 1em 0; }
                     20:    dt, dfn { font-weight: bold; font-style: normal; }
                     21:    dt dfn { font-style: italic; }
                     22:    pre, code { font-size: inherit; font-family: monospace; font-variant: normal; }
                     23:    pre strong { color: black; font: inherit; font-weight: bold; background: yellow; }
                     24:    pre em { font-weight: bolder; font-style: normal; }
                     25:    @media screen { code { color: orangered; } code :link, code :visited { color: inherit; } }
                     26:    var sub { vertical-align: bottom; font-size: smaller; position: relative; top: 0.1em; }
                     27:    table { border-collapse: collapse; border-style: hidden hidden none hidden; }
                     28:    table thead { border-bottom: solid; }
                     29:    table tbody th:first-child { border-left: solid; }
                     30:    table td, table th { border-left: solid; border-right: solid; border-bottom: solid thin; vertical-align: top; padding: 0.2em; }
                     31:    blockquote { margin: 0 0 0 2em; border: 0; padding: 0; font-style: italic; }
                     32: 
                     33:    .bad, .bad *:not(.XXX) { color: gray; border-color: gray; background: transparent; }
                     34:    .matrix, .matrix td { border: none; text-align: right; }
                     35:    .matrix { margin-left: 2em; }
                     36:    .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
                     37:    .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
                     38:    .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
1.2       mike       39:    .applies th > * { display: block; }
1.1       mike       40:    .applies thead code { display: block; }
                     41:    .applies td { text-align: center; }
                     42:    .applies .yes { background: yellow; }
                     43: 
                     44:    .toc dfn, h1 dfn, h2 dfn, h3 dfn, h4 dfn, h5 dfn, h6 dfn { font: inherit; }
                     45:    img.extra { float: right; }
                     46:    pre.idl { border: solid thin; background: #EEEEEE; color: black; padding: 0.5em 1em; }
                     47:    pre.idl :link, pre.idl :visited { color: inherit; background: transparent; }
                     48:    pre.css { border: solid thin; background: #FFFFEE; color: black; padding: 0.5em 1em; }
                     49:    pre.css:first-line { color: #AAAA50; }
                     50:    dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #EEFFEE; }
                     51:    hr + dl.domintro, div.impl + dl.domintro { margin-top: 2.5em; margin-bottom: 1.5em; }
                     52:    dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
                     53:    dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
                     54:    dl.domintro dd p { margin: 0.5em 0; }
                     55:    dl.switch { padding-left: 2em; }
                     56:    dl.switch > dt { text-indent: -1.5em; }
                     57:    dl.switch > dt:before { content: '\21AA'; padding: 0 0.5em 0 0; display: inline-block; width: 1em; text-align: right; line-height: 0.5em; }
                     58:    dl.triple { padding: 0 0 0 1em; }
                     59:    dl.triple dt, dl.triple dd { margin: 0; display: inline }
                     60:    dl.triple dt:after { content: ':'; }
                     61:    dl.triple dd:after { content: '\A'; white-space: pre; }
                     62:    .diff-old { text-decoration: line-through; color: silver; background: transparent; }
                     63:    .diff-chg, .diff-new { text-decoration: underline; color: green; background: transparent; }
                     64:    a .diff-new { border-bottom: 1px blue solid; }
                     65: 
                     66:    h2 { page-break-before: always; }
                     67:    h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }
                     68:    h1 + h2, hr + h2.no-toc { page-break-before: auto; }
                     69: 
                     70:    p > span:not([title=""]):not([class="XXX"]):not([class="impl"]), li > span:not([title=""]):not([class="XXX"]):not([class="impl"]) { border-bottom: solid #9999CC; }
                     71: 
                     72:    div.head { margin: 0 0 1em; padding: 1em 0 0 0; }
                     73:    div.head p { margin: 0; }
                     74:    div.head h1 { margin: 0; }
                     75:    div.head .logo { float: right; margin: 0 1em; }
                     76:    div.head .logo img { border: none } /* remove border from top image */
                     77:    div.head dl { margin: 1em 0; }
                     78:    p.copyright { font-size: x-small; font-style: oblique; margin: 0; }
                     79: 
                     80:    body > .toc > li { margin-top: 1em; margin-bottom: 1em; }
                     81:    body > .toc.brief > li { margin-top: 0.35em; margin-bottom: 0.35em; }
                     82:    body > .toc > li > * { margin-bottom: 0.5em; }
                     83:    body > .toc > li > * > li > * { margin-bottom: 0.25em; }
                     84:    .toc, .toc li { list-style: none; }
                     85: 
                     86:    .brief { margin-top: 1em; margin-bottom: 1em; line-height: 1.1; }
                     87:    .brief li { margin: 0; padding: 0; }
                     88:    .brief li p { margin: 0; padding: 0; }
                     89: 
                     90:    .category-list { margin-top: -0.75em; margin-bottom: 1em; line-height: 1.5; }
                     91:    .category-list::before { content: '\21D2\A0'; font-size: 1.2em; font-weight: 900; }
                     92:    .category-list li { display: inline; }
                     93:    .category-list li:not(:last-child)::after { content: ', '; }
                     94:    .category-list li > span, .category-list li > a { text-transform: lowercase; }
                     95:    .category-list li * { text-transform: none; } /* don't affect <code> nested in <a> */
                     96: 
                     97:    .XXX { color: #E50000; background: white; border: solid red; padding: 0.5em; margin: 1em 0; }
                     98:    .XXX > :first-child { margin-top: 0; }
                     99:    p .XXX { line-height: 3em; }
1.159     mike      100:    .annotation { border: solid thin black; background: #0C479D; color: white; position: relative; margin: 8px 0 20px 0; }
                    101:    .annotation:before { position: absolute; left: 0; top: 0; width: 100%; height: 100%; margin: 6px -6px -6px 6px; background: #333333; z-index: -1; content: ''; }
                    102:    .annotation :link, .annotation :visited { color: inherit; }
                    103:    .annotation :link:hover, .annotation :visited:hover { background: transparent; }
                    104:    .annotation span { border: none ! important; }
1.1       mike      105:    .note { color: green; background: transparent; font-family: sans-serif; }
                    106:    .warning { color: red; background: transparent; }
                    107:    .note, .warning { font-weight: bolder; font-style: italic; }
                    108:    p.note, div.note { padding: 0.5em 2em; }
                    109:    span.note { padding: 0 2em; }
                    110:    .note p:first-child, .warning p:first-child { margin-top: 0; }
                    111:    .note p:last-child, .warning p:last-child { margin-bottom: 0; }
                    112:    .warning:before { font-style: normal; }
                    113:    p.note:before { content: 'Note: '; }
                    114:    p.warning:before { content: '\26A0 Warning! '; }
                    115: 
                    116:    .bookkeeping:before { display: block; content: 'Bookkeeping details'; font-weight: bolder; font-style: italic; }
                    117:    .bookkeeping { font-size: 0.8em; margin: 2em 0; }
                    118:    .bookkeeping p { margin: 0.5em 2em; display: list-item; list-style: square; }
                    119: 
                    120:    h4 { position: relative; z-index: 3; }
                    121:    h4 + .element, h4 + div + .element { margin-top: -2.5em; padding-top: 2em; }
                    122:    .element {
                    123:      background: #EEEEFF;
                    124:      color: black;
                    125:      margin: 0 0 1em 0.15em;
                    126:      padding: 0 1em 0.25em 0.75em;
                    127:      border-left: solid #9999FF 0.25em;
                    128:      position: relative;
                    129:      z-index: 1;
                    130:    }
                    131:    .element:before {
                    132:      position: absolute;
                    133:      z-index: 2;
                    134:      top: 0;
                    135:      left: -1.15em;
                    136:      height: 2em;
                    137:      width: 0.9em;
                    138:      background: #EEEEFF;
                    139:      content: ' ';
                    140:      border-style: none none solid solid;
                    141:      border-color: #9999FF;
                    142:      border-width: 0.25em;
                    143:    }
                    144: 
1.149     mike      145:    .example { display: block; color: #222222; background: #FCFCFC; border-left: double; margin-left: 2em; padding-left: 1em; }
                    146:    td > .example:only-child { margin: 0 0 0 0.1em; }
1.1       mike      147: 
                    148:    .tall-and-narrow {
                    149:      font-size: 0.6em;
                    150:      column-width: 25em;
                    151:      column-gap: 1em;
                    152:      -moz-column-width: 25em;
                    153:      -moz-column-gap: 1em;
                    154:      -webkit-column-width: 25em;
                    155:      -webkit-column-gap: 1em;
                    156:    }
                    157: 
                    158:    ul.domTree, ul.domTree ul { padding: 0 0 0 1em; margin: 0; }
                    159:    ul.domTree li { padding: 0; margin: 0; list-style: none; position: relative; }
                    160:    ul.domTree li li { list-style: none; }
                    161:    ul.domTree li:first-child::before { position: absolute; top: 0; height: 0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
                    162:    ul.domTree li:not(:last-child)::after { position: absolute; top: 0; bottom: -0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
                    163:    ul.domTree span { font-style: italic; font-family: serif; }
                    164:    ul.domTree .t1 code { color: purple; font-weight: bold; }
                    165:    ul.domTree .t2 { font-style: normal; font-family: monospace; }
                    166:    ul.domTree .t2 .name { color: black; font-weight: bold; }
                    167:    ul.domTree .t2 .value { color: blue; font-weight: normal; }
                    168:    ul.domTree .t3 code, .domTree .t4 code, .domTree .t5 code { color: gray; }
                    169:    ul.domTree .t7 code, .domTree .t8 code { color: green; }
                    170:    ul.domTree .t10 code { color: teal; }
                    171: 
1.158     mike      172:   </style><link href="data:text/css," rel="stylesheet" title="Complete specification"><link href="data:text/css,.impl%20%7B%20display:%20none;%20%7D" rel="alternate stylesheet" title="Author documentation only"><link href="data:text/css,.impl%20%7B%20background:%20%23FFEEEE;%20%7D" rel="alternate stylesheet" title="Highlight implementation requirements"><link href="http://www.w3.org/StyleSheets/TR/W3C-WD" rel="stylesheet" type="text/css"><!-- ZZZ ED vs WD -->
1.2       mike      173:   <script src="link-fixup.js"></script>
                    174:   <link href="comms.html" title="8 Communication" rel="prev">
                    175:   <link href="spec.html#contents" title="Table of contents" rel="index">
1.1       mike      176:   <link href="named-character-references.html" title="9.6 Named character references" rel="next">
1.16      mike      177:   </head><body onload="fixBrokenLink(); fixBrokenLink()"><div class="head">
1.1       mike      178:    <p><a href="http://www.w3.org/"><img alt="W3C" height="48" src="http://www.w3.org/Icons/w3c_home" width="72"></a></p>
1.183     mike      179:    <h1>HTML5</h1>
1.1       mike      180:    <h2 class="no-num no-toc" id="a-vocabulary-and-associated-apis-for-html-and-xhtml">A vocabulary and associated APIs for HTML and XHTML</h2>
1.123     mike      181:    </div><nav>
1.1       mike      182:    <a href="comms.html">&#8592; 8 Communication</a> &#8211;
1.2       mike      183:    <a href="spec.html#contents">Table of contents</a> &#8211;
1.1       mike      184:    <a href="named-character-references.html">9.6 Named character references &#8594;</a>
1.195   ! mike      185:   </nav><p>This is revision 1.2896.</p>
1.11      mike      186: 
1.1       mike      187: 
1.123     mike      188:   <h2 id="syntax"><span class="secno">9 </span><dfn>The HTML syntax</dfn></h2><p class="note">This section only describes the rules for
1.83      mike      189:   <code><a href="iana-considerations.html#text-html">text/html</a></code> resources. Rules for XML resources are
1.1       mike      190:   discussed in the section below entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
1.159     mike      191:   syntax</a>".</p><h3 id="writing"><span class="secno">9.1 </span>Writing HTML documents</h3><p class="XXX annotation"><b>Status: </b><i>Working draft</i></p><div class="impl">
1.1       mike      192: 
                    193:   <p><i>This section only applies to documents, authoring tools, and
                    194:   markup generators. In particular, it does not apply to conformance
                    195:   checkers; conformance checkers must use the requirements given in
                    196:   the next section ("parsing HTML documents").</i></p>
                    197: 
1.123     mike      198:   </div><p>Documents must consist of the following parts, in the given
                    199:   order:</p><ol><li>Optionally, a single U+FEFF BYTE ORDER MARK (BOM) character.</li>
1.1       mike      200: 
                    201:    <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
                    202:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    203: 
                    204:    <li>A <a href="#syntax-doctype" title="syntax-doctype">DOCTYPE</a>.
                    205: 
                    206:    </li><li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
                    207:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    208: 
1.159     mike      209:    <li>The root element, in the form of an <code><a href="semantics.html#the-html-element-0">html</a></code> <a href="#syntax-elements" title="syntax-elements">element</a>.</li>
1.1       mike      210: 
                    211:    <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
                    212:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    213: 
                    214:   </ol><p>The various types of content mentioned above are described in the
1.123     mike      215:   next few sections.</p><p>In addition, there are some restrictions on how <a href="semantics.html#character-encoding-declaration" title="character encoding declaration">character encoding
1.1       mike      216:   declarations</a> are to be serialized, as discussed in the
1.123     mike      217:   section on that topic.</p><div class="note">
1.1       mike      218: 
1.159     mike      219:    <p>Space characters before the root <code><a href="semantics.html#the-html-element-0">html</a></code> element, and
                    220:    space characters at the start of the <code><a href="semantics.html#the-html-element-0">html</a></code> element and
                    221:    before the <code><a href="semantics.html#the-head-element-0">head</a></code> element, will be dropped when the
1.1       mike      222:    document is parsed; space characters <em>after</em> the root
1.159     mike      223:    <code><a href="semantics.html#the-html-element-0">html</a></code> element will be parsed as if they were at the end
                    224:    of the <code><a href="semantics.html#the-body-element-0">body</a></code> element. Thus, space characters around the
1.1       mike      225:    root element do not round-trip.</p>
                    226: 
                    227:    <p>It is suggested that newlines be inserted after the DOCTYPE,
                    228:    after any comments that are before the root element, after the
1.159     mike      229:    <code><a href="semantics.html#the-html-element-0">html</a></code> element's start tag (if it is not <a href="#syntax-tag-omission" title="syntax-tag-omission">omitted</a>), and after any comments
                    230:    that are inside the <code><a href="semantics.html#the-html-element-0">html</a></code> element but before the
                    231:    <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1       mike      232: 
1.123     mike      233:   </div><p>Many strings in the HTML syntax (e.g. the names of elements and
1.1       mike      234:   their attributes) are case-insensitive, but only for characters in
                    235:   the ranges U+0041 .. U+005A (LATIN CAPITAL LETTER A to LATIN CAPITAL
                    236:   LETTER Z) and U+0061 .. U+007A (LATIN SMALL LETTER A to LATIN SMALL
                    237:   LETTER Z). For convenience, in this section this is just referred to
1.168     mike      238:   as "case-insensitive".</p><h4 id="the-doctype"><span class="secno">9.1.1 </span>The DOCTYPE</h4><p class="XXX annotation"><span><a href="http://www.w3.org/html/wg/tracker/issues/4">ISSUE-4</a> (html-versioning) blocks progress to Last Call</span></p><p>A <dfn id="syntax-doctype" title="syntax-doctype">DOCTYPE</dfn> is a mostly useless,
1.123     mike      239:   but required, header.</p><p class="note">DOCTYPEs are required for legacy reasons. When
1.1       mike      240:   omitted, browsers tend to use a different rendering mode that is
                    241:   incompatible with some specifications. Including the DOCTYPE in a
                    242:   document ensures that the browser makes a best-effort attempt at
1.123     mike      243:   following the relevant specifications.</p><p>A DOCTYPE must consist of the following characters, in this
                    244:   order:</p><ol class="brief"><li>A U+003C LESS-THAN SIGN (<code>&lt;</code>) character.</li>
1.1       mike      245:    <li>A U+0021 EXCLAMATION MARK (<code>!</code>) character.</li>
                    246:    <li>A string that is an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title="">DOCTYPE</code>".</li>
                    247:    <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    248:    <li>A string that is an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title="">HTML</code>".</li>
                    249:    <li>Optionally, a <a href="#doctype-legacy-string">DOCTYPE legacy string</a> (defined below).</li>
                    250:    <li>Zero or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    251:    <li>A U+003E GREATER-THAN SIGN (<code>&gt;</code>) character.</li>
                    252:   </ol><p class="note">In other words, <code>&lt;!DOCTYPE HTML&gt;</code>,
1.123     mike      253:   case-insensitively.</p><p>For the purposes of HTML generators that cannot output HTML
1.1       mike      254:   markup with the short DOCTYPE "<code title="">&lt;!DOCTYPE
                    255:   HTML&gt;</code>", a <dfn id="doctype-legacy-string">DOCTYPE legacy string</dfn> may be inserted
                    256:   into the DOCTYPE (in the position defined above). This string must
1.123     mike      257:   consist of:</p><ol class="brief"><li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
1.1       mike      258:    <li>A string that is an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title="">SYSTEM</code>".</li>
                    259:    <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    260:    <li>A U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (the <i>quote mark</i>).</li>
                    261:    <li>The literal string "<code title="">about:legacy-compat</code>".</li>
                    262:    <li>A matching U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (i.e. the same character as in the earlier step marked <i>quote mark</i>).</li>
                    263:   </ol><p class="note">In other words, <code>&lt;!DOCTYPE HTML SYSTEM
                    264:   "about:legacy-compat"&gt;</code> or <code>&lt;!DOCTYPE HTML SYSTEM
                    265:   'about:legacy-compat'&gt;</code>, case-insensitively except for the bit
1.123     mike      266:   in quotes.</p><p>The <a href="#doctype-legacy-string">DOCTYPE legacy string</a> should not be used unless
1.1       mike      267:   the document is generated from a system that cannot output the
1.123     mike      268:   shorter string.</p><h4 id="elements-0"><span class="secno">9.1.2 </span>Elements</h4><p>There are five different kinds of <dfn id="syntax-elements" title="syntax-elements">elements</dfn>: void elements, raw text
1.1       mike      269:   elements, RCDATA elements, foreign elements, and normal
1.123     mike      270:   elements.</p><dl><dt><dfn id="void-elements">Void elements</dfn></dt>
1.1       mike      271: 
                    272:    <dd><code><a href="the-canvas-element.html#the-area-element">area</a></code>, <code><a href="semantics.html#the-base-element">base</a></code>, <code><a href="semantics.html#the-br-element">br</a></code>,
1.159     mike      273:    <code><a href="tabular-data.html#the-col-element">col</a></code>, <code><a href="interactive-elements.html#the-command">command</a></code>, <code><a href="text-level-semantics.html#the-embed-element">embed</a></code>,
                    274:    <code><a href="semantics.html#the-hr-element">hr</a></code>, <code><a href="text-level-semantics.html#the-img-element">img</a></code>, <code><a href="forms.html#the-input-element">input</a></code>,
1.1       mike      275:    <code><a href="forms.html#the-keygen-element">keygen</a></code>, <code><a href="semantics.html#the-link-element">link</a></code>, <code><a href="semantics.html#meta">meta</a></code>,
1.159     mike      276:    <code><a href="text-level-semantics.html#the-param-element">param</a></code>, <code><a href="video.html#the-source-element">source</a></code></dd>
1.1       mike      277: 
1.91      mike      278:    <dt>Raw text elements</dt>
1.1       mike      279: 
                    280:    <dd><code><a href="semantics.html#script">script</a></code>, <code><a href="semantics.html#the-style-element">style</a></code></dd> <!-- iframe and
1.91      mike      281:    noscript don't count as raw text for syntax purposes -->
1.1       mike      282: 
                    283:    <dt>RCDATA elements</dt>
                    284: 
1.159     mike      285:    <dd><code><a href="forms.html#the-textarea-element">textarea</a></code>, <code><a href="semantics.html#the-title-element-0">title</a></code></dd>
1.1       mike      286: 
                    287:    <dt>Foreign elements</dt>
                    288: 
                    289:    <dd>Elements from the <a href="#mathml-namespace">MathML namespace</a>
                    290:    and the <a href="#svg-namespace">SVG namespace</a>.</dd>
                    291: 
                    292:    <dt>Normal elements</dt>
                    293: 
                    294:    <dd>All other allowed <a href="infrastructure.html#html-elements">HTML elements</a> are normal
                    295:    elements.</dd>
                    296: 
                    297:   </dl><p><dfn id="syntax-tags" title="syntax-tags">Tags</dfn> are used to delimit the start
1.91      mike      298:   and end of elements in the markup. Raw text, RCDATA, and normal
1.1       mike      299:   elements have a <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> to
                    300:   indicate where they begin, and an <a href="#syntax-end-tag" title="syntax-end-tag">end
                    301:   tag</a> to indicate where they end. The start and end tags of
                    302:   certain normal elements can be <a href="#syntax-tag-omission" title="syntax-tag-omission">omitted</a>, as described
                    303:   later. Those that cannot be omitted must not be omitted. <a href="#void-elements">Void
                    304:   elements</a> only have a start tag; end tags must not be
                    305:   specified for void elements. Foreign elements must either have a
                    306:   start tag and an end tag, or a start tag that is marked as
1.123     mike      307:   self-closing, in which case they must not have an end tag.</p><p>The contents of the element must be placed between just after the
1.1       mike      308:   start tag (which <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied,
                    309:   in certain cases</a>) and just before the end tag (which again,
                    310:   <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied in certain
                    311:   cases</a>). The exact allowed contents of each individual element
                    312:   depends on the content model of that element, as described earlier
                    313:   in this specification. Elements must not contain content that their
                    314:   content model disallows. In addition to the restrictions placed on
                    315:   the contents by those content models, however, the five types of
1.123     mike      316:   elements have additional <em>syntactic</em> requirements.</p><p><a href="#void-elements">Void elements</a> can't have any contents (since there's
1.1       mike      317:   no end tag, no content can be put between the start tag and the end
1.123     mike      318:   tag).</p><p>Raw text elements can have <a href="#syntax-text" title="syntax-text">text</a>,
1.1       mike      319:   though it has <a href="#cdata-rcdata-restrictions">restrictions</a>
1.123     mike      320:   described below.</p><p>RCDATA elements can have <a href="#syntax-text" title="syntax-text">text</a>
1.1       mike      321:   and <a href="#syntax-charref" title="syntax-charref">character references</a>, but
                    322:   the text must not contain an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>.
                    323:   There are also <a href="#cdata-rcdata-restrictions">further
1.123     mike      324:   restrictions</a> described below.</p><p>Foreign elements whose start tag is marked as self-closing can't
1.1       mike      325:   have any contents (since, again, as there's no end tag, no content
                    326:   can be put between the start tag and the end tag). Foreign elements
                    327:   whose start tag is <em>not</em> marked as self-closing can have
                    328:   <a href="#syntax-text" title="syntax-text">text</a>, <a href="#syntax-charref" title="syntax-charref">character references</a>, <a href="#syntax-cdata" title="syntax-cdata">CDATA sections</a>, other <a href="#syntax-elements" title="syntax-elements">elements</a>, and <a href="#syntax-comments" title="syntax-comments">comments</a>, but the text must not
                    329:   contain the character U+003C LESS-THAN SIGN (<code>&lt;</code>) or
                    330:   an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
1.123     mike      331:   ampersand</a>.</p><p>Normal elements can have <a href="#syntax-text" title="syntax-text">text</a>,
1.1       mike      332:   <a href="#syntax-charref" title="syntax-charref">character references</a>, other
                    333:   <a href="#syntax-elements" title="syntax-elements">elements</a>, and <a href="#syntax-comments" title="syntax-comments">comments</a>, but the text must not
                    334:   contain the character U+003C LESS-THAN SIGN (<code>&lt;</code>) or
                    335:   an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
                    336:   ampersand</a>. Some normal elements also have <a href="#element-restrictions">yet more restrictions</a> on what
                    337:   content they are allowed to hold, beyond the restrictions imposed by
                    338:   the content model and those described in this paragraph. Those
1.123     mike      339:   restrictions are described below.</p><p>Tags contain a <dfn id="syntax-tag-name" title="syntax-tag-name">tag name</dfn>,
1.1       mike      340:   giving the element's name. HTML elements all have names that only
                    341:   use characters in the range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE,
                    342:   U+0061 LATIN SMALL LETTER A .. U+007A LATIN SMALL LETTER Z, U+0041
                    343:   LATIN CAPITAL LETTER A .. U+005A LATIN CAPITAL LETTER Z, and U+002D
                    344:   HYPHEN-MINUS (<code>-</code>). In the HTML syntax, tag names may be
                    345:   written with any mix of lower- and uppercase letters that, when
                    346:   converted to all-lowercase, matches the element's tag name; tag
1.123     mike      347:   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
                    348:   following format:</p><ol><li>The first character of a start tag must be a U+003C LESS-THAN
1.1       mike      349:    SIGN (<code>&lt;</code>).</li>
                    350: 
                    351:    <li>The next few characters of a start tag must be the element's
                    352:    <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
                    353: 
                    354:    <li>If there are to be any attributes in the next step, there must
                    355:    first be one or more <a href="infrastructure.html#space-character" title="space character">space
                    356:    characters</a>.</li>
                    357: 
                    358:    <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
                    359:    below. Attributes may be separated from each other by one or more
                    360:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    361: 
                    362:    <li>After the attributes, there may be one or more <a href="infrastructure.html#space-character" title="space character">space characters</a>. (Some attributes
                    363:    are required to be followed by a space. See the <a href="#syntax-attributes" title="syntax-attributes">attributes section</a> below.)</li>
                    364: 
                    365:    <li>Then, if the element is one of the <a href="#void-elements">void elements</a>,
                    366:    or if the element is a foreign element, then there may be a single
                    367:    U+002F SOLIDUS (<code>/</code>) character. This character has no
                    368:    effect on void elements, but on foreign elements it marks the start
                    369:    tag as self-closing.</li>
                    370: 
                    371:    <li>Finally, start tags must be closed by a U+003E GREATER-THAN
                    372:    SIGN (<code>&gt;</code>) character.</li>
                    373: 
1.123     mike      374:   </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
                    375:   following format:</p><ol><li>The first character of an end tag must be a U+003C LESS-THAN
1.1       mike      376:    SIGN (<code>&lt;</code>).</li>
                    377: 
                    378:    <li>The second character of an end tag must be a U+002F SOLIDUS
                    379:    (<code>/</code>).</li>
                    380: 
                    381:    <li>The next few characters of an end tag must be the element's
                    382:    <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
                    383: 
                    384:    <li>After the tag name, there may be one or more <a href="infrastructure.html#space-character" title="space
                    385:    character">space characters</a>.</li>
                    386: 
                    387:    <li>Finally, end tags must be closed by a U+003E GREATER-THAN
                    388:    SIGN (<code>&gt;</code>) character.</li>
                    389: 
1.123     mike      390:   </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
                    391:   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      392:   one or more characters other than the <a href="infrastructure.html#space-character" title="space
                    393:   character">space characters</a>, U+0000 NULL, U+0022 QUOTATION
                    394:   MARK ("), U+0027 APOSTROPHE ('), U+003E GREATER-THAN SIGN
                    395:   (&gt;), U+002F SOLIDUS (/), and U+003D EQUALS SIGN (=) characters,
                    396:   the control characters, and any characters that are not defined by
                    397:   Unicode. In the HTML syntax, attribute names may be written with any
                    398:   mix of lower- and uppercase letters that are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.123     mike      399:   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      400:   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      401:   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      402: 
                    403:    <dd>
                    404: 
                    405:     <p>Just the <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute
                    406:     name</a>.</p>
                    407: 
                    408:     <div class="example">
                    409: 
                    410:      <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
                    411:      the empty attribute syntax:</p>
                    412: 
                    413:      <pre>&lt;input <em>disabled</em>&gt;</pre>
                    414: 
                    415:     </div>
                    416: 
                    417:     <p>If an attribute using the empty attribute syntax is to be
                    418:     followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
                    419:     character</a> separating the two.</p>
                    420: 
                    421:    </dd>
                    422: 
1.2       mike      423:    <dt id="unquoted">Unquoted attribute value syntax</dt>
1.1       mike      424: 
                    425:    <dd>
                    426: 
                    427:     <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
                    428:     followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
                    429:     characters</a>, followed by a single U+003D EQUALS SIGN
                    430:     character, followed by zero or more <a href="infrastructure.html#space-character" title="space
                    431:     character">space characters</a>, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
                    432:     addition to the requirements given above for attribute values,
                    433:     must not contain any literal <a href="infrastructure.html#space-character" title="space character">space
                    434:     characters</a>, any U+0022 QUOTATION MARK (<code>"</code>)
                    435:     characters, U+0027 APOSTROPHE (<code>'</code>) characters,
                    436:     U+003D EQUALS SIGN (<code>=</code>) characters, U+003C LESS-THAN
                    437:     SIGN (<code>&lt;</code>) characters, or U+003E GREATER-THAN SIGN
                    438:     (<code>&gt;</code>) characters, and must not be the empty
                    439:     string.</p>
                    440: 
                    441:     <div class="example">
                    442: 
                    443:      <p>In the following example, the <code title="attr-input-value"><a href="forms.html#attr-input-value">value</a></code> attribute is given
                    444:      with the unquoted attribute value syntax:</p>
                    445: 
                    446:      <pre>&lt;input <em>value=yes</em>&gt;</pre>
                    447: 
                    448:     </div>
                    449: 
                    450:     <p>If an attribute using the unquoted attribute syntax is to be
1.101     mike      451:     followed by another attribute or by the optional U+002F SOLIDUS
                    452:     (<code>/</code>) character allowed in step 6 of the <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> syntax above, then there
1.1       mike      453:     must be a <a href="infrastructure.html#space-character">space character</a> separating the two.</p>
                    454: 
                    455:    </dd>
                    456: 
                    457:    <dt>Single-quoted attribute value syntax</dt>
                    458: 
                    459:    <dd>
                    460: 
                    461:     <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
                    462:     followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
                    463:     characters</a>, followed by a single U+003D EQUALS SIGN
                    464:     character, followed by zero or more <a href="infrastructure.html#space-character" title="space
                    465:     character">space characters</a>, followed by a single U+0027
                    466:     APOSTROPHE (<code>'</code>) character, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
                    467:     addition to the requirements given above for attribute values,
                    468:     must not contain any literal U+0027 APOSTROPHE (<code>'</code>)
                    469:     characters, and finally followed by a second single U+0027
                    470:     APOSTROPHE (<code>'</code>) character.</p>
                    471: 
                    472:     <div class="example">
                    473: 
                    474:      <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
                    475:      single-quoted attribute value syntax:</p>
                    476: 
                    477:      <pre>&lt;input <em>type='checkbox'</em>&gt;</pre>
                    478: 
                    479:     </div>
                    480: 
                    481:     <p>If an attribute using the single-quoted attribute syntax is to
                    482:     be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
                    483:     character</a> separating the two.</p>
                    484: 
                    485:    </dd>
                    486: 
                    487:    <dt>Double-quoted attribute value syntax</dt>
                    488: 
                    489:    <dd>
                    490: 
                    491:     <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
                    492:     followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
                    493:     characters</a>, followed by a single U+003D EQUALS SIGN
                    494:     character, followed by zero or more <a href="infrastructure.html#space-character" title="space
                    495:     character">space characters</a>, followed by a single U+0022
                    496:     QUOTATION MARK (<code>"</code>) character, 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 U+0022 QUOTATION MARK
                    499:     (<code>"</code>) characters, and finally followed by a second
                    500:     single U+0022 QUOTATION MARK (<code>"</code>) character.</p>
                    501: 
                    502:     <div class="example">
                    503: 
                    504:      <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
                    505:      double-quoted attribute value syntax:</p>
                    506: 
                    507:      <pre>&lt;input <em>name="be evil"</em>&gt;</pre>
                    508: 
                    509:     </div>
                    510: 
                    511:     <p>If an attribute using the double-quoted attribute syntax is to
                    512:     be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
                    513:     character</a> separating the two.</p>
                    514: 
                    515:    </dd>
                    516: 
                    517:   </dl><p>There must never be two or more attributes on the same start tag
                    518:   whose names are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for
1.123     mike      519:   each other.</p><h5 id="optional-tags"><span class="secno">9.1.2.4 </span>Optional tags</h5><p>Certain tags can be <dfn id="syntax-tag-omission" title="syntax-tag-omission">omitted</dfn>.</p><p class="note">Omitting an element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> does not mean the element
1.1       mike      520:   is not present; it is implied, but it is still there. An HTML
1.159     mike      521:   document always has a root <code><a href="semantics.html#the-html-element-0">html</a></code> element, even if the
1.1       mike      522:   string <code title="">&lt;html&gt;</code> doesn't appear anywhere in
1.159     mike      523:   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
                    524:   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
                    525:   tag</a> may be omitted if the <code><a href="semantics.html#the-html-element-0">html</a></code> element is not
                    526:   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      527:   element is empty, or--> if the first thing inside the
1.159     mike      528:   <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
                    529:   tag</a> may be omitted if the <code><a href="semantics.html#the-head-element-0">head</a></code> element is not
                    530:   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
                    531:   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      532:   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      533:   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      534:   <code><a href="semantics.html#the-style-element">style</a></code> element. <!-- Note that even if the </head> end
                    535:   tag is present, the parser makes <style> and <script> elements
                    536:   between </head> and <body> end up in the <head> instead of implying
1.159     mike      537:   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
                    538:   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      539:   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      540:   tag</a> may be omitted if the <code><a href="semantics.html#the-li-element">li</a></code> element is
                    541:   immediately followed by another <code><a href="semantics.html#the-li-element">li</a></code> element or if there
1.123     mike      542:   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      543:   tag</a> may be omitted if the <code><a href="semantics.html#the-dt-element">dt</a></code> element is
                    544:   immediately followed by another <code><a href="semantics.html#the-dt-element">dt</a></code> element or a
1.123     mike      545:   <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      546:   tag</a> may be omitted if the <code><a href="semantics.html#the-dd-element">dd</a></code> element is
                    547:   immediately followed by another <code><a href="semantics.html#the-dd-element">dd</a></code> element or a
                    548:   <code><a href="semantics.html#the-dt-element">dt</a></code> element, or if there is no more content in the
1.123     mike      549:   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      550:   tag</a> may be omitted if the <code><a href="semantics.html#the-p-element">p</a></code> element is
                    551:   immediately followed by an <code><a href="semantics.html#the-address-element">address</a></code>,
                    552:   <code><a href="semantics.html#the-article-element">article</a></code>, <code><a href="semantics.html#the-aside-element">aside</a></code>, <code><a href="semantics.html#the-blockquote-element">blockquote</a></code>,
1.86      mike      553:   <!--v2DATAGRID <code>datagrid</code>,--> <code><a href="semantics.html#the-dialog-element">dialog</a></code>,
                    554:   <code><a href="obsolete.html#dir">dir</a></code>, <code><a href="interactive-elements.html#the-div-element">div</a></code>, <code><a href="semantics.html#the-dl-element">dl</a></code>,
                    555:   <code><a href="forms.html#the-fieldset-element">fieldset</a></code>, <code><a href="semantics.html#the-footer-element">footer</a></code>, <code><a href="forms.html#the-form-element">form</a></code>,
                    556:   <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h1</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h2</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h3</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h4</a></code>,
                    557:   <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h5</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h6</a></code>, <code><a href="semantics.html#the-header-element">header</a></code>,
                    558:   <code><a href="semantics.html#the-hgroup-element">hgroup</a></code>, <code><a href="semantics.html#the-hr-element">hr</a></code>, <code><a href="interactive-elements.html#menus">menu</a></code>,
                    559:   <code><a href="semantics.html#the-nav-element">nav</a></code>, <code><a href="semantics.html#the-ol-element">ol</a></code>, <code><a href="semantics.html#the-p-element">p</a></code>, <code><a href="semantics.html#the-pre-element">pre</a></code>,
1.1       mike      560:   <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>,
                    561:   element, or if there is no more content in the parent element and
1.123     mike      562:   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      563:   tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element is
                    564:   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      565:   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      566:   tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element is
                    567:   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      568:   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      569:   <select>; commented out text below can handle the non-<select> case
1.123     mike      570:   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      571:   <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element <!--has an ancestor
                    572:   <code>select</code> element and--> is immediately followed by
                    573:   another <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or if <!--all of the elements
                    574:   that are ancestors of the <code>optgroup</code> element, up to and
                    575:   including the first ancestor element that is not an
                    576:   <code>optgroup</code> element, have no more content--> there is no
1.123     mike      577:   more content in the parent element.</p><!-- so e.g. the max number of </optgroup>s are omitted here:
1.1       mike      578:    <select><optgroup></select>
                    579:    <p id=x><optgroup></optgroup>x</p>
                    580:    <p id=x><optgroup><optgroup></optgroup></optgroup>x</p>
                    581:    <p><optgroup id=x><optgroup></optgroup>x</p>
                    582:    <p><optgroup><optgroup id=x>x</p>
1.123     mike      583:   --><!-- </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      584:   tag</a> may be omitted if the <code><a href="forms.html#the-option-element">option</a></code> element is
                    585:   immediately followed by another <code><a href="forms.html#the-option-element">option</a></code> element, or if
                    586:   it is immediately followed by an <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or
1.123     mike      587:   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      588:   first thing inside the <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is a
                    589:   <code><a href="tabular-data.html#the-col-element">col</a></code> element, and if the element is not immediately
                    590:   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      591:   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      592:   <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is not immediately followed by a
1.123     mike      593:   <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      594:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-thead-element">thead</a></code> element is
                    595:   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      596:   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      597:   first thing inside the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is a
                    598:   <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, and if the element is not immediately
                    599:   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
                    600:   <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element whose <a href="#syntax-end-tag" title="syntax-end-tag">end
                    601:   tag</a> has been omitted. (It can't be omitted if the element is
1.123     mike      602:   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      603:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is
                    604:   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      605:   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      606:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element is
                    607:   immediately followed by a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element, or if there is
1.123     mike      608:   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      609:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
                    610:   immediately followed by another <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, or if there
1.123     mike      611:   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      612:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-td-element">td</a></code> element is
                    613:   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      614:   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      615:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-th-element">th</a></code> element is
                    616:   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      617:   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
                    618:   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
                    619:   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      620:   elements, even though these elements are technically allowed inside
                    621:   <code><a href="tabular-data.html#the-table-element">table</a></code> elements according to the content models
                    622:   described in this specification. (If a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
                    623:   put inside a <code><a href="tabular-data.html#the-table-element">table</a></code> in the markup, it will in fact imply
1.123     mike      624:   a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> start tag before it.)</p><p>A single U+000A LINE FEED (LF) character may be placed
1.1       mike      625:   immediately after the <a href="#syntax-start-tag" title="syntax-start-tag">start
                    626:   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>
                    627:   elements. This does not affect the processing of the element. The
                    628:   otherwise optional U+000A LINE FEED (LF) character <em>must</em> be
                    629:   included if the element's contents start with that character
                    630:   (because otherwise the leading newline in the contents would be
1.123     mike      631:   treated like the optional newline, and ignored).</p><div class="example">
1.1       mike      632:    <p>The following two <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are equivalent:</p>
                    633:    <pre>&lt;pre&gt;Hello&lt;/pre&gt;</pre>
                    634:    <pre>&lt;pre&gt;<br>Hello&lt;/pre&gt;</pre>
1.123     mike      635:   </div><h5 id="cdata-rcdata-restrictions"><span class="secno">9.1.2.6 </span>Restrictions on the contents of raw text and RCDATA elements</h5><p>The text in raw text and RCDATA elements must not contain any
1.1       mike      636:   occurrences of the string "<code title="">&lt;/</code>" (U+003C
                    637:   LESS-THAN SIGN, U+002F SOLIDUS) followed by characters that
                    638:   case-insensitively match the tag name of the element followed by one
                    639:   of U+0009 CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM
                    640:   FEED (FF), U+0020 SPACE, U+003E GREATER-THAN SIGN (&gt;), or U+002F
1.123     mike      641:   SOLIDUS (/), unless that string is part of an <a href="#syntax-escape" title="syntax-escape">escaping text span</a>.</p><p>An <dfn id="syntax-escape" title="syntax-escape">escaping text span</dfn> is a span
1.1       mike      642:   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
                    643:   not itself in an <a href="#syntax-escape" title="syntax-escape">escaping text
                    644:   span</a>, and ends at the next <a href="#syntax-escape-end" title="syntax-escape-end">escaping text span end</a>. There
                    645:   cannot be any <a href="#syntax-charref" title="syntax-charref">character
                    646:   references</a> inside an <a href="#syntax-escape" title="syntax-escape">escaping
                    647:   text span</a> &#8212; sequences of characters that would look
                    648:   like <a href="#syntax-charref" title="syntax-charref">character references</a> do not
1.123     mike      649:   have special meaning.</p><p>An <dfn id="syntax-escape-start" title="syntax-escape-start">escaping text span
1.1       mike      650:   start</dfn> is a part of <a href="#syntax-text" title="syntax-text">text</a> that
                    651:   consists of the four character sequence "<code title="">&lt;!--</code>" (U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
1.123     mike      652:   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      653:   a part of <a href="#syntax-text" title="syntax-text">text</a> that consists of the
                    654:   three character sequence "<code title="">--&gt;</code>" (U+002D
1.134     mike      655:   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      656:   start</a> may share its U+002D HYPHEN-MINUS characters with its
                    657:   corresponding <a href="#syntax-escape-end" title="syntax-escape-end">escaping text span
1.123     mike      658:   end</a>.</p><p>The text in raw text elements and RCDATA elements must not have
1.91      mike      659:   an <a href="#syntax-escape-start" title="syntax-escape-start">escaping text span start</a>
                    660:   that is not followed by an <a href="#syntax-escape-end" title="syntax-escape-end">escaping
1.123     mike      661:   text span end</a>.</p><h4 id="text-0"><span class="secno">9.1.3 </span>Text</h4><p><dfn id="syntax-text" title="syntax-text">Text</dfn> is allowed inside elements,
1.1       mike      662:   attributes, and comments. Text must consist of Unicode characters.
                    663:   Text must not contain U+0000 characters. Text must not contain
                    664:   permanently undefined Unicode characters. Text must not contain
                    665:   control characters other than <a href="infrastructure.html#space-character" title="space character">space
                    666:   characters</a>. Extra constraints are placed on what is and what
                    667:   is not allowed in text based on where the text is to be put, as
1.123     mike      668:   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      669:   represented either as U+000D CARRIAGE RETURN (CR) characters, U+000A
                    670:   LINE FEED (LF) characters, or pairs of U+000D CARRIAGE RETURN (CR),
1.123     mike      671:   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      672:   to escape characters that couldn't otherwise legally be included in
1.123     mike      673:   <a href="#syntax-text" title="syntax-text">text</a>.</p><p>Character references must start with a U+0026 AMPERSAND
1.1       mike      674:   (<code>&amp;</code>). Following this, there are three possible kinds
1.123     mike      675:   of character references:</p><dl><dt>Named character references</dt>
1.1       mike      676: 
                    677:    <dd>The ampersand must be followed by one of the names given in the
                    678:    <a href="named-character-references.html#named-character-references">named character references</a> section, using the same
                    679:    case. The name must be one that is terminated by a U+003B SEMICOLON
                    680:    (<code title="">;</code>) character.</dd>
                    681: 
                    682: 
                    683:    <dt>Decimal numeric character reference</dt>
                    684: 
                    685:    <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
                    686:    (<code>#</code>) character, followed by one or more digits in the
                    687:    range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE, representing a
                    688:    base-ten integer that itself is a Unicode code point that is
                    689:    not U+0000, U+000D, in the range U+0080 .. U+009F, or in the range
                    690:    0xD800 .. 0xDFFF (surrogates). The digits must then be followed by
                    691:    a U+003B SEMICOLON character (<code title="">;</code>).</dd>
                    692: 
                    693: 
                    694:    <dt>Hexadecimal numeric character reference</dt>
                    695: 
                    696:    <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
                    697:    (<code>#</code>) character, which must be followed by either a
                    698:    U+0078 LATIN SMALL LETTER X or a U+0058 LATIN CAPITAL LETTER X
                    699:    character, which must then be followed by one or more digits in the
                    700:    range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE, U+0061 LATIN SMALL
                    701:    LETTER A .. U+0066 LATIN SMALL LETTER F, and U+0041 LATIN CAPITAL
                    702:    LETTER A .. U+0046 LATIN CAPITAL LETTER F, representing a
                    703:    base-sixteen integer that itself is a Unicode code point that is
                    704:    not U+0000, U+000D, in the range U+0080 .. U+009F, or in the range
                    705:    0xD800 .. 0xDFFF (surrogates). The digits must then be followed by
                    706:    a U+003B SEMICOLON character (<code title="">;</code>).</dd>
                    707: 
                    708:   </dl><p>An <dfn id="syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
                    709:   ampersand</dfn> is a U+0026 AMPERSAND (<code>&amp;</code>) character
                    710:   that is followed by some <a href="#syntax-text" title="syntax-text">text</a> other
                    711:   than a <a href="infrastructure.html#space-character">space character</a>, a U+003C LESS-THAN SIGN
                    712:   character ('&lt;'), or another U+0026 AMPERSAND (<code>&amp;</code>)
1.123     mike      713:   character.</p><h4 id="cdata-sections"><span class="secno">9.1.5 </span>CDATA sections</h4><p><dfn id="syntax-cdata" title="syntax-cdata">CDATA sections</dfn> must start with
1.1       mike      714:   the character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
                    715:   MARK, U+005B LEFT SQUARE BRACKET, U+0043 LATIN CAPITAL LETTER C,
                    716:   U+0044 LATIN CAPITAL LETTER D, U+0041 LATIN CAPITAL LETTER A, U+0054
                    717:   LATIN CAPITAL LETTER T, U+0041 LATIN CAPITAL LETTER A, U+005B LEFT
                    718:   SQUARE BRACKET (<code title="">&lt;![CDATA[</code>). Following this
                    719:   sequence, the CDATA section may have <a href="#syntax-text" title="syntax-text">text</a>, with the additional restriction
                    720:   that the text must not contain the three character sequence U+005D
                    721:   RIGHT SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E
                    722:   GREATER-THAN SIGN (<code title="">]]&gt;</code>). Finally, the CDATA
                    723:   section must be ended by the three character sequence U+005D RIGHT
                    724:   SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E GREATER-THAN
1.159     mike      725:   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      726:   four character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
                    727:   MARK, U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS (<code title="">&lt;!--</code>). Following this sequence, the comment may
                    728:   have <a href="#syntax-text" title="syntax-text">text</a>, with the additional
                    729:   restriction that the text must not start with a single U+003E
                    730:   GREATER-THAN SIGN ('&gt;') character, nor start with a U+002D
                    731:   HYPHEN-MINUS (<code title="">-</code>) character followed by a
                    732:   U+003E GREATER-THAN SIGN ('&gt;') character, nor contain two
                    733:   consecutive U+002D HYPHEN-MINUS (<code title="">-</code>)
                    734:   characters, nor end with a U+002D HYPHEN-MINUS (<code title="">-</code>) character. Finally, the comment must be ended by
                    735:   the three character sequence U+002D HYPHEN-MINUS, U+002D
1.123     mike      736:   HYPHEN-MINUS, U+003E GREATER-THAN SIGN (<code title="">--&gt;</code>).</p><div class="impl">
1.1       mike      737: 
1.159     mike      738:   <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      739: 
                    740:   <p><i>This section only applies to user agents, data mining tools,
                    741:   and conformance checkers.</i></p>
                    742: 
                    743:   <p class="note">The rules for parsing XML documents into DOM trees
                    744:   are covered by the next section, entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
                    745:   syntax</a>".</p>
                    746: 
                    747:   <p>For <a href="dom.html#html-documents">HTML documents</a>, user agents must use the parsing
                    748:   rules described in this section to generate the DOM trees. Together,
                    749:   these rules define what is referred to as the <dfn id="html-parser">HTML
                    750:   parser</dfn>.</p>
                    751: 
                    752:   <div class="note">
                    753: 
                    754:    <p>While the HTML syntax described in this specification bears a
                    755:    close resemblance to SGML and XML, it is a separate language with
                    756:    its own parsing rules.</p>
                    757: 
1.183     mike      758:    <p>Some earlier versions of HTML (in particular from HTML2 to
                    759:    HTML4) were based on SGML and used SGML parsing rules. However, few
1.1       mike      760:    (if any) web browsers ever implemented true SGML parsing for HTML
                    761:    documents; the only user agents to strictly handle HTML as an SGML
                    762:    application have historically been validators. The resulting
                    763:    confusion &#8212; with validators claiming documents to have one
                    764:    representation while widely deployed Web browsers interoperably
                    765:    implemented a different representation &#8212; has wasted decades
                    766:    of productivity. This version of HTML thus returns to a non-SGML
                    767:    basis.</p>
                    768: 
                    769:    <p>Authors interested in using SGML tools in their authoring
                    770:    pipeline are encouraged to use XML tools and the XML serialization
                    771:    of HTML.</p>
                    772: 
                    773:   </div>
                    774: 
                    775:   <p>This specification defines the parsing rules for HTML documents,
                    776:   whether they are syntactically correct or not. Certain points in the
                    777:   parsing algorithm are said to be <dfn id="parse-error" title="parse error">parse
                    778:   errors</dfn>. The error handling for parse errors is well-defined:
                    779:   user agents must either act as described below when encountering
                    780:   such problems, or must abort processing at the first error that they
                    781:   encounter for which they do not wish to apply the rules described
                    782:   below.</p>
                    783: 
                    784:   <p>Conformance checkers must report at least one parse error
                    785:   condition to the user if one or more parse error conditions exist in
                    786:   the document and must not report parse error conditions if none
                    787:   exist in the document. Conformance checkers may report more than one
1.174     mike      788:   parse error condition if more than one parse error condition exists
1.1       mike      789:   in the document. Conformance checkers are not required to recover
                    790:   from parse errors.</p>
                    791: 
                    792:   <p class="note">Parse errors are only errors with the
                    793:   <em>syntax</em> of HTML. In addition to checking for parse errors,
                    794:   conformance checkers will also verify that the document obeys all
                    795:   the other conformance requirements described in this
                    796:   specification.</p>
                    797: 
                    798:   <p>For the purposes of conformance checkers, if a resource is
                    799:   determined to be in <a href="#syntax">the HTML syntax</a>, then it is an
                    800:   <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
                    801: 
                    802: 
                    803:   <h4 id="overview-of-the-parsing-model"><span class="secno">9.2.1 </span>Overview of the parsing model</h4>
                    804: 
                    805:   <p>The input to the HTML parsing process consists of a stream of
                    806:   Unicode characters, which is passed through a
                    807:   <a href="#tokenization">tokenization</a> stage followed by a <a href="#tree-construction">tree
                    808:   construction</a> stage. The output is a <code>Document</code>
                    809:   object.</p>
                    810: 
                    811:   <p class="note">Implementations that <a href="infrastructure.html#non-scripted">do not
                    812:   support scripting</a> do not have to actually create a DOM
                    813:   <code>Document</code> object, but the DOM tree in such cases is
                    814:   still used as the model for the rest of the specification.</p>
                    815: 
                    816:   <p>In the common case, the data handled by the tokenization stage
1.159     mike      817:   comes from the network, but <a href="embedded-content-0.html#dynamic-markup-insertion" title="dynamic markup
                    818:   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      819: 
                    820:   <p><img alt="" src="images/parsing-model-overview.png"></p>
                    821: 
                    822:   <p id="nestedParsing">There is only one set of states for the
                    823:   tokenizer stage and the tree construction stage, but the tree
                    824:   construction stage is reentrant, meaning that while the tree
                    825:   construction stage is handling one token, the tokenizer might be
                    826:   resumed, causing further tokens to be emitted and processed before
                    827:   the first token's processing is complete.</p>
                    828: 
                    829:   <div class="example">
                    830: 
                    831:    <p>In the following example, the tree construction stage will be
                    832:    called upon to handle a "p" start tag token while handling the
                    833:    "script" start tag token:</p>
                    834: 
                    835:    <pre>...
                    836: &lt;script&gt;
                    837:  document.write('&lt;p&gt;');
                    838: &lt;/script&gt;
                    839: ...</pre>
                    840: 
                    841:   </div>
                    842: 
                    843:   <p>To handle these cases, parsers have a <dfn id="script-nesting-level">script nesting
                    844:   level</dfn>, which must be initially set to zero, and a <dfn id="parser-pause-flag">parser
                    845:   pause flag</dfn>, which must be initially set to false.</p>
                    846: 
                    847: 
                    848: 
                    849:   <h4 id="the-input-stream"><span class="secno">9.2.2 </span>The <dfn>input stream</dfn></h4>
                    850: 
                    851:   <p>The stream of Unicode characters that comprises the input to the
                    852:   tokenization stage will be initially seen by the user agent as a
                    853:   stream of bytes (typically coming over the network or from the local
                    854:   file system). The bytes encode the actual characters according to a
                    855:   particular <em>character encoding</em>, which the user agent must
                    856:   use to decode the bytes into characters.</p>
                    857: 
                    858:   <p class="note">For XML documents, the algorithm user agents must
                    859:   use to determine the character encoding is given by the XML
1.104     mike      860:   specification. This section does not apply to XML documents. <a href="references.html#refsXML">[XML]</a></p>
1.1       mike      861: 
                    862: 
1.168     mike      863:   <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      864: 
                    865:   <p>In some cases, it might be impractical to unambiguously determine
                    866:   the encoding before parsing the document. Because of this, this
                    867:   specification provides for a two-pass mechanism with an optional
                    868:   pre-scan. Implementations are allowed, as described below, to apply
                    869:   a simplified parsing algorithm to whatever bytes they have available
                    870:   before beginning to parse the document. Then, the real parser is
                    871:   started, using a tentative encoding derived from this pre-parse and
                    872:   other out-of-band metadata. If, while the document is being loaded,
                    873:   the user agent discovers an encoding declaration that conflicts with
                    874:   this information, then the parser can get reinvoked to perform a
                    875:   parse of the document with the real encoding.</p>
                    876: 
                    877:   <p id="documentEncoding">User agents must use the following
                    878:   algorithm (the <dfn id="encoding-sniffing-algorithm">encoding sniffing algorithm</dfn>) to determine
                    879:   the character encoding to use when decoding a document in the first
                    880:   pass. This algorithm takes as input any out-of-band metadata
                    881:   available to the user agent (e.g. the <a href="infrastructure.html#content-type" title="Content-Type">Content-Type metadata</a> of the document)
                    882:   and all the bytes available so far, and returns an encoding and a
                    883:   <dfn id="concept-encoding-confidence" title="concept-encoding-confidence">confidence</dfn>. The
                    884:   confidence is either <i>tentative</i>, <i>certain</i>, or
                    885:   <i>irrelevant</i>. The encoding used, and whether the confidence in
                    886:   that encoding is <i>tentative</i> or <i>certain</i>, is <a href="#meta-charset-during-parse">used during the parsing</a> to
                    887:   determine whether to <a href="#change-the-encoding">change the encoding</a>. If no
                    888:   encoding is necessary, e.g. because the parser is operating on a
                    889:   stream of Unicode characters and doesn't have to use an encoding at
                    890:   all, then the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                    891:   <i>irrelevant</i>.</p>
                    892: 
                    893:   <ol><li><p>If the transport layer specifies an encoding, and it is
                    894:    supported, return that encoding with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                    895:    <i>certain</i>, and abort these steps.</p></li>
                    896: 
                    897:    <li><p>The user agent may wait for more bytes of the resource to be
                    898:    available, either in this step or at any later step in this
                    899:    algorithm. For instance, a user agent might wait 500ms or 512
                    900:    bytes, whichever came first. In general preparsing the source to
                    901:    find the encoding improves performance, as it reduces the need to
                    902:    throw away the data structures used when parsing upon finding the
                    903:    encoding information. However, if the user agent delays too long to
                    904:    obtain data to determine the encoding, then the cost of the delay
                    905:    could outweigh any performance improvements from the
                    906:    preparse.</p></li>
                    907: 
                    908:    <li><p>For each of the rows in the following table, starting with
                    909:    the first one and going down, if there are as many or more bytes
                    910:    available than the number of bytes in the first column, and the
                    911:    first bytes of the file match the bytes given in the first column,
                    912:    then return the encoding given in the cell in the second column of
                    913:    that row, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                    914:    <i>certain</i>, and abort these steps:</p>
                    915: 
                    916:     <!-- this table is present in several forms in this file; keep them in sync -->
                    917:     <table><thead><tr><th>Bytes in Hexadecimal
                    918:        </th><th>Encoding
                    919:      </th></tr></thead><tbody><!-- nobody uses this
                    920:       <tr>
                    921:        <td>00 00 FE FF
                    922:        <td>UTF-32BE
                    923:       <tr>
                    924:        <td>FF FE 00 00
                    925:        <td>UTF-32LE
                    926: --><tr><td>FE FF
                    927:        </td><td>UTF-16BE
                    928:       </td></tr><tr><td>FF FE
                    929:        </td><td>UTF-16LE
                    930:       </td></tr><tr><td>EF BB BF
                    931:        </td><td>UTF-8
                    932: <!-- nobody uses this
                    933:       <tr>
                    934:        <td>DD 73 66 73
                    935:        <td>UTF-EBCDIC
                    936: -->
                    937:     </td></tr></tbody></table><p class="note">This step looks for Unicode Byte Order Marks
                    938:    (BOMs).</p></li>
                    939: 
                    940:    <li><p>Otherwise, the user agent will have to search for explicit
                    941:    character encoding information in the file itself. This should
                    942:    proceed as follows:
                    943: 
                    944:     </p><p>Let <var title="">position</var> be a pointer to a byte in the
                    945:     input stream, initially pointing at the first byte. If at any
                    946:     point during these substeps the user agent either runs out of
                    947:     bytes or decides that scanning further bytes would not be
                    948:     efficient, then skip to the next step of the overall character
                    949:     encoding detection algorithm. User agents may decide that scanning
                    950:     <em>any</em> bytes is not efficient, in which case these substeps
                    951:     are entirely skipped.</p>
                    952: 
                    953:     <p>Now, repeat the following "two" steps until the algorithm
                    954:     aborts (either because user agent aborts, as described above, or
                    955:     because a character encoding is found):</p>
                    956: 
                    957:     <ol><li><p>If <var title="">position</var> points to:</p>
                    958: 
                    959:       <dl class="switch"><dt>A sequence of bytes starting with: 0x3C 0x21 0x2D 0x2D (ASCII '&lt;!--')</dt>
                    960:        <dd>
                    961: 
                    962:         <p>Advance the <var title="">position</var> pointer so that it
                    963:         points at the first 0x3E byte which is preceded by two 0x2D
                    964:         bytes (i.e. at the end of an ASCII '--&gt;' sequence) and comes
                    965:         after the 0x3C byte that was found. (The two 0x2D bytes can be
                    966:         the same as the those in the '&lt;!--' sequence.)</p>
                    967: 
                    968:        </dd>
                    969: 
                    970:        <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>
                    971:        <dd>
                    972: 
                    973:         <ol><li><p>Advance the <var title="">position</var> pointer so
                    974:          that it points at the next 0x09, 0x0A, 0x0C, 0x0D, 0x20, or
                    975:          0x2F byte (the one in sequence of characters matched
                    976:          above).</p></li>
                    977: 
                    978:          <li><p><a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">Get
                    979:          an attribute</a> and its value. If no attribute was
                    980:          sniffed, then skip this inner set of steps, and jump to the
                    981:          second step in the overall "two step" algorithm.</p></li>
                    982: 
                    983:          <li><p>If the attribute's name is neither "<code title="">charset</code>" nor "<code title="">content</code>",
                    984:          then return to step 2 in these inner steps.</p></li>
                    985: 
                    986:          <li><p>If the attribute's name is "<code title="">charset</code>", let <var title="">charset</var> be
                    987:          the attribute's value, interpreted as a character
                    988:          encoding.</p></li>
                    989: 
                    990:          <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
                    991:          extracting an encoding from a Content-Type</a>, giving the
                    992:          attribute's value as the string to parse. If an encoding is
                    993:          returned, let <var title="">charset</var> be that
                    994:          encoding. Otherwise, return to step 2 in these inner
                    995:          steps.</p></li>
                    996: 
                    997:          <li><p>If <var title="">charset</var> is a UTF-16 encoding,
                    998:          change the value of <var title="">charset</var> to
                    999:          UTF-8.</p></li>
                   1000: 
                   1001:          <li><p>If <var title="">charset</var> is a supported
                   1002:          character encoding, then return the given encoding, with
                   1003:          <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1004:          <i>tentative</i>, and abort all these steps.</p></li>
                   1005: 
                   1006:          <li><p>Otherwise, return to step 2 in these inner
                   1007:          steps.</p></li>
                   1008: 
                   1009:         </ol></dd>
                   1010: 
                   1011:        <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>
                   1012:        <dd>
                   1013: 
                   1014:         <ol><li><p>Advance the <var title="">position</var> pointer so
                   1015:          that it points at the next 0x09 (ASCII TAB), 0x0A (ASCII LF),
                   1016:          0x0C (ASCII FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E
                   1017:          (ASCII '&gt;') byte.</p></li>
                   1018: 
                   1019:          <li><p>Repeatedly <a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">get an
                   1020:          attribute</a> until no further attributes can be found,
                   1021:          then jump to the second step in the overall "two step"
                   1022:          algorithm.</p></li>
                   1023: 
                   1024:         </ol></dd>
                   1025: 
                   1026:        <dt>A sequence of bytes starting with: 0x3C 0x21 (ASCII '&lt;!')</dt>
                   1027:        <dt>A sequence of bytes starting with: 0x3C 0x2F (ASCII '&lt;/')</dt>
                   1028:        <dt>A sequence of bytes starting with: 0x3C 0x3F (ASCII '&lt;?')</dt>
                   1029:        <dd>
                   1030: 
                   1031:         <p>Advance the <var title="">position</var> pointer so that it
                   1032:         points at the first 0x3E byte (ASCII '&gt;') that comes after the
                   1033:         0x3C byte that was found.</p>
                   1034: 
                   1035:        </dd>
                   1036: 
                   1037:        <dt>Any other byte</dt>
                   1038:        <dd>
                   1039: 
                   1040:         <p>Do nothing with that byte.</p>
                   1041: 
                   1042:        </dd>
                   1043: 
                   1044:       </dl></li>
                   1045: 
                   1046:      <li>Move <var title="">position</var> so it points at the next
                   1047:      byte in the input stream, and return to the first step of this
                   1048:      "two step" algorithm.</li>
                   1049: 
                   1050:     </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
                   1051:     attribute</dfn>, it means doing this:</p>
                   1052: 
                   1053:     <ol><li><p>If the byte at <var title="">position</var> is one of 0x09
                   1054:      (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII FF), 0x0D (ASCII CR),
                   1055:      0x20 (ASCII space), or 0x2F (ASCII '/') then advance <var title="">position</var> to the next byte and redo this
                   1056:      substep.</p></li>
                   1057: 
                   1058:      <li><p>If the byte at <var title="">position</var> is 0x3E (ASCII
                   1059:      '&gt;'), then abort the "get an attribute" algorithm. There isn't
                   1060:      one.</p></li>
                   1061: 
                   1062:      <li><p>Otherwise, the byte at <var title="">position</var> is the
                   1063:      start of the attribute name. Let <var title="">attribute
                   1064:      name</var> and <var title="">attribute value</var> be the empty
                   1065:      string.</p></li>
                   1066: 
                   1067:      <li><p><i>Attribute name</i>: Process the byte at <var title="">position</var> as follows:</p>
                   1068: 
                   1069:       <dl class="switch"><dt>If it is 0x3D (ASCII '='), and the <var title="">attribute
                   1070:        name</var> is longer than the empty string</dt>
                   1071: 
                   1072:        <dd>Advance <var title="">position</var> to the next byte and
                   1073:        jump to the step below labeled <i>value</i>.</dd>
                   1074: 
                   1075:        <dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
                   1076:        FF), 0x0D (ASCII CR), or 0x20 (ASCII space)</dt>
                   1077: 
                   1078:        <dd>Jump to the step below labeled <i>spaces</i>.</dd>
                   1079: 
                   1080:        <dt>If it is 0x2F (ASCII '/') or 0x3E (ASCII '&gt;')</dt>
                   1081: 
                   1082:        <dd>Abort the "get an attribute" algorithm. The attribute's
                   1083:        name is the value of <var title="">attribute name</var>, its
                   1084:        value is the empty string.</dd>
                   1085: 
                   1086:        <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
                   1087:        'Z')</dt>
                   1088: 
                   1089:        <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
                   1090:        name</var> (where <var title="">b</var> is the value of the
                   1091:        byte at <var title="">position</var>).</dd>
                   1092: 
                   1093:        <dt>Anything else</dt>
                   1094: 
                   1095:        <dd>Append the Unicode character with the same code point as the
                   1096:        value of the byte at <var title="">position</var>) to <var title="">attribute name</var>. (It doesn't actually matter how
                   1097:        bytes outside the ASCII range are handled here, since only
                   1098:        ASCII characters can contribute to the detection of a character
                   1099:        encoding.)</dd>
                   1100: 
                   1101:       </dl></li>
                   1102: 
                   1103:      <li><p>Advance <var title="">position</var> to the next byte and
                   1104:      return to the previous step.</p></li>
                   1105: 
                   1106:      <li><p><i>Spaces</i>: If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
                   1107:      LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
                   1108:      advance <var title="">position</var> to the next byte, then,
                   1109:      repeat this step.</p></li>
                   1110: 
                   1111:      <li><p>If the byte at <var title="">position</var> is
                   1112:      <em>not</em> 0x3D (ASCII '='), abort the "get an attribute"
                   1113:      algorithm. The attribute's name is the value of <var title="">attribute name</var>, its value is the empty
                   1114:      string.</p></li>
                   1115: 
                   1116:      <li><p>Advance <var title="">position</var> past the 0x3D (ASCII
                   1117:      '=') byte.</p></li>
                   1118: 
                   1119:      <li><p><i>Value:</i> If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
                   1120:      LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
                   1121:      advance <var title="">position</var> to the next byte, then,
                   1122:      repeat this step.</p></li>
                   1123: 
                   1124:      <li><p>Process the byte at <var title="">position</var> as
                   1125:      follows:</p>
                   1126: 
                   1127:       <dl class="switch"><dt>If it is 0x22 (ASCII '"') or 0x27 ("'")</dt>
                   1128: 
                   1129:        <dd>
                   1130: 
                   1131:         <ol><li>Let <var title="">b</var> be the value of the byte at
                   1132:          <var title="">position</var>.</li>
                   1133: 
                   1134:          <li>Advance <var title="">position</var> to the next
                   1135:          byte.</li>
                   1136: 
                   1137:          <li>If the value of the byte at <var title="">position</var>
                   1138:          is the value of <var title="">b</var>, then advance <var title="">position</var> to the next byte and abort the "get
                   1139:          an attribute" algorithm. The attribute's name is the value of
                   1140:          <var title="">attribute name</var>, and its value is the
                   1141:          value of <var title="">attribute value</var>.</li>
                   1142: 
                   1143:          <li>Otherwise, if the value of the byte at <var title="">position</var> is in the range 0x41 (ASCII 'A') to
                   1144:          0x5A (ASCII 'Z'), then append a Unicode character to <var title="">attribute value</var> whose code point is 0x20 more
                   1145:          than the value of the byte at <var title="">position</var>.</li>
                   1146: 
                   1147:          <li>Otherwise, append a Unicode character to <var title="">attribute value</var> whose code point is the same as
                   1148:          the value of the byte at <var title="">position</var>.</li>
                   1149: 
                   1150:          <li>Return to the second step in these substeps.</li>
                   1151: 
                   1152:         </ol></dd>
                   1153: 
                   1154:        <dt>If it is 0x3E (ASCII '&gt;')</dt>
                   1155: 
                   1156:        <dd>Abort the "get an attribute" algorithm. The attribute's
                   1157:        name is the value of <var title="">attribute name</var>, its
                   1158:        value is the empty string.</dd>
                   1159: 
                   1160: 
                   1161:        <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
                   1162:        'Z')</dt>
                   1163: 
                   1164:        <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
                   1165:        value</var> (where <var title="">b</var> is the value of the
                   1166:        byte at <var title="">position</var>). Advance <var title="">position</var> to the next byte.</dd>
                   1167: 
                   1168:        <dt>Anything else</dt>
                   1169: 
                   1170:        <dd>Append the Unicode character with the same code point as the
                   1171:        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>
                   1172: 
                   1173:       </dl></li>
                   1174: 
                   1175:      <li><p>Process the byte at <var title="">position</var> as
                   1176:      follows:</p>
                   1177: 
                   1178:       <dl class="switch"><dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
                   1179:        FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E (ASCII
                   1180:        '&gt;')</dt>
                   1181: 
                   1182:        <dd>Abort the "get an attribute" algorithm. The attribute's
                   1183:        name is the value of <var title="">attribute name</var> and its
                   1184:        value is the value of <var title="">attribute value</var>.</dd>
                   1185: 
                   1186:        <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
                   1187:        'Z')</dt>
                   1188: 
                   1189:        <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
                   1190:        value</var> (where <var title="">b</var> is the value of the
                   1191:        byte at <var title="">position</var>).</dd>
                   1192: 
                   1193:        <dt>Anything else</dt>
                   1194: 
                   1195:        <dd>Append the Unicode character with the same code point as the
                   1196:        value of the byte at <var title="">position</var>) to <var title="">attribute value</var>.</dd>
                   1197: 
                   1198:       </dl></li>
                   1199: 
                   1200:      <li><p>Advance <var title="">position</var> to the next byte and
                   1201:      return to the previous step.</p></li>
                   1202: 
                   1203:     </ol><p>For the sake of interoperability, user agents should not use a
                   1204:     pre-scan algorithm that returns different results than the one
                   1205:     described above. (But, if you do, please at least let us know, so
                   1206:     that we can improve this algorithm and benefit everyone...)</p>
                   1207: 
                   1208:    </li>
                   1209: 
                   1210:    <li><p>If the user agent has information on the likely encoding for
                   1211:    this page, e.g. based on the encoding of the page when it was last
                   1212:    visited, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1213:    <i>tentative</i>, and abort these steps.</p></li>
                   1214: 
                   1215:    <li><p>The user agent may attempt to autodetect the character
                   1216:    encoding from applying frequency analysis or other algorithms to
                   1217:    the data stream. If autodetection succeeds in determining a
                   1218:    character encoding, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1.104     mike     1219:    <i>tentative</i>, and abort these steps. <a href="references.html#refsUNIVCHARDET">[UNIVCHARDET]</a></p></li>
1.1       mike     1220: 
                   1221:    <li><p>Otherwise, return an implementation-defined or
                   1222:    user-specified default character encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1223:    <i>tentative</i>. In non-legacy environments, the more
                   1224:    comprehensive <code title="">UTF-8</code> encoding is
                   1225:    recommended. Due to its use in legacy content, <code title="">windows-1252</code> is recommended as a default in
1.187     mike     1226:    predominantly Western demographics instead.</p></li>
1.1       mike     1227: 
                   1228:   </ol><p>The <a href="dom.html#document-s-character-encoding">document's character encoding</a> must immediately
                   1229:   be set to the value returned from this algorithm, at the same time
                   1230:   as the user agent uses the returned value to select the decoder to
                   1231:   use for the input stream.</p>
                   1232: 
                   1233: 
                   1234: 
                   1235:   <h5 id="preprocessing-the-input-stream"><span class="secno">9.2.2.2 </span>Preprocessing the input stream</h5>
                   1236: 
                   1237:   <p>Given an encoding, the bytes in the input stream must be
                   1238:   converted to Unicode characters for the tokenizer, as described by
                   1239:   the rules for that encoding, except that the leading U+FEFF BYTE
                   1240:   ORDER MARK character, if any, must not be stripped by the encoding
                   1241:   layer (it is stripped by the rule below).</p> <!-- this is to
                   1242:   prevent two leading BOMs from being both stripped, once by the
                   1243:   decoder, and once by the parser -->
                   1244: 
                   1245:   <p>Bytes or sequences of bytes in the original byte stream that
                   1246:   could not be converted to Unicode characters must be converted to
                   1247:   U+FFFD REPLACEMENT CHARACTER code points.</p>
                   1248: 
                   1249:   <p class="note">Bytes or sequences of bytes in the original byte
                   1250:   stream that did not conform to the encoding specification
                   1251:   (e.g. invalid UTF-8 byte sequences in a UTF-8 input stream) are
                   1252:   errors that conformance checkers are expected to report.</p>
                   1253: 
                   1254:   <p>Any byte or sequences of bytes in the original byte stream that
                   1255:   is <a href="infrastructure.html#misinterpreted-for-compatibility">misinterpreted for compatibility</a> is a <a href="#parse-error">parse
                   1256:   error</a>.</p>
                   1257: 
                   1258:   <p>One leading U+FEFF BYTE ORDER MARK character must be ignored if
                   1259:   any are present.</p>
                   1260: 
                   1261:   <p>All U+0000 NULL characters in the input must be replaced by
                   1262:   U+FFFD REPLACEMENT CHARACTERs. Any occurrences of such characters is
                   1263:   a <a href="#parse-error">parse error</a>.</p>
                   1264: 
                   1265:   <p>Any occurrences of any characters in the ranges U+0001 to U+0008,
                   1266:   <!-- HT, LF allowed --> <!-- U+000B is in the next list --> <!-- FF,
                   1267:   CR allowed --> U+000E to U+001F, <!-- ASCII allowed --> U+007F
                   1268:   <!--to U+0084, (U+0085 NEL not allowed), U+0086--> to U+009F, U+D800
                   1269:   to U+DFFF<!-- surrogates not allowed -->, U+FDD0 to U+FDEF, and
                   1270:   characters U+000B, U+FFFE, U+FFFF, U+1FFFE, U+1FFFF, U+2FFFE,
                   1271:   U+2FFFF, U+3FFFE, U+3FFFF, U+4FFFE, U+4FFFF, U+5FFFE, U+5FFFF,
                   1272:   U+6FFFE, U+6FFFF, U+7FFFE, U+7FFFF, U+8FFFE, U+8FFFF, U+9FFFE,
                   1273:   U+9FFFF, U+AFFFE, U+AFFFF, U+BFFFE, U+BFFFF, U+CFFFE, U+CFFFF,
                   1274:   U+DFFFE, U+DFFFF, U+EFFFE, U+EFFFF, U+FFFFE, U+FFFFF, U+10FFFE, and
                   1275:   U+10FFFF are <a href="#parse-error" title="parse error">parse errors</a>. (These
                   1276:   are all control characters or permanently undefined Unicode
                   1277:   characters.)</p>
                   1278: 
                   1279:   <p>U+000D CARRIAGE RETURN (CR) characters and U+000A LINE FEED (LF)
                   1280:   characters are treated specially. Any CR characters that are
                   1281:   followed by LF characters must be removed, and any CR characters not
                   1282:   followed by LF characters must be converted to LF characters. Thus,
                   1283:   newlines in HTML DOMs are represented by LF characters, and there
                   1284:   are never any CR characters in the input to the
                   1285:   <a href="#tokenization">tokenization</a> stage.</p>
                   1286: 
                   1287:   <p>The <dfn id="next-input-character">next input character</dfn> is the first character in the
                   1288:   input stream that has not yet been <dfn id="consumed">consumed</dfn>. Initially,
                   1289:   the <i><a href="#next-input-character">next input character</a></i> is the first character in the
                   1290:   input. The <dfn id="current-input-character">current input character</dfn> is the last character
                   1291:   to have been <i><a href="#consumed">consumed</a></i>.</p>
                   1292: 
                   1293:   <p>The <dfn id="insertion-point">insertion point</dfn> is the position (just before a
                   1294:   character or just before the end of the input stream) where content
1.159     mike     1295:   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     1296:   inserted. The insertion point is relative to the position of the
                   1297:   character immediately after it, it is not an absolute offset into
                   1298:   the input stream. Initially, the insertion point is
1.10      mike     1299:   undefined.</p>
1.1       mike     1300: 
                   1301:   <p>The "EOF" character in the tables below is a conceptual character
                   1302:   representing the end of the <a href="#the-input-stream">input stream</a>. If the parser
1.159     mike     1303:   is a <a href="embedded-content-0.html#script-created-parser">script-created parser</a>, then the end of the
1.1       mike     1304:   <a href="#the-input-stream">input stream</a> is reached when an <dfn id="explicit-eof-character">explicit "EOF"
1.159     mike     1305:   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     1306:   consumed. Otherwise, the "EOF" character is not a real character in
                   1307:   the stream, but rather the lack of any further characters.</p>
                   1308: 
                   1309: 
                   1310:   <h5 id="changing-the-encoding-while-parsing"><span class="secno">9.2.2.3 </span>Changing the encoding while parsing</h5>
                   1311: 
                   1312:   <p>When the parser requires the user agent to <dfn id="change-the-encoding">change the
                   1313:   encoding</dfn>, it must run the following steps. This might happen
                   1314:   if the <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> described above
                   1315:   failed to find an encoding, or if it found an encoding that was not
                   1316:   the actual encoding of the file.</p>
                   1317: 
                   1318:   <ol><li>If the new encoding is identical or equivalent to the encoding
                   1319:    that is already being used to interpret the input stream, then set
                   1320:    the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1321:    <i>certain</i> and abort these steps. This happens when the
                   1322:    encoding information found in the file matches what the
                   1323:    <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> determined to be the
                   1324:    encoding, and in the second pass through the parser if the first
                   1325:    pass found that the encoding sniffing algorithm described in the
                   1326:    earlier section failed to find the right encoding.</li>
                   1327: 
                   1328:    <li>If the encoding that is already being used to interpret the
                   1329:    input stream is a UTF-16 encoding, then set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1330:    <i>certain</i> and abort these steps. The new encoding is ignored;
                   1331:    if it was anything but the same encoding, then it would be clearly
                   1332:    incorrect.</li>
                   1333: 
                   1334:    <li>If the new encoding is a UTF-16 encoding, change it to
                   1335:    UTF-8.</li>
                   1336: 
                   1337:    <li>If all the bytes up to the last byte converted by the current
                   1338:    decoder have the same Unicode interpretations in both the current
                   1339:    encoding and the new encoding, and if the user agent supports
                   1340:    changing the converter on the fly, then the user agent may change
                   1341:    to the new converter for the encoding on the fly. Set the
                   1342:    <a href="dom.html#document-s-character-encoding">document's character encoding</a> and the encoding used to
                   1343:    convert the input stream to the new encoding, set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1344:    <i>certain</i>, and abort these steps.</li>
                   1345: 
                   1346:    <li>Otherwise, <a href="history.html#navigate">navigate</a> to the document again, with
                   1347:    <a href="history.html#replacement-enabled">replacement enabled</a>, and using the same <a href="history.html#source-browsing-context">source
                   1348:    browsing context</a>, but this time skip the <a href="#encoding-sniffing-algorithm">encoding
                   1349:    sniffing algorithm</a> and instead just set the encoding to the
                   1350:    new encoding and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1351:    <i>certain</i>. Whenever possible, this should be done without
                   1352:    actually contacting the network layer (the bytes should be
                   1353:    re-parsed from memory), even if, e.g., the document is marked as
                   1354:    not being cacheable. If this is not possible and contacting the
                   1355:    network layer would involve repeating a request that uses a method
                   1356:    other than HTTP GET (<a href="infrastructure.html#concept-http-equivalent-get" title="concept-http-equivalent-get">or
                   1357:    equivalent</a> for non-HTTP URLs), then instead set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1358:    <i>certain</i> and ignore the new encoding. The resource will be
                   1359:    misinterpreted. User agents may notify the user of the situation,
                   1360:    to aid in application development.</li>
                   1361: 
                   1362:   </ol><h4 id="parse-state"><span class="secno">9.2.3 </span>Parse state</h4>
                   1363: 
                   1364:   <h5 id="the-insertion-mode"><span class="secno">9.2.3.1 </span>The insertion mode</h5>
                   1365: 
                   1366:   <p>The <dfn id="insertion-mode">insertion mode</dfn> is a state variable that controls
                   1367:   the primary operation of the tree construction stage.</p>
                   1368: 
                   1369:   <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
                   1370:   "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>",
                   1371:   "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>",
                   1372:   "<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     1373:   "<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     1374:   "<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>",
                   1375:   "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table body</a>",
                   1376:   "<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
                   1377:   table</a>", "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in
                   1378:   foreign content</a>", "<a href="#parsing-main-afterbody" title="insertion mode: after
                   1379:   body">after body</a>", "<a href="#parsing-main-inframeset" title="insertion mode: in
                   1380:   frameset">in frameset</a>", "<a href="#parsing-main-afterframeset" title="insertion mode: after
                   1381:   frameset">after frameset</a>", "<a href="#the-after-after-body-insertion-mode" title="insertion mode:
                   1382:   after after body">after after body</a>", and "<a href="#the-after-after-frameset-insertion-mode" title="insertion mode: after after frameset">after after
                   1383:   frameset</a>" during the course of the parsing, as described in
                   1384:   the <a href="#tree-construction">tree construction</a> stage. The insertion mode affects
                   1385:   how tokens are processed and whether CDATA sections are
                   1386:   supported.</p>
                   1387: 
                   1388:   <p>Seven of these modes, namely "<a href="#parsing-main-inhead" title="insertion mode: in
                   1389:   head">in head</a>", "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   1390:   body</a>", "<a href="#parsing-main-intable" title="insertion mode: in table">in
                   1391:   table</a>", "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   1392:   body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>",
                   1393:   "<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
                   1394:   that the other modes defer to them at various times. When the
                   1395:   algorithm below says that the user agent is to do something
                   1396:   "<dfn id="using-the-rules-for">using the rules for</dfn> the <var title="">m</var> insertion
                   1397:   mode", where <var title="">m</var> is one of these modes, the user
                   1398:   agent must use the rules described under the <var title="">m</var>
                   1399:   <a href="#insertion-mode">insertion mode</a>'s section, but must leave the
                   1400:   <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>
                   1401:   to a new value.</p>
                   1402: 
                   1403:   <p>When the insertion mode is switched to "<a href="#parsing-main-incdata" title="insertion
1.91      mike     1404:   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     1405:   <dfn id="original-insertion-mode">original insertion mode</dfn> is also set. This is the
                   1406:   insertion mode to which the tree construction stage will return.</p>
                   1407: 
                   1408:   <p>When the insertion mode is switched to "<a href="#parsing-main-inforeign" title="insertion
                   1409:   mode: in foreign content">in foreign content</a>", the
                   1410:   <dfn id="secondary-insertion-mode">secondary insertion mode</dfn> is also set. This secondary mode
                   1411:   is used within the rules for the "<a href="#parsing-main-inforeign" title="insertion mode: in
                   1412:   foreign content">in foreign content</a>" mode to handle HTML
                   1413:   (i.e. not foreign) content.</p>
                   1414: 
                   1415:   <hr><p>When the steps below require the UA to <dfn id="reset-the-insertion-mode-appropriately">reset the insertion
                   1416:   mode appropriately</dfn>, it means the UA must follow these
                   1417:   steps:</p>
                   1418: 
                   1419:   <ol><li>Let <var title="">last</var> be false.</li>
                   1420: 
                   1421:    <li>Let <var title="">node</var> be the last node in the
                   1422:    <a href="#stack-of-open-elements">stack of open elements</a>.</li>
                   1423: 
                   1424:    <li>If <var title="">node</var> is the first node in the stack of
                   1425:    open elements, then set <var title="">last</var> to true and set
                   1426:    <var title="">node</var> to the <var title="">context</var>
                   1427:    element. (<a href="#fragment-case">fragment case</a>)</li>
                   1428: 
                   1429:    <li>If <var title="">node</var> is a <code><a href="forms.html#the-select-element">select</a></code> element,
                   1430:    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
                   1431:    steps. (<a href="#fragment-case">fragment case</a>)</li>
                   1432: 
                   1433:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-td-element">td</a></code> or
                   1434:    <code><a href="tabular-data.html#the-th-element">th</a></code> element and <var title="">last</var> is false, then
                   1435:    switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion
                   1436:    mode: in cell">in cell</a>" and abort these steps.</li>
                   1437: 
                   1438:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then
                   1439:    switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion
                   1440:    mode: in row">in row</a>" and abort these steps.</li>
                   1441: 
                   1442:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
                   1443:    <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
                   1444:    <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in
                   1445:    table body">in table body</a>" and abort these steps.</li>
                   1446: 
                   1447:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-caption-element">caption</a></code> element,
                   1448:    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
                   1449:    these steps.</li>
                   1450: 
                   1451:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element,
                   1452:    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
                   1453:    abort these steps. (<a href="#fragment-case">fragment case</a>)</li>
                   1454: 
                   1455:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-table-element">table</a></code> element,
                   1456:    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
                   1457:    steps.</li>
                   1458: 
                   1459:    <li>If <var title="">node</var> is an element from the <a href="#mathml-namespace">MathML
                   1460:    namespace</a> or the <a href="#svg-namespace">SVG namespace</a>, then switch the
                   1461:    <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
                   1462:    foreign content">in foreign content</a>", let the
                   1463:    <a href="#secondary-insertion-mode">secondary insertion mode</a> be "<a href="#parsing-main-inbody" title="insertion
                   1464:    mode: in body">in body</a>", and abort these steps.</li>
                   1465: 
1.159     mike     1466:    <li>If <var title="">node</var> is a <code><a href="semantics.html#the-head-element-0">head</a></code> element,
1.1       mike     1467:    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
                   1468:    these steps. (<a href="#fragment-case">fragment case</a>)</li> <!-- This is only
                   1469:    here for now in case people think that the spec accidentally
                   1470:    omitted it and try to "fix" it. Note that noscript-in-head is also
                   1471:    handled this way. This is all intentional. The only thing it
                   1472:    doesn't handle is the scripting-disabled fragment parsing case for
                   1473:    a <head> element containing a <noscript> which itself contains
                   1474:    something other than a <link> or a <style> element; you'd expect
                   1475:    that to break out of the <noscript> but it doesn't. This is an edge
                   1476:    case that doesn't affect the spec, since the algorithm for fragment
                   1477:    parsing is only used for innerHTML/outerHTML/insertAdjacentHTML(),
                   1478:    where we know scripting is enabled. (XXX except maybe if innerHTML
                   1479:    is set from another browsing context on a document with designMode
                   1480:    set?) -->
                   1481: 
1.159     mike     1482:    <li>If <var title="">node</var> is a <code><a href="semantics.html#the-body-element-0">body</a></code> element,
1.1       mike     1483:    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
                   1484:    steps.</li>
                   1485: 
1.5       mike     1486:    <li>If <var title="">node</var> is a <code><a href="obsolete.html#frameset">frameset</a></code> element,
1.1       mike     1487:    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
                   1488:    these steps. (<a href="#fragment-case">fragment case</a>)</li>
                   1489: 
1.159     mike     1490:    <li>If <var title="">node</var> is an <code><a href="semantics.html#the-html-element-0">html</a></code> element,
1.1       mike     1491:    then: if the <a href="#head-element-pointer"><code title="">head</code> element
                   1492:    pointer</a> is null, switch the <a href="#insertion-mode">insertion mode</a> to
                   1493:    "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>",
                   1494:    otherwise, switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#the-after-head-insertion-mode" title="insertion mode: after head">after head</a>". In either
                   1495:    case, abort these steps. (<a href="#fragment-case">fragment case</a>)</li> <!-- XXX
                   1496:    can the head element pointer ever be non-null when we're going
                   1497:    through these steps? -->
                   1498: 
                   1499:    <li>If <var title="">last</var> is true, then switch the
                   1500:    <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in
                   1501:    body">in body</a>" and abort these steps. (<a href="#fragment-case">fragment
                   1502:    case</a>)</li>
                   1503: 
                   1504:    <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
                   1505:    elements</a>.</li>
                   1506: 
                   1507:    <li>Return to step 3.</li>
                   1508: 
                   1509:   </ol><h5 id="the-stack-of-open-elements"><span class="secno">9.2.3.2 </span>The stack of open elements</h5>
                   1510: 
                   1511:   <p>Initially, the <dfn id="stack-of-open-elements">stack of open elements</dfn> is empty. The
                   1512:   stack grows downwards; the topmost node on the stack is the first
                   1513:   one added to the stack, and the bottommost node of the stack is the
                   1514:   most recently added node in the stack (notwithstanding when the
                   1515:   stack is manipulated in a random access fashion as part of <a href="#adoptionAgency">the handling for misnested tags</a>).</p>
                   1516: 
                   1517:   <p>The "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before
                   1518:   html</a>" <a href="#insertion-mode">insertion mode</a> creates the
1.159     mike     1519:   <code><a href="semantics.html#the-html-element-0">html</a></code> root element node, which is then added to the
1.1       mike     1520:   stack.</p>
                   1521: 
                   1522:   <p>In the <a href="#fragment-case">fragment case</a>, the <a href="#stack-of-open-elements">stack of open
1.159     mike     1523:   elements</a> is initialized to contain an <code><a href="semantics.html#the-html-element-0">html</a></code>
1.1       mike     1524:   element that is created as part of <a href="#html-fragment-parsing-algorithm" title="html fragment
                   1525:   parsing algorithm">that algorithm</a>. (The <a href="#fragment-case">fragment
                   1526:   case</a> skips the "<a href="#the-before-html-insertion-mode" title="insertion mode: before
                   1527:   html">before html</a>" <a href="#insertion-mode">insertion mode</a>.)</p>
                   1528: 
1.159     mike     1529:   <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     1530:   node of the stack. It never gets popped off the stack.</p>
                   1531: 
                   1532:   <p>The <dfn id="current-node">current node</dfn> is the bottommost node in this
                   1533:   stack.</p>
                   1534: 
                   1535:   <p>The <dfn id="current-table">current table</dfn> is the last <code><a href="tabular-data.html#the-table-element">table</a></code>
                   1536:   element in the <a href="#stack-of-open-elements">stack of open elements</a>, if there is
                   1537:   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
                   1538:   open elements</a> (<a href="#fragment-case">fragment case</a>), then the
                   1539:   <a href="#current-table">current table</a> is the first element in the <a href="#stack-of-open-elements">stack
1.159     mike     1540:   of open elements</a> (the <code><a href="semantics.html#the-html-element-0">html</a></code> element).</p>
1.1       mike     1541: 
                   1542:   <p>Elements in the stack fall into the following categories:</p>
                   1543: 
                   1544:   <dl><dt><dfn id="special">Special</dfn></dt>
                   1545: 
                   1546:    <dd><p>The following HTML elements have varying levels of special
                   1547:    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>,
                   1548:    <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     1549:    <code><a href="obsolete.html#basefont">basefont</a></code>, <code>bgsound</code>,
1.159     mike     1550:    <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     1551:    <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     1552:    <code><a href="interactive-elements.html#the-command">command</a></code>, <!--v2DDATAGRID--><code>datagrid</code>,
                   1553:    <code><a href="semantics.html#the-dd-element">dd</a></code>, <code><a href="interactive-elements.html#the-details-element">details</a></code>, <code><a href="semantics.html#the-dialog-element">dialog</a></code>,
                   1554:    <code><a href="obsolete.html#dir">dir</a></code>, <code><a href="interactive-elements.html#the-div-element">div</a></code>, <code><a href="semantics.html#the-dl-element">dl</a></code>,
1.159     mike     1555:    <code><a href="semantics.html#the-dt-element">dt</a></code>, <code><a href="text-level-semantics.html#the-embed-element">embed</a></code>, <code><a href="forms.html#the-fieldset-element">fieldset</a></code>,
                   1556:    <code><a href="text-level-semantics.html#the-figure-element">figure</a></code>, <code><a href="semantics.html#the-footer-element">footer</a></code>, <code><a href="forms.html#the-form-element">form</a></code>,
1.86      mike     1557:    <code><a href="obsolete.html#frame">frame</a></code>, <code><a href="obsolete.html#frameset">frameset</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h1</a></code>,
                   1558:    <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h2</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h3</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h4</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h5</a></code>,
1.159     mike     1559:    <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h6</a></code>, <code><a href="semantics.html#the-head-element-0">head</a></code>, <code><a href="semantics.html#the-header-element">header</a></code>,
                   1560:    <code><a href="semantics.html#the-hgroup-element">hgroup</a></code>, <code><a href="semantics.html#the-hr-element">hr</a></code>, <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>, <!--
1.86      mike     1561:    <code>image</code>, (commented out because this isn't an element
                   1562:    that can end up on the stack, so it doesn't matter) -->
1.159     mike     1563:    <code><a href="text-level-semantics.html#the-img-element">img</a></code>, <code><a href="forms.html#the-input-element">input</a></code>, <code><a href="obsolete.html#isindex-0">isindex</a></code>,
1.86      mike     1564:    <code><a href="semantics.html#the-li-element">li</a></code>, <code><a href="semantics.html#the-link-element">link</a></code>, <code><a href="obsolete.html#listing">listing</a></code>,
                   1565:    <code><a href="interactive-elements.html#menus">menu</a></code>, <code><a href="semantics.html#meta">meta</a></code>, <code><a href="semantics.html#the-nav-element">nav</a></code>,
                   1566:    <code><a href="obsolete.html#noembed">noembed</a></code>, <code><a href="obsolete.html#noframes">noframes</a></code>, <code><a href="semantics.html#the-noscript-element">noscript</a></code>,
1.159     mike     1567:    <code><a href="semantics.html#the-ol-element">ol</a></code>, <code><a href="semantics.html#the-p-element">p</a></code>, <code><a href="text-level-semantics.html#the-param-element">param</a></code>,
1.86      mike     1568:    <code><a href="obsolete.html#plaintext">plaintext</a></code>, <code><a href="semantics.html#the-pre-element">pre</a></code>, <code><a href="semantics.html#script">script</a></code>,
                   1569:    <code><a href="semantics.html#the-section-element">section</a></code>, <code><a href="forms.html#the-select-element">select</a></code>, <code><a href="obsolete.html#spacer">spacer</a></code>,
                   1570:    <code><a href="semantics.html#the-style-element">style</a></code>, <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>, <code><a href="forms.html#the-textarea-element">textarea</a></code>,
1.159     mike     1571:    <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>, <code><a href="tabular-data.html#the-thead-element">thead</a></code>, <code><a href="semantics.html#the-title-element-0">title</a></code>,
1.174     mike     1572:    <code><a href="tabular-data.html#the-tr-element">tr</a></code>, <code><a href="semantics.html#the-ul-element">ul</a></code>, <code>wbr</code>, and
                   1573:    <code><a href="obsolete.html#xmp">xmp</a></code>.</p></dd>
1.1       mike     1574: 
                   1575:    <dt><dfn id="scoping">Scoping</dfn></dt>
                   1576:    <dd><p>The following HTML elements introduce new <a href="#has-an-element-in-scope" title="has
                   1577:    an element in scope">scopes</a> for various parts of the
1.5       mike     1578:    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     1579:    <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>,
                   1580:    <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     1581:    <code><a href="tabular-data.html#the-th-element">th</a></code>, and SVG's <code>foreignObject</code>.</p></dd>
                   1582: 
                   1583:    <dt><dfn id="formatting">Formatting</dfn></dt>
                   1584:    <dd><p>The following HTML elements are those that end up in the
                   1585:    <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     1586:    <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>,
                   1587:    <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>,
                   1588:    <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>,
                   1589:    <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
                   1590:    <code><a href="obsolete.html#u">u</a></code>.</p></dd>
1.1       mike     1591: 
                   1592:    <dt><dfn id="phrasing">Phrasing</dfn></dt>
                   1593:    <dd><p>All other elements found while parsing an HTML
                   1594:    document.</p></dd>
                   1595: 
                   1596:   </dl><p>The <a href="#stack-of-open-elements">stack of open elements</a> is said to <dfn id="has-an-element-in-scope" title="has an element in scope">have an element in scope</dfn> when
                   1597:   the following algorithm terminates in a match state:</p>
                   1598: 
                   1599:   <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   1600:    node</a> (the bottommost node of the stack).</p></li>
                   1601: 
                   1602:    <li><p>If <var title="">node</var> is the target node, terminate in
                   1603:    a match state.</p></li>
                   1604: 
                   1605:    <li><p>Otherwise, if <var title="">node</var> is one of the
                   1606:    following elements, terminate in a failure state:</p>
1.5       mike     1607:     <ul class="brief"><li><code><a href="obsolete.html#the-applet-element">applet</a></code> in the HTML namespace</li>
1.1       mike     1608:      <li><code><a href="tabular-data.html#the-caption-element">caption</a></code> in the HTML namespace</li>
1.159     mike     1609:      <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.) -->
1.1       mike     1610:      <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
                   1611:      <li><code><a href="tabular-data.html#the-td-element">td</a></code> in the HTML namespace</li>
                   1612:      <li><code><a href="tabular-data.html#the-th-element">th</a></code> in the HTML namespace</li>
                   1613:      <li><code><a href="forms.html#the-button-element">button</a></code> in the HTML namespace</li>
1.159     mike     1614:      <li><code><a href="obsolete.html#the-marquee-element">marquee</a></code> in the HTML namespace</li>
                   1615:      <li><code><a href="text-level-semantics.html#the-object-element">object</a></code> in the HTML namespace</li>
1.1       mike     1616:      <li><code title="">foreignObject</code> in the SVG namespace</li>
                   1617:     </ul></li>
                   1618: 
                   1619:    <li><p>Otherwise, set <var title="">node</var> to the previous
                   1620:    entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to step
                   1621:    2. (This will never fail, since the loop will always terminate in
                   1622:    the previous step if the top of the stack &#8212; an
1.159     mike     1623:    <code><a href="semantics.html#the-html-element-0">html</a></code> element &#8212; is reached.)</p></li>
1.1       mike     1624: 
                   1625:   </ol><p>The <a href="#stack-of-open-elements">stack of open elements</a> is said to <dfn id="has-an-element-in-table-scope" title="has an element in table scope">have an element in <em>table
                   1626:   scope</em></dfn> when the following algorithm terminates in a match
                   1627:   state:</p>
                   1628: 
                   1629:   <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   1630:    node</a> (the bottommost node of the stack).</p></li>
                   1631: 
                   1632:    <li><p>If <var title="">node</var> is the target node, terminate in
                   1633:    a match state.</p></li>
                   1634: 
                   1635:    <li><p>Otherwise, if <var title="">node</var> is one of the
                   1636:    following elements, terminate in a failure state:</p>
1.159     mike     1637:     <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.) -->
1.1       mike     1638:      <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
                   1639:     </ul></li>
                   1640: 
                   1641:    <li><p>Otherwise, set <var title="">node</var> to the previous
                   1642:    entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to step
                   1643:    2. (This will never fail, since the loop will always terminate in
                   1644:    the previous step if the top of the stack &#8212; an
1.159     mike     1645:    <code><a href="semantics.html#the-html-element-0">html</a></code> element &#8212; is reached.)</p></li>
1.1       mike     1646: 
                   1647:   </ol><p>Nothing happens if at any time any of the elements in the
                   1648:   <a href="#stack-of-open-elements">stack of open elements</a> are moved to a new location in,
                   1649:   or removed from, the <code>Document</code> tree. In particular, the
                   1650:   stack is not changed in this situation. This can cause, amongst
                   1651:   other strange effects, content to be appended to nodes that are no
                   1652:   longer in the DOM.</p>
                   1653: 
                   1654:   <p class="note">In some cases (namely, when <a href="#adoptionAgency">closing misnested formatting elements</a>),
                   1655:   the stack is manipulated in a random-access fashion.</p>
                   1656: 
                   1657: 
                   1658:   <h5 id="the-list-of-active-formatting-elements"><span class="secno">9.2.3.3 </span>The list of active formatting elements</h5>
                   1659: 
                   1660:   <p>Initially, the <dfn id="list-of-active-formatting-elements">list of active formatting elements</dfn> is
                   1661:   empty. It is used to handle mis-nested <a href="#formatting" title="formatting">formatting element tags</a>.</p>
                   1662: 
                   1663:   <p>The list contains elements in the <a href="#formatting">formatting</a>
                   1664:   category, and scope markers. The scope markers are inserted when
1.159     mike     1665:   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     1666:   elements, marquees, table cells, and table captions, and are used to
1.5       mike     1667:   prevent formatting from "leaking" <em>into</em> <code><a href="obsolete.html#the-applet-element">applet</a></code>
1.159     mike     1668:   elements, buttons, <code><a href="text-level-semantics.html#the-object-element">object</a></code> elements, marquees, and
1.1       mike     1669:   tables.</p>
                   1670: 
                   1671:   <p class="note">The scope markers are unrelated to the concept of an
                   1672:   element being <a href="#has-an-element-in-scope" title="has an element in scope">in
                   1673:   scope</a>.</p>
                   1674: 
                   1675:   <p>In addition, each element in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1676:   elements</a> is associated with the token for which it was
                   1677:   created, so that further elements can be created for that token if
                   1678:   necessary.</p>
                   1679: 
                   1680:   <p>When the steps below require the UA to <dfn id="reconstruct-the-active-formatting-elements">reconstruct the
                   1681:   active formatting elements</dfn>, the UA must perform the following
                   1682:   steps:</p>
                   1683: 
                   1684:   <ol><li>If there are no entries in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1685:    elements</a>, then there is nothing to reconstruct; stop this
                   1686:    algorithm.</li>
                   1687: 
                   1688:    <li>If the last (most recently added) entry in the <a href="#list-of-active-formatting-elements">list of
                   1689:    active formatting elements</a> is a marker, or if it is an
                   1690:    element that is in the <a href="#stack-of-open-elements">stack of open elements</a>, then
                   1691:    there is nothing to reconstruct; stop this algorithm.</li>
                   1692: 
                   1693:    <li>Let <var title="">entry</var> be the last (most recently added)
                   1694:    element in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1695:    elements</a>.</li>
                   1696: 
                   1697:    <li>If there are no entries before <var title="">entry</var> in the
                   1698:    <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, then jump to step
                   1699:    8.</li>
                   1700: 
                   1701:    <li>Let <var title="">entry</var> be the entry one earlier than
                   1702:    <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1703:    elements</a>.</li>
                   1704: 
                   1705:    <li>If <var title="">entry</var> is neither a marker nor an element
                   1706:    that is also in the <a href="#stack-of-open-elements">stack of open elements</a>, go to step
                   1707:    4.</li>
                   1708: 
                   1709:    <li>Let <var title="">entry</var> be the element one later than
                   1710:    <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1711:    elements</a>.</li>
                   1712: 
                   1713:    <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
                   1714:    element <var title="">entry</var> was created, to obtain <var title="">new element</var>.</li>
                   1715: 
                   1716:    <li>Append <var title="">new element</var> to the <a href="#current-node">current
                   1717:    node</a> and push it onto the <a href="#stack-of-open-elements">stack of open
                   1718:    elements</a> so that it is the new <a href="#current-node">current
                   1719:    node</a>.</li>
                   1720: 
                   1721:    <li>Replace the entry for <var title="">entry</var> in the list
                   1722:    with an entry for <var title="">new element</var>.</li>
                   1723: 
                   1724:    <li>If the entry for <var title="">new element</var> in the
                   1725:    <a href="#list-of-active-formatting-elements">list of active formatting elements</a> is not the last
                   1726:    entry in the list, return to step 7.</li>
                   1727: 
                   1728:   </ol><p>This has the effect of reopening all the formatting elements that
                   1729:   were opened in the current body, cell, or caption (whichever is
                   1730:   youngest) that haven't been explicitly closed.</p>
                   1731: 
                   1732:   <p class="note">The way this specification is written, the
                   1733:   <a href="#list-of-active-formatting-elements">list of active formatting elements</a> always consists of
                   1734:   elements in chronological order with the least recently added
                   1735:   element first and the most recently added element last (except for
                   1736:   while steps 8 to 11 of the above algorithm are being executed, of
                   1737:   course).</p>
                   1738: 
                   1739:   <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
                   1740:   active formatting elements up to the last marker</dfn>, the UA must
                   1741:   perform the following steps:</p>
                   1742: 
                   1743:   <ol><li>Let <var title="">entry</var> be the last (most recently added)
                   1744:    entry in the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</li>
                   1745: 
                   1746:    <li>Remove <var title="">entry</var> from the <a href="#list-of-active-formatting-elements">list of active
                   1747:    formatting elements</a>.</li>
                   1748: 
                   1749:    <li>If <var title="">entry</var> was a marker, then stop the
                   1750:    algorithm at this point. The list has been cleared up to the last
                   1751:    marker.</li>
                   1752: 
                   1753:    <li>Go to step 1.</li>
                   1754: 
                   1755:   </ol><h5 id="the-element-pointers"><span class="secno">9.2.3.4 </span>The element pointers</h5>
                   1756: 
                   1757:   <p>Initially, the <dfn id="head-element-pointer"><code title="">head</code> element
                   1758:   pointer</dfn> and the <dfn id="form-element-pointer"><code title="">form</code> element
                   1759:   pointer</dfn> are both null.</p>
                   1760: 
1.159     mike     1761:   <p>Once a <code><a href="semantics.html#the-head-element-0">head</a></code> element has been parsed (whether
1.1       mike     1762:   implicitly or explicitly) the <a href="#head-element-pointer"><code title="">head</code>
                   1763:   element pointer</a> gets set to point to this node.</p>
                   1764: 
                   1765:   <p>The <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
                   1766:   points to the last <code><a href="forms.html#the-form-element">form</a></code> element that was opened and
                   1767:   whose end tag has not yet been seen. It is used to make form
                   1768:   controls associate with forms in the face of dramatically bad
                   1769:   markup, for historical reasons.</p>
                   1770: 
                   1771: 
                   1772:   <h5 id="other-parsing-state-flags"><span class="secno">9.2.3.5 </span>Other parsing state flags</h5>
                   1773: 
                   1774:   <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
                   1775:   <code>Document</code> with which the parser is associated when the
                   1776:   parser was created, and "disabled" otherwise.</p>
                   1777: 
                   1778:   <p class="note">The <a href="#scripting-flag">scripting flag</a> can be enabled even
                   1779:   when the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML fragment
                   1780:   parsing algorithm</a>, even though <code><a href="semantics.html#script">script</a></code> elements
                   1781:   don't execute in that case.</p>
                   1782: 
                   1783:   <p>The <dfn id="frameset-ok-flag">frameset-ok flag</dfn> is set to "ok" when the parser is
                   1784:   created. It is set to "not ok" after certain tokens are seen.</p>
                   1785: 
                   1786: 
1.159     mike     1787:   <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     1788: 
                   1789:   <p>Implementations must act as if they used the following state
                   1790:   machine to tokenize HTML. The state machine must start in the
                   1791:   <a href="#data-state">data state</a>. Most states consume a single character,
                   1792:   which may have various side-effects, and either switches the state
                   1793:   machine to a new state to <em>reconsume</em> the same character, or
                   1794:   switches it to a new state (to consume the next character), or
                   1795:   repeats the same state (to consume the next character). Some states
                   1796:   have more complicated behavior and can consume several characters
                   1797:   before switching to another state.</p>
                   1798: 
                   1799:   <p>The exact behavior of certain states depends on a <dfn id="content-model-flag">content
                   1800:   model flag</dfn> that is set after certain tokens are emitted. The
1.91      mike     1801:   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
                   1802:   state. In the RCDATA and RAWTEXT states, a further <dfn id="escape-flag">escape
1.1       mike     1803:   flag</dfn> is used to control the behavior of the tokenizer. It is
                   1804:   either true or false, and initially must be set to the false
                   1805:   state. The <a href="#insertion-mode">insertion mode</a> and the <a href="#stack-of-open-elements">stack of open
                   1806:   elements</a> also affects tokenization.</p>
                   1807: 
                   1808:   <p>The output of the tokenization step is a series of zero or more
                   1809:   of the following tokens: DOCTYPE, start tag, end tag, comment,
                   1810:   character, end-of-file. DOCTYPE tokens have a name, a public
                   1811:   identifier, a system identifier, and a <i>force-quirks
                   1812:   flag</i>. When a DOCTYPE token is created, its name, public
                   1813:   identifier, and system identifier must be marked as missing (which
                   1814:   is a distinct state from the empty string), and the <i>force-quirks
                   1815:   flag</i> must be set to <i>off</i> (its other state is
                   1816:   <i>on</i>). Start and end tag tokens have a tag name, a
                   1817:   <i>self-closing flag</i>, and a list of attributes, each of which
                   1818:   has a name and a value. When a start or end tag token is created,
                   1819:   its <i>self-closing flag</i> must be unset (its other state is that
                   1820:   it be set), and its attributes list must be empty. Comment and
                   1821:   character tokens have data.</p>
                   1822: 
                   1823:   <p>When a token is emitted, it must immediately be handled by the
                   1824:   <a href="#tree-construction">tree construction</a> stage. The tree construction stage
                   1825:   can affect the state of the <a href="#content-model-flag">content model flag</a>, and can
                   1826:   insert additional characters into the stream. (For example, the
                   1827:   <code><a href="semantics.html#script">script</a></code> element can result in scripts executing and
1.159     mike     1828:   using the <a href="embedded-content-0.html#dynamic-markup-insertion">dynamic markup insertion</a> APIs to insert
1.1       mike     1829:   characters into the stream being tokenized.)</p>
                   1830: 
                   1831:   <p>When a start tag token is emitted with its <i>self-closing
                   1832:   flag</i> set, if the flag is not <dfn id="acknowledge-self-closing-flag" title="acknowledge
                   1833:   self-closing flag">acknowledged</dfn> when it is processed by the
                   1834:   tree construction stage, that is a <a href="#parse-error">parse error</a>.</p>
                   1835: 
                   1836:   <p>When an end tag token is emitted, the <a href="#content-model-flag">content model
                   1837:   flag</a> must be switched to the PCDATA state.</p>
                   1838: 
                   1839:   <p>When an end tag token is emitted with attributes, that is a
                   1840:   <a href="#parse-error">parse error</a>.</p>
                   1841: 
                   1842:   <p>When an end tag token is emitted with its <i>self-closing
                   1843:   flag</i> set, that is a <a href="#parse-error">parse error</a>.</p>
                   1844: 
                   1845:   <p>Before each step of the tokenizer, the user agent must first
                   1846:   check the <a href="#parser-pause-flag">parser pause flag</a>. If it is true, then the
                   1847:   tokenizer must abort the processing of any nested invocations of the
                   1848:   tokenizer, yielding control back to the caller. If it is false, then
                   1849:   the user agent may then check to see if either one of the scripts in
                   1850:   the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts that will execute as soon as
                   1851:   possible</a> or the first script in the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts
                   1852:   that will execute asynchronously</a>, has <a href="semantics.html#completed-loading">completed
                   1853:   loading</a>. If one has, then it must be <a href="semantics.html#executing-a-script-block" title="executing a
                   1854:   script block">executed</a> and removed from its list.</p>
                   1855: 
                   1856:   <p>The tokenizer state machine consists of the states defined in the
                   1857:   following subsections.</p>
                   1858: 
                   1859:   <!-- XXX should go through these reordering the entries so that
                   1860:   they're in some consistent order, like, by Unicode, errors last, or
                   1861:   something -->
                   1862: 
                   1863:   <h5 id="data-state"><span class="secno">9.2.4.1 </span><dfn>Data state</dfn></h5>
                   1864: 
                   1865:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   1866: 
                   1867:   <dl class="switch"><dt>U+0026 AMPERSAND (&amp;)</dt>
                   1868:    <dd>When the <a href="#content-model-flag">content model flag</a> is set to one of the
                   1869:    PCDATA or RCDATA states and the <a href="#escape-flag">escape flag</a> is
                   1870:    false: switch to the <a href="#character-reference-data-state">character reference data
1.56      mike     1871:    state</a>.</dd>
                   1872:    <dd>Otherwise: treat it as per the "anything else" entry
                   1873:    below.</dd>
1.1       mike     1874: 
                   1875:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   1876:    <dd>
                   1877: 
                   1878:     <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91      mike     1879:     RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1       mike     1880:     is false, and there are at least three characters before this
                   1881:     one in the input stream, and the last four characters in the
                   1882:     input stream, including this one, are U+003C LESS-THAN SIGN,
                   1883:     U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS, and U+002D
                   1884:     HYPHEN-MINUS ("&lt;!--"), then set the <a href="#escape-flag">escape flag</a>
                   1885:     to true.</p>
                   1886: 
                   1887:     <p>In any case, emit the input character as a character
                   1888:     token. Stay in the <a href="#data-state">data state</a>.</p>
                   1889: 
                   1890:    </dd>
                   1891: 
                   1892:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   1893:    <dd>When the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
                   1894:    state: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
                   1895:    <dd>When the <a href="#content-model-flag">content model flag</a> is set to either the
1.91      mike     1896:    RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1       mike     1897:    is false: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
                   1898:    <dd>Otherwise: treat it as per the "anything else" entry
                   1899:    below.</dd>
                   1900: 
                   1901:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   1902:    <dd>
                   1903: 
                   1904:     <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91      mike     1905:     RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape
1.1       mike     1906:     flag</a> is true, and the last three characters in the input
                   1907:     stream including this one are U+002D HYPHEN-MINUS, U+002D
                   1908:     HYPHEN-MINUS, U+003E GREATER-THAN SIGN ("--&gt;"), set the
                   1909:     <a href="#escape-flag">escape flag</a> to false.</p> <!-- no need to check
                   1910:     that there are enough characters, since you can only run into
                   1911:     this if the flag is true in the first place, which requires four
                   1912:     characters. -->
                   1913: 
                   1914:     <p>In any case, emit the input character as a character
                   1915:     token. Stay in the <a href="#data-state">data state</a>.</p>
                   1916: 
                   1917:    </dd>
                   1918: 
                   1919:    <dt>EOF</dt>
                   1920:    <dd>Emit an end-of-file token.</dd>
                   1921: 
                   1922:    <dt>Anything else</dt>
                   1923:    <dd>Emit the input character as a character token. Stay in the
                   1924:    <a href="#data-state">data state</a>.</dd>
                   1925: 
                   1926:   </dl><h5 id="character-reference-data-state"><span class="secno">9.2.4.2 </span><dfn>Character reference data state</dfn></h5>
                   1927: 
                   1928:   <p><i>(This cannot happen if the <a href="#content-model-flag">content model flag</a>
1.91      mike     1929:   is set to the RAWTEXT state.)</i></p>
1.1       mike     1930: 
                   1931:   <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>, with no
                   1932:   <a href="#additional-allowed-character">additional allowed character</a>.</p>
                   1933: 
                   1934:   <p>If nothing is returned, emit a U+0026 AMPERSAND character
                   1935:   token.</p>
                   1936: 
                   1937:   <p>Otherwise, emit the character token that was returned.</p>
                   1938: 
                   1939:   <p>Finally, switch to the <a href="#data-state">data state</a>.</p>
                   1940: 
                   1941: 
                   1942:   <h5 id="tag-open-state"><span class="secno">9.2.4.3 </span><dfn>Tag open state</dfn></h5>
                   1943: 
                   1944:   <p>The behavior of this state depends on the <a href="#content-model-flag">content model
                   1945:   flag</a>.</p>
                   1946: 
                   1947:   <dl><dt>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA
1.91      mike     1948:    or RAWTEXT states</dt>
1.1       mike     1949: 
                   1950:    <dd>
                   1951: 
                   1952:     <p>Consume the <a href="#next-input-character">next input character</a>. If it is a
                   1953:     U+002F SOLIDUS (/) character, switch to the <a href="#close-tag-open-state">close tag open
                   1954:     state</a>. Otherwise, emit a U+003C LESS-THAN SIGN character
                   1955:     token and reconsume the <a href="#current-input-character">current input character</a> in the
                   1956:     <a href="#data-state">data state</a>.</p>
                   1957: 
                   1958:    </dd>
                   1959: 
                   1960:    <dt>If the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
                   1961:    state</dt>
                   1962: 
                   1963:    <dd>
                   1964: 
                   1965:     <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   1966: 
                   1967:     <dl class="switch"><dt>U+0021 EXCLAMATION MARK (!)</dt>
                   1968:      <dd>Switch to the <a href="#markup-declaration-open-state">markup declaration open state</a>.</dd>
                   1969: 
                   1970:      <dt>U+002F SOLIDUS (/)</dt>
                   1971:      <dd>Switch to the <a href="#close-tag-open-state">close tag open state</a>.</dd>
                   1972: 
                   1973:      <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   1974:      <dd>Create a new start tag token, set its tag name to the
                   1975:      lowercase version of the input character (add 0x0020 to the
                   1976:      character's code point), then switch to the <a href="#tag-name-state">tag name
                   1977:      state</a>. (Don't emit the token yet; further details will
                   1978:      be filled in before it is emitted.)</dd>
                   1979: 
                   1980:      <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
                   1981:      <dd>Create a new start tag token, set its tag name to the input
                   1982:      character, then switch to the <a href="#tag-name-state">tag name
                   1983:      state</a>. (Don't emit the token yet; further details will
                   1984:      be filled in before it is emitted.)</dd>
                   1985: 
                   1986:      <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   1987:      <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
                   1988:      character token and a U+003E GREATER-THAN SIGN character
                   1989:      token. Switch to the <a href="#data-state">data state</a>.</dd>
                   1990: 
                   1991:      <dt>U+003F QUESTION MARK (?)</dt>
                   1992:      <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
                   1993:      comment state</a>.</dd>
                   1994: 
                   1995:      <dt>Anything else</dt>
                   1996:      <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
                   1997:      character token and reconsume the <a href="#current-input-character">current input character</a> in the
                   1998:      <a href="#data-state">data state</a>.</dd>
                   1999: 
                   2000:     </dl></dd>
                   2001: 
                   2002:   </dl><h5 id="close-tag-open-state"><span class="secno">9.2.4.4 </span><dfn>Close tag open state</dfn></h5>
                   2003: 
                   2004:   <p>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA or
1.91      mike     2005:   RAWTEXT states but no start tag token has ever been emitted by this
1.1       mike     2006:   instance of the tokenizer (<a href="#fragment-case">fragment case</a>), or, if the
1.91      mike     2007:   <a href="#content-model-flag">content model flag</a> is set to the RCDATA or RAWTEXT states
1.1       mike     2008:   and the next few characters do not match the tag name of the last
                   2009:   start tag token emitted (compared in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   2010:   case-insensitive</a> manner), or if they do but they are not
                   2011:   immediately followed by one of the following characters:</p>
                   2012: 
                   2013:   <ul class="brief"><li>U+0009 CHARACTER TABULATION</li>
                   2014:    <li>U+000A LINE FEED (LF)</li>
                   2015:    <li>U+000C FORM FEED (FF)</li>
                   2016:    <!--<li>U+000D CARRIAGE RETURN (CR)</li>-->
                   2017:    <li>U+0020 SPACE</li>
                   2018:    <li>U+003E GREATER-THAN SIGN (&gt;)</li>
                   2019:    <li>U+002F SOLIDUS (/)</li>
                   2020:    <li>EOF</li>
                   2021:   </ul><p>...then emit a U+003C LESS-THAN SIGN character token, a U+002F
                   2022:   SOLIDUS character token, and switch to the <a href="#data-state">data state</a>
                   2023:   to process the <a href="#next-input-character">next input character</a>.</p>
                   2024: 
                   2025:   <p>Otherwise, if the <a href="#content-model-flag">content model flag</a> is set to the
                   2026:   PCDATA state, or if the next few characters <em>do</em> match that tag
                   2027:   name, consume the <a href="#next-input-character">next input character</a>:</p>
                   2028: 
                   2029:   <dl class="switch"><dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2030:    <dd>Create a new end tag token, set its tag name to the lowercase
                   2031:    version of the input character (add 0x0020 to the character's
                   2032:    code point), then switch to the <a href="#tag-name-state">tag name
                   2033:    state</a>. (Don't emit the token yet; further details will be
                   2034:    filled in before it is emitted.)</dd>
                   2035: 
                   2036:    <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
                   2037:    <dd>Create a new end tag token, set its tag name to the input
                   2038:    character, then switch to the <a href="#tag-name-state">tag name state</a>. (Don't
                   2039:    emit the token yet; further details will be filled in before it
                   2040:    is emitted.)</dd>
                   2041: 
                   2042:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2043:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#data-state">data
                   2044:    state</a>.</dd>
                   2045: 
                   2046:    <dt>EOF</dt>
                   2047:    <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
                   2048:    character token and a U+002F SOLIDUS character token. Reconsume
                   2049:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2050: 
                   2051:    <dt>Anything else</dt>
                   2052:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
                   2053:    comment state</a>.</dd>
                   2054: 
                   2055:   </dl><h5 id="tag-name-state"><span class="secno">9.2.4.5 </span><dfn>Tag name state</dfn></h5>
                   2056: 
                   2057:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2058: 
                   2059:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2060:    <dt>U+000A LINE FEED (LF)</dt>
                   2061:    <dt>U+000C FORM FEED (FF)</dt>
                   2062:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2063:    <dt>U+0020 SPACE</dt>
                   2064:    <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2065: 
                   2066:    <dt>U+002F SOLIDUS (/)</dt>
                   2067:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2068: 
                   2069:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2070:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2071:    state</a>.</dd>
                   2072: 
                   2073:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2074:    <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
                   2075:    (add 0x0020 to the character's code point) to the current tag
                   2076:    token's tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
                   2077: 
                   2078:    <dt>EOF</dt>
                   2079:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2080:    <a href="#data-state">data state</a>.</dd>
                   2081: 
                   2082:    <dt>Anything else</dt>
                   2083:    <dd>Append the <a href="#current-input-character">current input character</a> to the current tag token's
                   2084:    tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
                   2085: 
                   2086:   </dl><h5 id="before-attribute-name-state"><span class="secno">9.2.4.6 </span><dfn>Before attribute name state</dfn></h5>
                   2087: 
                   2088:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2089: 
                   2090:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2091:    <dt>U+000A LINE FEED (LF)</dt>
                   2092:    <dt>U+000C FORM FEED (FF)</dt>
                   2093:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2094:    <dt>U+0020 SPACE</dt>
                   2095:    <dd>Stay in the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2096: 
                   2097:    <dt>U+002F SOLIDUS (/)</dt>
                   2098:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2099: 
                   2100:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2101:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2102:    state</a>.</dd>
                   2103: 
                   2104:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2105:    <dd>Start a new attribute in the current tag token. Set that
                   2106:    attribute's name to the lowercase version of the <a href="#current-input-character">current input
                   2107:    character</a> (add 0x0020 to the character's code point), and its
                   2108:    value to the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2109:    state</a>.</dd>
                   2110: 
                   2111:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2112:    <dt>U+0027 APOSTROPHE (')</dt>
                   2113:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2114:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2115:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2116:    entry below.</dd>
                   2117: 
                   2118:    <dt>EOF</dt>
                   2119:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2120:    <a href="#data-state">data state</a>.</dd>
                   2121: 
                   2122:    <dt>Anything else</dt>
                   2123:    <dd>Start a new attribute in the current tag token. Set that
                   2124:    attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
                   2125:    the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2126:    state</a>.</dd>
                   2127: 
                   2128:   </dl><h5 id="attribute-name-state"><span class="secno">9.2.4.7 </span><dfn>Attribute name state</dfn></h5>
                   2129: 
                   2130:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2131: 
                   2132:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2133:    <dt>U+000A LINE FEED (LF)</dt>
                   2134:    <dt>U+000C FORM FEED (FF)</dt>
                   2135:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2136:    <dt>U+0020 SPACE</dt>
                   2137:    <dd>Switch to the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
                   2138: 
                   2139:    <dt>U+002F SOLIDUS (/)</dt>
                   2140:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2141: 
                   2142:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2143:    <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
                   2144: 
                   2145:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2146:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2147:    state</a>.</dd>
                   2148: 
                   2149:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2150:    <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
                   2151:    (add 0x0020 to the character's code point) to the current
                   2152:    attribute's name. Stay in the <a href="#attribute-name-state">attribute name
                   2153:    state</a>.</dd>
                   2154: 
                   2155:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2156:    <dt>U+0027 APOSTROPHE (')</dt>
                   2157:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2158:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2159:    entry below.</dd>
                   2160: 
                   2161:    <dt>EOF</dt>
                   2162:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2163:    <a href="#data-state">data state</a>.</dd>
                   2164: 
                   2165:    <dt>Anything else</dt>
                   2166:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2167:    name. Stay in the <a href="#attribute-name-state">attribute name state</a>.</dd>
                   2168: 
                   2169:   </dl><p>When the user agent leaves the attribute name state (and before
                   2170:   emitting the tag token, if appropriate), the complete attribute's
                   2171:   name must be compared to the other attributes on the same token;
                   2172:   if there is already an attribute on the token with the exact same
                   2173:   name, then this is a <a href="#parse-error">parse error</a> and the new
                   2174:   attribute must be dropped, along with the value that gets
                   2175:   associated with it (if any).</p>
                   2176: 
                   2177: 
                   2178:   <h5 id="after-attribute-name-state"><span class="secno">9.2.4.8 </span><dfn>After attribute name state</dfn></h5>
                   2179: 
                   2180:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2181: 
                   2182:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2183:    <dt>U+000A LINE FEED (LF)</dt>
                   2184:    <dt>U+000C FORM FEED (FF)</dt>
                   2185:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2186:    <dt>U+0020 SPACE</dt>
                   2187:    <dd>Stay in the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
                   2188: 
                   2189:    <dt>U+002F SOLIDUS (/)</dt>
                   2190:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2191: 
                   2192:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2193:    <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
                   2194: 
                   2195:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2196:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2197:    state</a>.</dd>
                   2198: 
                   2199:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2200:    <dd>Start a new attribute in the current tag token. Set that
                   2201:    attribute's name to the lowercase version of the <a href="#current-input-character">current input character</a>
                   2202:    (add 0x0020 to the character's code point), and its value to
                   2203:    the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2204:    state</a>.</dd>
                   2205: 
                   2206:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2207:    <dt>U+0027 APOSTROPHE (')</dt>
                   2208:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2209:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2210:    entry below.</dd>
                   2211: 
                   2212:    <dt>EOF</dt>
                   2213:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2214:    <a href="#data-state">data state</a>.</dd>
                   2215: 
                   2216:    <dt>Anything else</dt>
                   2217:    <dd>Start a new attribute in the current tag token. Set that
                   2218:    attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
                   2219:    the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2220:    state</a>.</dd>
                   2221: 
                   2222:   </dl><h5 id="before-attribute-value-state"><span class="secno">9.2.4.9 </span><dfn>Before attribute value state</dfn></h5>
                   2223: 
                   2224:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2225: 
                   2226:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2227:    <dt>U+000A LINE FEED (LF)</dt>
                   2228:    <dt>U+000C FORM FEED (FF)</dt>
                   2229:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2230:    <dt>U+0020 SPACE</dt>
                   2231:    <dd>Stay in the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
                   2232: 
                   2233:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2234:    <dd>Switch to the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted) state</a>.</dd>
                   2235: 
                   2236:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2237:    <dd>Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted) state</a>
                   2238:    and reconsume this input character.</dd>
                   2239: 
                   2240:    <dt>U+0027 APOSTROPHE (')</dt>
                   2241:    <dd>Switch to the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted) state</a>.</dd>
                   2242: 
                   2243:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2244:    <dd><a href="#parse-error">Parse error</a>. Emit the current tag token. Switch to
                   2245:    the <a href="#data-state">data state</a>.</dd>
                   2246: 
                   2247:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2248:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2249:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2250:    entry below.</dd>
                   2251: 
                   2252:    <dt>EOF</dt>
                   2253:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2254:    <a href="#data-state">data state</a>.</dd>
                   2255: 
                   2256:    <dt>Anything else</dt>
                   2257:    <dd>Append the <a href="#current-input-character">current input character</a> to the current
                   2258:    attribute's value. Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
                   2259:    state</a>.</dd>
                   2260: 
                   2261:   </dl><h5 id="attribute-value-double-quoted-state"><span class="secno">9.2.4.10 </span><dfn>Attribute value (double-quoted) state</dfn></h5>
                   2262: 
                   2263:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2264: 
                   2265:   <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
                   2266:    <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
                   2267:    state</a>.</dd>
                   2268: 
                   2269:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2270:    <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
                   2271:    state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
                   2272:    being U+0022 QUOTATION MARK (").</dd>
                   2273: 
                   2274:    <dt>EOF</dt>
                   2275:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2276:    <a href="#data-state">data state</a>.</dd>
                   2277: 
                   2278:    <dt>Anything else</dt>
                   2279:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2280:    value. Stay in the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted)
                   2281:    state</a>.</dd>
                   2282: 
                   2283:   </dl><h5 id="attribute-value-single-quoted-state"><span class="secno">9.2.4.11 </span><dfn>Attribute value (single-quoted) state</dfn></h5>
                   2284: 
                   2285:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2286: 
                   2287:   <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
                   2288:    <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
                   2289:    state</a>.</dd>
                   2290: 
                   2291:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2292:    <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
                   2293:    state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
                   2294:    being U+0027 APOSTROPHE (').</dd>
                   2295: 
                   2296:    <dt>EOF</dt>
                   2297:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2298:    <a href="#data-state">data state</a>.</dd>
                   2299: 
                   2300:    <dt>Anything else</dt>
                   2301:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2302:    value. Stay in the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted)
                   2303:    state</a>.</dd>
                   2304: 
                   2305:   </dl><h5 id="attribute-value-unquoted-state"><span class="secno">9.2.4.12 </span><dfn>Attribute value (unquoted) state</dfn></h5>
                   2306: 
                   2307:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2308: 
                   2309:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2310:    <dt>U+000A LINE FEED (LF)</dt>
                   2311:    <dt>U+000C FORM FEED (FF)</dt>
                   2312:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2313:    <dt>U+0020 SPACE</dt>
                   2314:    <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2315: 
                   2316:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2317:    <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
                   2318:    state</a>, with no <a href="#additional-allowed-character">additional allowed
                   2319:    character</a>.</dd>
                   2320: 
                   2321:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2322:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2323:    state</a>.</dd>
                   2324: 
                   2325:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2326:    <dt>U+0027 APOSTROPHE (')</dt>
                   2327:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2328:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2329:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2330:    entry below.</dd>
                   2331: 
                   2332:    <dt>EOF</dt>
                   2333:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2334:    <a href="#data-state">data state</a>.</dd>
                   2335: 
                   2336:    <dt>Anything else</dt>
                   2337:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2338:    value. Stay in the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
                   2339:    state</a>.</dd>
                   2340: 
                   2341:   </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>
                   2342: 
                   2343:   <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>.</p>
                   2344: 
                   2345:   <p>If nothing is returned, append a U+0026 AMPERSAND character to
                   2346:   the current attribute's value.</p>
                   2347: 
                   2348:   <p>Otherwise, append the returned character token to the current
                   2349:   attribute's value.</p>
                   2350: 
                   2351:   <p>Finally, switch back to the attribute value state that you were
                   2352:   in when were switched into this state.</p>
                   2353: 
                   2354: 
                   2355:   <h5 id="after-attribute-value-quoted-state"><span class="secno">9.2.4.14 </span><dfn>After attribute value (quoted) state</dfn></h5>
                   2356: 
                   2357:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2358: 
                   2359:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2360:    <dt>U+000A LINE FEED (LF)</dt>
                   2361:    <dt>U+000C FORM FEED (FF)</dt>
                   2362:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2363:    <dt>U+0020 SPACE</dt>
                   2364:    <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2365: 
                   2366:    <dt>U+002F SOLIDUS (/)</dt>
                   2367:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2368: 
                   2369:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2370:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2371:    state</a>.</dd>
                   2372: 
                   2373:    <dt>EOF</dt>
                   2374:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2375:    <a href="#data-state">data state</a>.</dd>
                   2376: 
                   2377:    <dt>Anything else</dt>
                   2378:    <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
                   2379:    the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2380: 
                   2381:   </dl><h5 id="self-closing-start-tag-state"><span class="secno">9.2.4.15 </span><dfn>Self-closing start tag state</dfn></h5>
                   2382: 
                   2383:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2384: 
                   2385:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2386:    <dd>Set the <i>self-closing flag</i> of the current tag
                   2387:    token. Emit the current tag token. Switch to the <a href="#data-state">data
                   2388:    state</a>.</dd>
                   2389: 
                   2390:    <dt>EOF</dt>
                   2391:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2392:    <a href="#data-state">data state</a>.</dd>
                   2393: 
                   2394:    <dt>Anything else</dt>
                   2395:    <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
                   2396:    the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2397: 
                   2398:   </dl><h5 id="bogus-comment-state"><span class="secno">9.2.4.16 </span><dfn>Bogus comment state</dfn></h5>
                   2399: 
                   2400:   <p><i>(This can only happen if the <a href="#content-model-flag">content model
                   2401:   flag</a> is set to the PCDATA state.)</i></p>
                   2402: 
                   2403:   <p>Consume every character up to and including the first U+003E
                   2404:   GREATER-THAN SIGN character (&gt;) or the end of the file (EOF),
                   2405:   whichever comes first. Emit a comment token whose data is the
                   2406:   concatenation of all the characters starting from and including
                   2407:   the character that caused the state machine to switch into the
                   2408:   bogus comment state, up to and including the character immediately
                   2409:   before the last consumed character (i.e. up to the character just
                   2410:   before the U+003E or EOF character). (If the comment was started
                   2411:   by the end of the file (EOF), the token is empty.)</p>
                   2412: 
                   2413:   <p>Switch to the <a href="#data-state">data state</a>.</p>
                   2414: 
                   2415:   <p>If the end of the file was reached, reconsume the EOF
                   2416:   character.</p>
                   2417: 
                   2418: 
                   2419:   <h5 id="markup-declaration-open-state"><span class="secno">9.2.4.17 </span><dfn>Markup declaration open state</dfn></h5>
                   2420: 
                   2421:   <p><i>(This can only happen if the <a href="#content-model-flag">content model
                   2422:   flag</a> is set to the PCDATA state.)</i></p>
                   2423: 
                   2424:   <p>If the next two characters are both U+002D HYPHEN-MINUS (-)
                   2425:   characters, consume those two characters, create a comment token
                   2426:   whose data is the empty string, and switch to the <a href="#comment-start-state">comment
                   2427:   start state</a>.</p>
                   2428: 
                   2429:   <p>Otherwise, if the next seven characters are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   2430:   case-insensitive</a> match for the word "DOCTYPE", then consume
                   2431:   those characters and switch to the <a href="#doctype-state">DOCTYPE state</a>.</p>
                   2432: 
                   2433:   <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
                   2434:   content</a>" and the <a href="#current-node">current node</a> is not an element
                   2435:   in the <a href="#html-namespace-0">HTML namespace</a> and the next seven characters are
                   2436:   an <span>ASCII case-sensitive</span> match for the string "[CDATA["
                   2437:   (the five uppercase letters "CDATA" with a U+005B LEFT SQUARE
                   2438:   BRACKET character before and after), then consume those characters
1.91      mike     2439:   and switch to the <a href="#cdata-section-state">CDATA section state</a>.</p>
1.1       mike     2440: 
                   2441:   <p>Otherwise, this is a <a href="#parse-error">parse error</a>. Switch to the
                   2442:   <a href="#bogus-comment-state">bogus comment state</a>. The next character that is
                   2443:   consumed, if any, is the first character that will be in the
                   2444:   comment.</p>
                   2445: 
                   2446: 
                   2447:   <h5 id="comment-start-state"><span class="secno">9.2.4.18 </span><dfn>Comment start state</dfn></h5>
                   2448: 
                   2449:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2450: 
                   2451:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2452:    <dd>Switch to the <a href="#comment-start-dash-state">comment start dash state</a>.</dd>
                   2453: 
                   2454:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2455:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to the
                   2456:    <a href="#data-state">data state</a>.</dd> <!-- see comment in comment end state
                   2457:    -->
                   2458: 
                   2459:    <dt>EOF</dt>
                   2460:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2461:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2462: 
                   2463:    <dt>Anything else</dt>
                   2464:    <dd>Append the input character to the comment token's
                   2465:    data. Switch to the <a href="#comment-state">comment state</a>.</dd>
                   2466: 
                   2467:   </dl><h5 id="comment-start-dash-state"><span class="secno">9.2.4.19 </span><dfn>Comment start dash state</dfn></h5>
                   2468: 
                   2469:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2470: 
                   2471:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2472:    <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
                   2473: 
                   2474:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2475:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to
                   2476:    the <a href="#data-state">data state</a>.</dd>
                   2477: 
                   2478:    <dt>EOF</dt>
                   2479:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
                   2480:    EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
                   2481:    in comment end state -->
                   2482: 
                   2483:    <dt>Anything else</dt>
                   2484:    <dd>Append a U+002D HYPHEN-MINUS (-) character and the input
                   2485:    character to the comment token's data. Switch to the
                   2486:    <a href="#comment-state">comment state</a>.</dd>
                   2487: 
                   2488:   </dl><h5 id="comment-state"><span class="secno">9.2.4.20 </span><dfn id="comment">Comment state</dfn></h5>
                   2489: 
                   2490:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2491: 
                   2492:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2493:    <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a></dd>
                   2494: 
                   2495:    <dt>EOF</dt>
                   2496:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
                   2497:    EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
                   2498:    in comment end state -->
                   2499: 
                   2500:    <dt>Anything else</dt>
                   2501:    <dd>Append the input character to the comment token's data. Stay
                   2502:    in the <a href="#comment-state">comment state</a>.</dd>
                   2503: 
                   2504:   </dl><h5 id="comment-end-dash-state"><span class="secno">9.2.4.21 </span><dfn>Comment end dash state</dfn></h5>
                   2505: 
                   2506:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2507: 
                   2508:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2509:    <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
                   2510: 
                   2511:    <dt>EOF</dt>
                   2512:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
                   2513:    EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
                   2514:    in comment end state -->
                   2515: 
                   2516:    <dt>Anything else</dt>
                   2517:    <dd>Append a U+002D HYPHEN-MINUS (-) character and the input
                   2518:    character to the comment token's data. Switch to the
                   2519:    <a href="#comment-state">comment state</a>.</dd>
                   2520: 
                   2521:   </dl><h5 id="comment-end-state"><span class="secno">9.2.4.22 </span><dfn>Comment end state</dfn></h5>
                   2522: 
                   2523:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2524: 
                   2525:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2526:    <dd>Emit the comment token. Switch to the <a href="#data-state">data
                   2527:    state</a>.</dd>
                   2528: 
                   2529:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2530:    <dd><a href="#parse-error">Parse error</a>. Append a U+002D HYPHEN-MINUS
                   2531:    (-) character to the comment token's data. Stay in the
                   2532:    <a href="#comment-end-state">comment end state</a>.</dd>
                   2533: 
                   2534:    <dt>U+0009 CHARACTER TABULATION</dt>
                   2535:    <dt>U+000A LINE FEED (LF)</dt>
                   2536:    <dt>U+000C FORM FEED (FF)</dt>
                   2537:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2538:    <dt>U+0020 SPACE</dt>
                   2539:    <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
                   2540:    characters and the input character to the comment token's
                   2541:    data. Switch to the <a href="#comment-end-space-state">comment end space state</a>.</dd>
                   2542: 
                   2543:    <dt>U+0021 EXCLAMATION MARK (!)</dt>
                   2544:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#comment-end-bang-state">comment end bang
                   2545:    state</a>.</dd>
                   2546: 
                   2547:    <dt>EOF</dt>
                   2548:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2549:    the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- For
                   2550:    security reasons: otherwise, hostile user could put a <script> in
                   2551:    a comment e.g. in a blog comment and then DOS the server so that
                   2552:    the end tag isn't read, and then the commented <script> tag would
                   2553:    be treated as live code -->
                   2554: 
                   2555:    <dt>Anything else</dt>
                   2556:    <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
                   2557:    characters and the input character to the comment token's
                   2558:    data. Switch to the <a href="#comment-state">comment state</a>.</dd>
                   2559: 
                   2560:   </dl><h5 id="comment-end-bang-state"><span class="secno">9.2.4.23 </span><dfn>Comment end bang state</dfn></h5>
                   2561: 
                   2562:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2563: 
                   2564:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2565:    <dd>Emit the comment token. Switch to the <a href="#data-state">data
                   2566:    state</a>.</dd>
                   2567: 
                   2568:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2569:    <dd>Append two U+002D HYPHEN-MINUS (-) characters and a U+0021
                   2570:    EXCLAMATION MARK (!) character to the comment token's data. Switch
                   2571:    to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
                   2572: 
                   2573:    <dt>EOF</dt>
                   2574:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2575:    the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
                   2576:    comment in comment end state -->
                   2577: 
                   2578:    <dt>Anything else</dt>
                   2579:    <dd>Append two U+002D HYPHEN-MINUS (-) characters, a U+0021
                   2580:    EXCLAMATION MARK (!) character, and the input character to the
                   2581:    comment token's data. Switch to the <a href="#comment-state">comment
                   2582:    state</a>.</dd>
                   2583: 
                   2584:   </dl><h5 id="comment-end-space-state"><span class="secno">9.2.4.24 </span><dfn>Comment end space state</dfn></h5>
                   2585: 
                   2586:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2587: 
                   2588:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2589:    <dd>Emit the comment token. Switch to the <a href="#data-state">data
                   2590:    state</a>.</dd>
                   2591: 
                   2592:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2593:    <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
                   2594: 
                   2595:    <dt>U+0009 CHARACTER TABULATION</dt>
                   2596:    <dt>U+000A LINE FEED (LF)</dt>
                   2597:    <dt>U+000C FORM FEED (FF)</dt>
                   2598:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2599:    <dt>U+0020 SPACE</dt>
                   2600:    <dd>Append the input character to the comment token's data. Stay in
                   2601:    the <a href="#comment-end-space-state">comment end space state</a>.</dd>
                   2602: 
                   2603:    <dt>EOF</dt>
                   2604:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2605:    the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
                   2606:    comment in comment end state -->
                   2607: 
                   2608:    <dt>Anything else</dt>
                   2609:    <dd>Append the input character to the comment token's data. Switch
                   2610:    to the <a href="#comment-state">comment state</a>.</dd>
                   2611: 
                   2612:   </dl><h5 id="doctype-state"><span class="secno">9.2.4.25 </span><dfn>DOCTYPE state</dfn></h5>
                   2613: 
                   2614:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2615: 
                   2616:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2617:    <dt>U+000A LINE FEED (LF)</dt>
                   2618:    <dt>U+000C FORM FEED (FF)</dt>
                   2619:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2620:    <dt>U+0020 SPACE</dt>
                   2621:    <dd>Switch to the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
                   2622: 
                   2623:    <dt>EOF</dt>
                   2624:    <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
                   2625:    <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
                   2626:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2627: 
                   2628:    <dt>Anything else</dt>
                   2629:    <dd><a href="#parse-error">Parse error</a>. Reconsume the current
                   2630:    character in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
                   2631: 
                   2632:   </dl><h5 id="before-doctype-name-state"><span class="secno">9.2.4.26 </span><dfn>Before DOCTYPE name state</dfn></h5>
                   2633: 
                   2634:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2635: 
                   2636:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2637:    <dt>U+000A LINE FEED (LF)</dt>
                   2638:    <dt>U+000C FORM FEED (FF)</dt>
                   2639:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2640:    <dt>U+0020 SPACE</dt>
                   2641:    <dd>Stay in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
                   2642: 
                   2643:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2644:    <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
                   2645:    <i>force-quirks flag</i> to <i>on</i>. Emit the token. Switch to
                   2646:    the <a href="#data-state">data state</a>.</dd>
                   2647: 
                   2648:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2649:    <dd>Create a new DOCTYPE token. Set the token's name to the
                   2650:    lowercase version of the input character (add 0x0020 to the
                   2651:    character's code point). Switch to the <a href="#doctype-name-state">DOCTYPE name
                   2652:    state</a>.</dd>
                   2653: 
                   2654:    <dt>EOF</dt>
                   2655:    <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
                   2656:    <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
                   2657:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2658: 
                   2659:    <dt>Anything else</dt>
                   2660:    <dd>Create a new DOCTYPE token. Set the token's name to the
                   2661:    <a href="#current-input-character">current input character</a>. Switch to the <a href="#doctype-name-state">DOCTYPE name
                   2662:    state</a>.</dd>
                   2663: 
                   2664:   </dl><h5 id="doctype-name-state"><span class="secno">9.2.4.27 </span><dfn>DOCTYPE name state</dfn></h5>
                   2665: 
                   2666:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2667: 
                   2668:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2669:    <dt>U+000A LINE FEED (LF)</dt>
                   2670:    <dt>U+000C FORM FEED (FF)</dt>
                   2671:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2672:    <dt>U+0020 SPACE</dt>
                   2673:    <dd>Switch to the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
                   2674: 
                   2675:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2676:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   2677:    state</a>.</dd>
                   2678: 
                   2679:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2680:    <dd>Append the lowercase version of the input character (add 0x0020
                   2681:    to the character's code point) to the current DOCTYPE token's
                   2682:    name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
                   2683: 
                   2684:    <dt>EOF</dt>
                   2685:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2686:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2687:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2688: 
                   2689:    <dt>Anything else</dt>
                   2690:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   2691:    token's name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
                   2692: 
                   2693:   </dl><h5 id="after-doctype-name-state"><span class="secno">9.2.4.28 </span><dfn>After DOCTYPE name state</dfn></h5>
                   2694: 
                   2695:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2696: 
                   2697:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2698:    <dt>U+000A LINE FEED (LF)</dt>
                   2699:    <dt>U+000C FORM FEED (FF)</dt>
                   2700:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2701:    <dt>U+0020 SPACE</dt>
                   2702:    <dd>Stay in the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
                   2703: 
                   2704:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2705:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   2706:    state</a>.</dd>
                   2707: 
                   2708:    <dt>EOF</dt>
                   2709:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2710:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2711:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2712: 
                   2713:    <dt>Anything else</dt>
                   2714:    <dd>
                   2715: 
                   2716:     <p>If the six characters starting from the <a href="#current-input-character">current input
                   2717:     character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match
                   2718:     for the word "PUBLIC", then consume those characters and switch to
                   2719:     the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</p>
                   2720: 
                   2721:     <p>Otherwise, if the six characters starting from the
                   2722:     <a href="#current-input-character">current input character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   2723:     case-insensitive</a> match for the word "SYSTEM", then consume
                   2724:     those characters and switch to the <a href="#before-doctype-system-identifier-state">before DOCTYPE system
                   2725:     identifier state</a>.</p>
                   2726: 
                   2727:     <p>Otherwise, this is the <a href="#parse-error">parse error</a>. Set the
                   2728:     DOCTYPE token's <i>force-quirks flag</i> to <i>on</i>. Switch to
                   2729:     the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</p>
                   2730: 
                   2731:    </dd>
                   2732: 
                   2733:   </dl><h5 id="before-doctype-public-identifier-state"><span class="secno">9.2.4.29 </span><dfn>Before DOCTYPE public identifier 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+0009 CHARACTER TABULATION</dt>
                   2738:    <dt>U+000A LINE FEED (LF)</dt>
                   2739:    <dt>U+000C FORM FEED (FF)</dt>
                   2740:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2741:    <dt>U+0020 SPACE</dt>
                   2742:    <dd>Stay in the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</dd>
                   2743: 
                   2744:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2745:    <dd>Set the DOCTYPE token's public identifier to the empty string
                   2746:    (not missing), then switch to the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public identifier
                   2747:    (double-quoted) state</a>.</dd>
                   2748: 
                   2749:    <dt>U+0027 APOSTROPHE (')</dt>
                   2750:    <dd>Set the DOCTYPE token's public identifier to the empty string
                   2751:    (not missing), then switch to the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public identifier
                   2752:    (single-quoted) state</a>.</dd>
                   2753: 
                   2754:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2755:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2756:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   2757:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2758: 
                   2759:    <dt>EOF</dt>
                   2760:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2761:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2762:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2763: 
                   2764:    <dt>Anything else</dt>
                   2765:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2766:    <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
                   2767:    DOCTYPE state</a>.</dd>
                   2768: 
                   2769:   </dl><h5 id="doctype-public-identifier-double-quoted-state"><span class="secno">9.2.4.30 </span><dfn>DOCTYPE public identifier (double-quoted) state</dfn></h5>
                   2770: 
                   2771:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2772: 
                   2773:   <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
                   2774:    <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
                   2775: 
                   2776:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2777:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2778:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   2779:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2780: 
                   2781:    <dt>EOF</dt>
                   2782:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2783:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2784:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2785: 
                   2786:    <dt>Anything else</dt>
                   2787:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   2788:    token's public identifier. Stay in the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public
                   2789:    identifier (double-quoted) state</a>.</dd>
                   2790: 
                   2791:   </dl><h5 id="doctype-public-identifier-single-quoted-state"><span class="secno">9.2.4.31 </span><dfn>DOCTYPE public identifier (single-quoted) state</dfn></h5>
                   2792: 
                   2793:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2794: 
                   2795:   <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
                   2796:    <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
                   2797: 
                   2798:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2799:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2800:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   2801:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2802: 
                   2803:    <dt>EOF</dt>
                   2804:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2805:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2806:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2807: 
                   2808:    <dt>Anything else</dt>
                   2809:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   2810:    token's public identifier. Stay in the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public
                   2811:    identifier (single-quoted) state</a>.</dd>
                   2812: 
                   2813:   </dl><h5 id="after-doctype-public-identifier-state"><span class="secno">9.2.4.32 </span><dfn>After DOCTYPE public identifier state</dfn></h5>
                   2814: 
                   2815:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2816: 
                   2817:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2818:    <dt>U+000A LINE FEED (LF)</dt>
                   2819:    <dt>U+000C FORM FEED (FF)</dt>
                   2820:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2821:    <dt>U+0020 SPACE</dt>
                   2822:    <dd>Stay in the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
                   2823: 
                   2824:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2825:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   2826:    (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
                   2827:    (double-quoted) state</a>.</dd>
                   2828: 
                   2829:    <dt>U+0027 APOSTROPHE (')</dt>
                   2830:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   2831:    (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
                   2832:    (single-quoted) state</a>.</dd>
                   2833: 
                   2834:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2835:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   2836:    state</a>.</dd>
                   2837: 
                   2838:    <dt>EOF</dt>
                   2839:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2840:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2841:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2842: 
                   2843:    <dt>Anything else</dt>
                   2844:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2845:    <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
                   2846:    DOCTYPE state</a>.</dd>
                   2847: 
                   2848:   </dl><h5 id="before-doctype-system-identifier-state"><span class="secno">9.2.4.33 </span><dfn>Before DOCTYPE system identifier state</dfn></h5>
                   2849: 
                   2850:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2851: 
                   2852:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2853:    <dt>U+000A LINE FEED (LF)</dt>
                   2854:    <dt>U+000C FORM FEED (FF)</dt>
                   2855:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2856:    <dt>U+0020 SPACE</dt>
                   2857:    <dd>Stay in the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier state</a>.</dd>
                   2858: 
                   2859:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2860:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   2861:    (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
                   2862:    (double-quoted) state</a>.</dd>
                   2863: 
                   2864:    <dt>U+0027 APOSTROPHE (')</dt>
                   2865:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   2866:    (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
                   2867:    (single-quoted) state</a>.</dd>
                   2868: 
                   2869:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2870:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2871:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   2872:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2873: 
                   2874:    <dt>EOF</dt>
                   2875:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2876:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2877:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2878: 
                   2879:    <dt>Anything else</dt>
                   2880:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2881:    <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
                   2882:    DOCTYPE state</a>.</dd>
                   2883: 
                   2884:   </dl><h5 id="doctype-system-identifier-double-quoted-state"><span class="secno">9.2.4.34 </span><dfn>DOCTYPE system identifier (double-quoted) state</dfn></h5>
                   2885: 
                   2886:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2887: 
                   2888:   <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
                   2889:    <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
                   2890: 
                   2891:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2892:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2893:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   2894:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2895: 
                   2896:    <dt>EOF</dt>
                   2897:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2898:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2899:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2900: 
                   2901:    <dt>Anything else</dt>
                   2902:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   2903:    token's system identifier. Stay in the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system
                   2904:    identifier (double-quoted) state</a>.</dd>
                   2905: 
                   2906:   </dl><h5 id="doctype-system-identifier-single-quoted-state"><span class="secno">9.2.4.35 </span><dfn>DOCTYPE system identifier (single-quoted) state</dfn></h5>
                   2907: 
                   2908:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2909: 
                   2910:   <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
                   2911:    <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
                   2912: 
                   2913:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2914:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2915:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   2916:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2917: 
                   2918:    <dt>EOF</dt>
                   2919:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2920:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2921:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2922: 
                   2923:    <dt>Anything else</dt>
                   2924:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   2925:    token's system identifier. Stay in the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system
                   2926:    identifier (single-quoted) state</a>.</dd>
                   2927: 
                   2928:   </dl><h5 id="after-doctype-system-identifier-state"><span class="secno">9.2.4.36 </span><dfn>After DOCTYPE system identifier state</dfn></h5>
                   2929: 
                   2930:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2931: 
                   2932:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2933:    <dt>U+000A LINE FEED (LF)</dt>
                   2934:    <dt>U+000C FORM FEED (FF)</dt>
                   2935:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2936:    <dt>U+0020 SPACE</dt>
                   2937:    <dd>Stay in the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
                   2938: 
                   2939:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2940:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   2941:    state</a>.</dd>
                   2942: 
                   2943:    <dt>EOF</dt>
                   2944:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2945:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2946:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2947: 
                   2948:    <dt>Anything else</dt>
                   2949:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-doctype-state">bogus DOCTYPE
                   2950:    state</a>. (This does <em>not</em> set the DOCTYPE token's
                   2951:    <i>force-quirks flag</i> to <i>on</i>.)</dd>
                   2952: 
                   2953:   </dl><h5 id="bogus-doctype-state"><span class="secno">9.2.4.37 </span><dfn>Bogus DOCTYPE state</dfn></h5>
                   2954: 
                   2955:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2956: 
                   2957:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2958:    <dd>Emit the DOCTYPE token. Switch to the <a href="#data-state">data
                   2959:    state</a>.</dd>
                   2960: 
                   2961:    <dt>EOF</dt>
                   2962:    <dd>Emit the DOCTYPE token. Reconsume the EOF character in the
                   2963:    <a href="#data-state">data state</a>.</dd>
                   2964: 
                   2965:    <dt>Anything else</dt>
                   2966:    <dd>Stay in the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</dd>
                   2967: 
                   2968:   </dl><h5 id="cdata-section-state"><span class="secno">9.2.4.38 </span><dfn>CDATA section state</dfn></h5>
                   2969: 
                   2970:   <p><i>(This can only happen if the <a href="#content-model-flag">content model
1.91      mike     2971:   flag</a> is set to the PCDATA state.)</i></p>
1.1       mike     2972: 
                   2973:   <p>Consume every character up to the next occurrence of the three
                   2974:   character sequence U+005D RIGHT SQUARE BRACKET U+005D RIGHT SQUARE
                   2975:   BRACKET U+003E GREATER-THAN SIGN (<code title="">]]&gt;</code>), or the
                   2976:   end of the file (EOF), whichever comes first. Emit a series of
                   2977:   character tokens consisting of all the characters consumed except
                   2978:   the matching three character sequence at the end (if one was found
                   2979:   before the end of the file).</p>
                   2980: 
                   2981:   <p>Switch to the <a href="#data-state">data state</a>.</p>
                   2982: 
                   2983:   <p>If the end of the file was reached, reconsume the EOF
                   2984:   character.</p>
                   2985: 
                   2986: 
                   2987: 
                   2988:   <h5 id="tokenizing-character-references"><span class="secno">9.2.4.39 </span>Tokenizing character references</h5>
                   2989: 
                   2990:   <p>This section defines how to <dfn id="consume-a-character-reference">consume a character
                   2991:   reference</dfn>. This definition is used when parsing character
                   2992:   references <a href="#character-reference-data-state" title="character reference data state">in
                   2993:   text</a> and <a href="#character-reference-in-attribute-value-state" title="character reference in attribute value
                   2994:   state">in attributes</a>.</p>
                   2995: 
                   2996:   <p>The behavior depends on the identity of the next character (the
                   2997:   one immediately after the U+0026 AMPERSAND character):</p>
                   2998: 
                   2999:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3000:    <dt>U+000A LINE FEED (LF)</dt>
                   3001:    <dt>U+000C FORM FEED (FF)</dt>
                   3002:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3003:    <dt>U+0020 SPACE</dt>
                   3004:    <dt>U+003C LESS-THAN SIGN</dt>
                   3005:    <dt>U+0026 AMPERSAND</dt>
                   3006:    <dt>EOF</dt>
                   3007:    <dt>The <dfn id="additional-allowed-character">additional allowed character</dfn>, if there is one</dt>
                   3008: 
                   3009:    <dd>Not a character reference. No characters are consumed, and
                   3010:    nothing is returned. (This is not an error, either.)</dd>
                   3011: 
                   3012: 
                   3013:    <dt>U+0023 NUMBER SIGN (#)</dt>
                   3014: 
                   3015:    <dd>
                   3016: 
                   3017:     <p>Consume the U+0023 NUMBER SIGN.</p>
                   3018: 
                   3019:     <p>The behavior further depends on the character after the U+0023
                   3020:     NUMBER SIGN:</p>
                   3021: 
                   3022:     <dl class="switch"><dt>U+0078 LATIN SMALL LETTER X</dt>
                   3023:      <dt>U+0058 LATIN CAPITAL LETTER X</dt>
                   3024: 
                   3025:      <dd>
                   3026: 
                   3027:       <p>Consume the X.</p>
                   3028: 
                   3029:       <p>Follow the steps below, but using the range of characters
                   3030:       U+0030 DIGIT ZERO through to U+0039 DIGIT NINE, U+0061 LATIN
                   3031:       SMALL LETTER A through to U+0066 LATIN SMALL LETTER F, and
                   3032:       U+0041 LATIN CAPITAL LETTER A, through to U+0046 LATIN CAPITAL
                   3033:       LETTER F (in other words, 0-9, A-F, a-f).</p>
                   3034: 
                   3035:       <p>When it comes to interpreting the number, interpret it as a
                   3036:       hexadecimal number.</p>
                   3037: 
                   3038:      </dd>
                   3039: 
                   3040: 
                   3041:      <dt>Anything else</dt>
                   3042: 
                   3043:      <dd>
                   3044: 
                   3045:       <p>Follow the steps below, but using the range of characters
                   3046:       U+0030 DIGIT ZERO through to U+0039 DIGIT NINE (i.e. just
                   3047:       0-9).</p>
                   3048: 
                   3049:       <p>When it comes to interpreting the number, interpret it as a
                   3050:       decimal number.</p>
                   3051: 
                   3052:      </dd>
                   3053: 
                   3054:     </dl><p>Consume as many characters as match the range of characters
                   3055:     given above.</p>
                   3056: 
                   3057:     <p>If no characters match the range, then don't consume any
                   3058:     characters (and unconsume the U+0023 NUMBER SIGN character and, if
                   3059:     appropriate, the X character). This is a <a href="#parse-error">parse
                   3060:     error</a>; nothing is returned.</p>
                   3061: 
                   3062:     <p>Otherwise, if the next character is a U+003B SEMICOLON, consume
                   3063:     that too. If it isn't, there is a <a href="#parse-error">parse
                   3064:     error</a>.</p>
                   3065: 
                   3066:     <p>If one or more characters match the range, then take them all
                   3067:     and interpret the string of characters as a number (either
                   3068:     hexadecimal or decimal as appropriate).</p>
                   3069: 
                   3070:     <p>If that number is one of the numbers in the first column of the
                   3071:     following table, then this is a <a href="#parse-error">parse error</a>. Find the
                   3072:     row with that number in the first column, and return a character
                   3073:     token for the Unicode character given in the second column of that
                   3074:     row.</p>
                   3075: 
                   3076:     <table><thead><tr><th>Number </th><th colspan="2">Unicode character
                   3077:      </th></tr></thead><tbody><tr><td>0x00 </td><td>U+FFFD </td><td>REPLACEMENT CHARACTER
                   3078:       </td></tr><tr><td>0x0D </td><td>U+000A </td><td>LINE FEED (LF)
                   3079:       </td></tr><tr><td>0x80 </td><td>U+20AC </td><td>EURO SIGN ('&#8364;')
                   3080:       </td></tr><tr><td>0x81 </td><td>U+0081 </td><td>&lt;control&gt;
                   3081:       </td></tr><tr><td>0x82 </td><td>U+201A </td><td>SINGLE LOW-9 QUOTATION MARK ('&#8218;')
                   3082:       </td></tr><tr><td>0x83 </td><td>U+0192 </td><td>LATIN SMALL LETTER F WITH HOOK ('&#402;')
                   3083:       </td></tr><tr><td>0x84 </td><td>U+201E </td><td>DOUBLE LOW-9 QUOTATION MARK ('&#8222;')
                   3084:       </td></tr><tr><td>0x85 </td><td>U+2026 </td><td>HORIZONTAL ELLIPSIS ('&#8230;')
                   3085:       </td></tr><tr><td>0x86 </td><td>U+2020 </td><td>DAGGER ('&#8224;')
                   3086:       </td></tr><tr><td>0x87 </td><td>U+2021 </td><td>DOUBLE DAGGER ('&#8225;')
                   3087:       </td></tr><tr><td>0x88 </td><td>U+02C6 </td><td>MODIFIER LETTER CIRCUMFLEX ACCENT ('&#710;')
                   3088:       </td></tr><tr><td>0x89 </td><td>U+2030 </td><td>PER MILLE SIGN ('&#8240;')
                   3089:       </td></tr><tr><td>0x8A </td><td>U+0160 </td><td>LATIN CAPITAL LETTER S WITH CARON ('&#352;')
                   3090:       </td></tr><tr><td>0x8B </td><td>U+2039 </td><td>SINGLE LEFT-POINTING ANGLE QUOTATION MARK ('&#8249;')
                   3091:       </td></tr><tr><td>0x8C </td><td>U+0152 </td><td>LATIN CAPITAL LIGATURE OE ('&#338;')
                   3092:       </td></tr><tr><td>0x8D </td><td>U+008D </td><td>&lt;control&gt;
                   3093:       </td></tr><tr><td>0x8E </td><td>U+017D </td><td>LATIN CAPITAL LETTER Z WITH CARON ('&#381;')
                   3094:       </td></tr><tr><td>0x8F </td><td>U+008F </td><td>&lt;control&gt;
                   3095:       </td></tr><tr><td>0x90 </td><td>U+0090 </td><td>&lt;control&gt;
                   3096:       </td></tr><tr><td>0x91 </td><td>U+2018 </td><td>LEFT SINGLE QUOTATION MARK ('&#8216;')
                   3097:       </td></tr><tr><td>0x92 </td><td>U+2019 </td><td>RIGHT SINGLE QUOTATION MARK ('&#8217;')
                   3098:       </td></tr><tr><td>0x93 </td><td>U+201C </td><td>LEFT DOUBLE QUOTATION MARK ('&#8220;')
                   3099:       </td></tr><tr><td>0x94 </td><td>U+201D </td><td>RIGHT DOUBLE QUOTATION MARK ('&#8221;')
                   3100:       </td></tr><tr><td>0x95 </td><td>U+2022 </td><td>BULLET ('&#8226;')
                   3101:       </td></tr><tr><td>0x96 </td><td>U+2013 </td><td>EN DASH ('&#8211;')
                   3102:       </td></tr><tr><td>0x97 </td><td>U+2014 </td><td>EM DASH ('&#8212;')
                   3103:       </td></tr><tr><td>0x98 </td><td>U+02DC </td><td>SMALL TILDE ('&#732;')
                   3104:       </td></tr><tr><td>0x99 </td><td>U+2122 </td><td>TRADE MARK SIGN ('&#8482;')
                   3105:       </td></tr><tr><td>0x9A </td><td>U+0161 </td><td>LATIN SMALL LETTER S WITH CARON ('&#353;')
                   3106:       </td></tr><tr><td>0x9B </td><td>U+203A </td><td>SINGLE RIGHT-POINTING ANGLE QUOTATION MARK ('&#8250;')
                   3107:       </td></tr><tr><td>0x9C </td><td>U+0153 </td><td>LATIN SMALL LIGATURE OE ('&#339;')
                   3108:       </td></tr><tr><td>0x9D </td><td>U+009D </td><td>&lt;control&gt;
                   3109:       </td></tr><tr><td>0x9E </td><td>U+017E </td><td>LATIN SMALL LETTER Z WITH CARON ('&#382;')
                   3110:       </td></tr><tr><td>0x9F </td><td>U+0178 </td><td>LATIN CAPITAL LETTER Y WITH DIAERESIS ('&#376;')
1.18      mike     3111:     </td></tr></tbody></table><p>Otherwise, if the number is greater than 0x10FFFF, then this is
                   3112:     a <a href="#parse-error">parse error</a>. Return a U+FFFD REPLACEMENT
                   3113:     CHARACTER.</p>
                   3114: 
                   3115:     <p>Otherwise, return a character token for the Unicode character
1.1       mike     3116:     whose code point is that number.
                   3117: 
                   3118:     <!-- this is the same as the equivalent list in the input stream
                   3119:     section -->
                   3120:     If the number is in the range 0x0001 to 0x0008, <!-- HT, LF
                   3121:     allowed --> <!-- U+000B is in the next list --> <!-- FF, CR
                   3122:     allowed --> 0x000E to 0x001F, <!-- ASCII allowed --> 0x007F <!--to
                   3123:     0x0084, (0x0085 NEL not allowed), 0x0086--> to 0x009F, 0xD800 to
                   3124:     0xDFFF<!-- surrogates not allowed -->, 0xFDD0 to 0xFDEF, or is one
                   3125:     of 0x000B, 0xFFFE, 0xFFFF, 0x1FFFE, 0x1FFFF, 0x2FFFE, 0x2FFFF,
                   3126:     0x3FFFE, 0x3FFFF, 0x4FFFE, 0x4FFFF, 0x5FFFE, 0x5FFFF, 0x6FFFE,
                   3127:     0x6FFFF, 0x7FFFE, 0x7FFFF, 0x8FFFE, 0x8FFFF, 0x9FFFE, 0x9FFFF,
                   3128:     0xAFFFE, 0xAFFFF, 0xBFFFE, 0xBFFFF, 0xCFFFE, 0xCFFFF, 0xDFFFE,
                   3129:     0xDFFFF, 0xEFFFE, 0xEFFFF, 0xFFFFE, 0xFFFFF, 0x10FFFE, or
1.18      mike     3130:     0x10FFFF, then this is a <a href="#parse-error">parse error</a>.</p>
1.1       mike     3131: 
                   3132:    </dd>
                   3133: 
                   3134: 
                   3135:    <dt>Anything else</dt>
                   3136: 
                   3137:    <dd>
                   3138: 
                   3139:     <p>Consume the maximum number of characters possible, with the
                   3140:     consumed characters matching one of the identifiers in the first
                   3141:     column of the <a href="named-character-references.html#named-character-references">named character references</a> table (in a
                   3142:     <a href="infrastructure.html#case-sensitive">case-sensitive</a> manner).</p>
                   3143: 
                   3144:     <p>If no match can be made, then this is a <a href="#parse-error">parse
                   3145:     error</a>. No characters are consumed, and nothing is
                   3146:     returned.</p>
                   3147: 
                   3148:     <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>
                   3149: 
                   3150:     <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
                   3151:     attribute</a>, and the last character matched is not a U+003B
                   3152:     SEMICOLON (<code title="">;</code>), and the next character is in
                   3153:     the range U+0030 DIGIT ZERO to U+0039 DIGIT NINE, U+0041 LATIN
                   3154:     CAPITAL LETTER A to U+005A LATIN CAPITAL LETTER Z, or U+0061 LATIN
                   3155:     SMALL LETTER A to U+007A LATIN SMALL LETTER Z, then, for
                   3156:     historical reasons, all the characters that were matched after the
                   3157:     U+0026 AMPERSAND (&amp;) must be unconsumed, and nothing is
                   3158:     returned.</p>
                   3159: 
                   3160:     <p>Otherwise, return a character token for the character
                   3161:     corresponding to the character reference name (as given by the
                   3162:     second column of the <a href="named-character-references.html#named-character-references">named character references</a>
                   3163:     table).</p>
                   3164: 
                   3165:     <div class="example">
                   3166: 
                   3167:      <p>If the markup contains <code title="">I'm &amp;notit; I tell
                   3168:      you</code>, the character reference is parsed as "not", as in,
                   3169:      <code title="">I'm &#172;it; I tell you</code>. But if the markup
                   3170:      was <code title="">I'm &amp;notin; I tell you</code>, the
                   3171:      character reference would be parsed as "notin;", resulting in
                   3172:      <code title="">I'm &#8713; I tell you</code>.</p>
                   3173: 
                   3174:     </div>
                   3175: 
                   3176:    </dd>
                   3177: 
                   3178:   </dl><h4 id="tree-construction"><span class="secno">9.2.5 </span><dfn>Tree construction</dfn></h4>
                   3179: 
                   3180:   <p>The input to the tree construction stage is a sequence of tokens
                   3181:   from the <a href="#tokenization">tokenization</a> stage. The tree construction
                   3182:   stage is associated with a DOM <code>Document</code> object when a
                   3183:   parser is created. The "output" of this stage consists of
                   3184:   dynamically modifying or extending that document's DOM tree.</p>
                   3185: 
                   3186:   <p>This specification does not define when an interactive user agent
                   3187:   has to render the <code>Document</code> so that it is available to
                   3188:   the user, or when it has to begin accepting user input.</p>
                   3189: 
                   3190:   <p>As each token is emitted from the tokenizer, the user agent must
                   3191:   process the token according to the rules given in the section
                   3192:   corresponding to the current <a href="#insertion-mode">insertion mode</a>.</p>
                   3193: 
                   3194:   <p>When the steps below require the UA to <dfn id="insert-a-character">insert a
                   3195:   character</dfn> into a node, if that node has a child immediately
                   3196:   before where the character is to be inserted, and that child is a
                   3197:   <code>Text</code> node, and that <code>Text</code> node was the last
                   3198:   node that the parser inserted into the document, then the character
                   3199:   must be appended to that <code>Text</code> node; otherwise, a new
                   3200:   <code>Text</code> node whose data is just that character must be
                   3201:   inserted in the appropriate place.</p>
                   3202: 
                   3203:   <div class="example">
                   3204: 
                   3205:    <p>Here are some sample inputs to the parser and the corresponding
                   3206:    number of text nodes that they result in, assuming a user agent
                   3207:    that executes scripts.</p>
                   3208: 
                   3209:    <table><thead><tr><th>Input </th><th>Number of text nodes
                   3210:     </th></tr></thead><tbody><tr><td><pre>A&lt;script&gt;
                   3211: var&#160;script&#160;=&#160;document.getElementsByTagName('script')[0];
                   3212: document.body.removeChild(script);
                   3213: &lt;/script&gt;B</pre>
                   3214:       </td><td>Two adjacent text nodes in the document, containing "A" and "B".
                   3215:      </td></tr><tr><td><pre>A&lt;script&gt;
                   3216: var&#160;text&#160;=&#160;document.createTextNode('B');
                   3217: document.body.appendChild(text);
                   3218: &lt;/script&gt;C</pre>
                   3219:       </td><td>Four text nodes; "A" before the script, the script's contents, "B" after the script, and then, immediately after that, "C".
                   3220:      </td></tr><tr><td><pre>A&lt;script&gt;
                   3221: var&#160;text&#160;=&#160;document.getElementsByTagName('script')[0].firstChild;
                   3222: text.data&#160;=&#160;'B';
                   3223: document.body.appendChild(text);
                   3224: &lt;/script&gt;B</pre>
                   3225:       </td><td>Two adjacent text nodes in the document, containing "A" and "BB".
                   3226:      </td></tr><tr><td><pre>A&lt;table&gt;B&lt;tr&gt;C&lt;/tr&gt;C&lt;/table&gt;</pre>
                   3227:       </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>.)
                   3228:      </td></tr><tr><td><pre>A&lt;table&gt;&lt;tr&gt;&#160;B&lt;/tr&gt;&#160;B&lt;/table&gt;</pre>
                   3229:       </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>.)
                   3230:      </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>
                   3231:       </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.)
                   3232:    </td></tr></tbody></table></div>
                   3233: 
                   3234:   <p id="mutation-during-parsing">DOM mutation events must not fire
                   3235:   for changes caused by the UA parsing the document. (Conceptually,
                   3236:   the parser is not mutating the DOM, it is constructing it.) This
1.159     mike     3237:   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     3238: 
                   3239:   <p class="note">Not all of the tag names mentioned below are
                   3240:   conformant tag names in this specification; many are included to
                   3241:   handle legacy content. They still form part of the algorithm that
                   3242:   implementations are required to implement to claim conformance.</p>
                   3243: 
                   3244:   <p class="note">The algorithm described below places no limit on the
                   3245:   depth of the DOM tree generated, or on the length of tag names,
                   3246:   attribute names, attribute values, text nodes, etc. While
                   3247:   implementors are encouraged to avoid arbitrary limits, it is
                   3248:   recognized that <a href="infrastructure.html#hardwareLimitations">practical
                   3249:   concerns</a> will likely force user agents to impose nesting
                   3250:   depths.</p>
                   3251: 
                   3252: 
                   3253:   <h5 id="creating-and-inserting-elements"><span class="secno">9.2.5.1 </span>Creating and inserting elements</h5>
                   3254: 
                   3255:   <p>When the steps below require the UA to <dfn id="create-an-element-for-the-token" title="create an
                   3256:   element for the token">create an element for a token</dfn> in a
                   3257:   particular namespace, the UA must create a node implementing the
                   3258:   interface appropriate for the element type corresponding to the tag
                   3259:   name of the token in the given namespace (as given in the
                   3260:   specification that defines that element, e.g. for an <code><a href="text-level-semantics.html#the-a-element">a</a></code>
                   3261:   element in the <a href="#html-namespace-0">HTML namespace</a>, this specification
                   3262:   defines it to be the <code><a href="text-level-semantics.html#htmlanchorelement">HTMLAnchorElement</a></code> interface), with
                   3263:   the tag name being the name of that element, with the node being in
                   3264:   the given namespace, and with the attributes on the node being those
                   3265:   given in the given token.</p>
                   3266: 
                   3267:   <p>The interface appropriate for an element in the <a href="#html-namespace-0">HTML
                   3268:   namespace</a> that is not defined in this specification is
1.44      mike     3269:   <code><a href="dom.html#htmlunknownelement">HTMLUnknownElement</a></code>. Element in other namespaces whose
1.1       mike     3270:   interface is not defined by that namespace's specification must use
                   3271:   the interface <code>Element</code>.</p>
                   3272: 
                   3273:   <p>When a <a href="forms.html#category-reset" title="category-reset">resettable</a> element is
                   3274:   created in this manner, its <a href="forms.html#concept-form-reset-control" title="concept-form-reset-control">reset algorithm</a> must be
                   3275:   invoked once the attributes are set. (This initializes the element's
                   3276:   <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
                   3277:   attributes.)</p>
                   3278: 
                   3279:   <hr><p>When the steps below require the UA to <dfn id="insert-an-html-element">insert an HTML
                   3280:   element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
                   3281:   for the token</a> in the <a href="#html-namespace-0">HTML namespace</a>, and then
                   3282:   append this node to the <a href="#current-node">current node</a>, and push it onto
                   3283:   the <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
                   3284:   <a href="#current-node">current node</a>.</p>
                   3285: 
                   3286:   <p>The steps below may also require that the UA insert an HTML
                   3287:   element in a particular place, in which case the UA must follow the
                   3288:   same steps except that it must insert or append the new node in the
                   3289:   location specified instead of appending it to the <a href="#current-node">current
                   3290:   node</a>. (This happens in particular during the parsing of
                   3291:   tables with invalid content.)</p>
                   3292: 
                   3293:   <p>If an element created by the <a href="#insert-an-html-element">insert an HTML element</a>
                   3294:   algorithm is a <a href="forms.html#form-associated-element">form-associated element</a>, and the
                   3295:   <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is not null,
                   3296:   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
                   3297:   <a href="forms.html#concept-form-association" title="concept-form-association">associate</a> the newly
                   3298:   created element with the <code><a href="forms.html#the-form-element">form</a></code> element pointed to by the
                   3299:   <a href="#form-element-pointer"><code title="">form</code> element pointer</a> before
                   3300:   inserting it wherever it is to be inserted.</p>
                   3301: 
                   3302:   <hr><p>When the steps below require the UA to <dfn id="insert-a-foreign-element">insert a foreign
                   3303:   element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
                   3304:   for the token</a> in the given namespace, and then append this
                   3305:   node to the <a href="#current-node">current node</a>, and push it onto the
                   3306:   <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
                   3307:   <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>
                   3308:   whose value is not exactly the same as the element's namespace, that
                   3309:   is a <a href="#parse-error">parse error</a>. Similarly, if the newly created
                   3310:   element has an <code title="">xmlns:xlink</code> attribute in the
                   3311:   <a href="#xmlns-namespace">XMLNS namespace</a> whose value is not the <a href="#xlink-namespace">XLink
                   3312:   Namespace</a>, that is a <a href="#parse-error">parse error</a>.</p>
                   3313: 
                   3314:   <p>When the steps below require the user agent to <dfn id="adjust-mathml-attributes">adjust MathML
                   3315:   attributes</dfn> for a token, then, if the token has an attribute
                   3316:   named <code title="">definitionurl</code>, change its name to <code title="">definitionURL</code> (note the case difference).</p>
                   3317: 
                   3318:   <p>When the steps below require the user agent to <dfn id="adjust-svg-attributes">adjust SVG
                   3319:   attributes</dfn> for a token, then, for each attribute on the token
                   3320:   whose attribute name is one of the ones in the first column of the
                   3321:   following table, change the attribute's name to the name given in
                   3322:   the corresponding cell in the second column. (This fixes the case of
                   3323:   SVG attributes that are not all lowercase.)</p>
                   3324: 
                   3325:   <table><thead><tr><th> Attribute name on token </th><th> Attribute name on element
                   3326:    </th></tr></thead><tbody><tr><td> <code title="">attributename</code> </td><td> <code title="">attributeName</code>
                   3327:     </td></tr><tr><td> <code title="">attributetype</code> </td><td> <code title="">attributeType</code>
                   3328:     </td></tr><tr><td> <code title="">basefrequency</code> </td><td> <code title="">baseFrequency</code>
                   3329:     </td></tr><tr><td> <code title="">baseprofile</code> </td><td> <code title="">baseProfile</code>
                   3330:     </td></tr><tr><td> <code title="">calcmode</code> </td><td> <code title="">calcMode</code>
                   3331:     </td></tr><tr><td> <code title="">clippathunits</code> </td><td> <code title="">clipPathUnits</code>
                   3332:     </td></tr><tr><td> <code title="">contentscripttype</code> </td><td> <code title="">contentScriptType</code>
                   3333:     </td></tr><tr><td> <code title="">contentstyletype</code> </td><td> <code title="">contentStyleType</code>
                   3334:     </td></tr><tr><td> <code title="">diffuseconstant</code> </td><td> <code title="">diffuseConstant</code>
                   3335:     </td></tr><tr><td> <code title="">edgemode</code> </td><td> <code title="">edgeMode</code>
                   3336:     </td></tr><tr><td> <code title="">externalresourcesrequired</code> </td><td> <code title="">externalResourcesRequired</code>
                   3337:     </td></tr><tr><td> <code title="">filterres</code> </td><td> <code title="">filterRes</code>
                   3338:     </td></tr><tr><td> <code title="">filterunits</code> </td><td> <code title="">filterUnits</code>
                   3339:     </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
                   3340:     </td></tr><tr><td> <code title="">gradienttransform</code> </td><td> <code title="">gradientTransform</code>
                   3341:     </td></tr><tr><td> <code title="">gradientunits</code> </td><td> <code title="">gradientUnits</code>
                   3342:     </td></tr><tr><td> <code title="">kernelmatrix</code> </td><td> <code title="">kernelMatrix</code>
                   3343:     </td></tr><tr><td> <code title="">kernelunitlength</code> </td><td> <code title="">kernelUnitLength</code>
                   3344:     </td></tr><tr><td> <code title="">keypoints</code> </td><td> <code title="">keyPoints</code>
                   3345:     </td></tr><tr><td> <code title="">keysplines</code> </td><td> <code title="">keySplines</code>
                   3346:     </td></tr><tr><td> <code title="">keytimes</code> </td><td> <code title="">keyTimes</code>
                   3347:     </td></tr><tr><td> <code title="">lengthadjust</code> </td><td> <code title="">lengthAdjust</code>
                   3348:     </td></tr><tr><td> <code title="">limitingconeangle</code> </td><td> <code title="">limitingConeAngle</code>
                   3349:     </td></tr><tr><td> <code title="">markerheight</code> </td><td> <code title="">markerHeight</code>
                   3350:     </td></tr><tr><td> <code title="">markerunits</code> </td><td> <code title="">markerUnits</code>
                   3351:     </td></tr><tr><td> <code title="">markerwidth</code> </td><td> <code title="">markerWidth</code>
                   3352:     </td></tr><tr><td> <code title="">maskcontentunits</code> </td><td> <code title="">maskContentUnits</code>
                   3353:     </td></tr><tr><td> <code title="">maskunits</code> </td><td> <code title="">maskUnits</code>
                   3354:     </td></tr><tr><td> <code title="">numoctaves</code> </td><td> <code title="">numOctaves</code>
                   3355:     </td></tr><tr><td> <code title="">pathlength</code> </td><td> <code title="">pathLength</code>
                   3356:     </td></tr><tr><td> <code title="">patterncontentunits</code> </td><td> <code title="">patternContentUnits</code>
                   3357:     </td></tr><tr><td> <code title="">patterntransform</code> </td><td> <code title="">patternTransform</code>
                   3358:     </td></tr><tr><td> <code title="">patternunits</code> </td><td> <code title="">patternUnits</code>
                   3359:     </td></tr><tr><td> <code title="">pointsatx</code> </td><td> <code title="">pointsAtX</code>
                   3360:     </td></tr><tr><td> <code title="">pointsaty</code> </td><td> <code title="">pointsAtY</code>
                   3361:     </td></tr><tr><td> <code title="">pointsatz</code> </td><td> <code title="">pointsAtZ</code>
                   3362:     </td></tr><tr><td> <code title="">preservealpha</code> </td><td> <code title="">preserveAlpha</code>
                   3363:     </td></tr><tr><td> <code title="">preserveaspectratio</code> </td><td> <code title="">preserveAspectRatio</code>
                   3364:     </td></tr><tr><td> <code title="">primitiveunits</code> </td><td> <code title="">primitiveUnits</code>
                   3365:     </td></tr><tr><td> <code title="">refx</code> </td><td> <code title="">refX</code>
                   3366:     </td></tr><tr><td> <code title="">refy</code> </td><td> <code title="">refY</code>
                   3367:     </td></tr><tr><td> <code title="">repeatcount</code> </td><td> <code title="">repeatCount</code>
                   3368:     </td></tr><tr><td> <code title="">repeatdur</code> </td><td> <code title="">repeatDur</code>
                   3369:     </td></tr><tr><td> <code title="">requiredextensions</code> </td><td> <code title="">requiredExtensions</code>
                   3370:     </td></tr><tr><td> <code title="">requiredfeatures</code> </td><td> <code title="">requiredFeatures</code>
                   3371:     </td></tr><tr><td> <code title="">specularconstant</code> </td><td> <code title="">specularConstant</code>
                   3372:     </td></tr><tr><td> <code title="">specularexponent</code> </td><td> <code title="">specularExponent</code>
                   3373:     </td></tr><tr><td> <code title="">spreadmethod</code> </td><td> <code title="">spreadMethod</code>
                   3374:     </td></tr><tr><td> <code title="">startoffset</code> </td><td> <code title="">startOffset</code>
                   3375:     </td></tr><tr><td> <code title="">stddeviation</code> </td><td> <code title="">stdDeviation</code>
                   3376:     </td></tr><tr><td> <code title="">stitchtiles</code> </td><td> <code title="">stitchTiles</code>
                   3377:     </td></tr><tr><td> <code title="">surfacescale</code> </td><td> <code title="">surfaceScale</code>
                   3378:     </td></tr><tr><td> <code title="">systemlanguage</code> </td><td> <code title="">systemLanguage</code>
                   3379:     </td></tr><tr><td> <code title="">tablevalues</code> </td><td> <code title="">tableValues</code>
                   3380:     </td></tr><tr><td> <code title="">targetx</code> </td><td> <code title="">targetX</code>
                   3381:     </td></tr><tr><td> <code title="">targety</code> </td><td> <code title="">targetY</code>
                   3382:     </td></tr><tr><td> <code title="">textlength</code> </td><td> <code title="">textLength</code>
                   3383:     </td></tr><tr><td> <code title="">viewbox</code> </td><td> <code title="">viewBox</code>
                   3384:     </td></tr><tr><td> <code title="">viewtarget</code> </td><td> <code title="">viewTarget</code>
                   3385:     </td></tr><tr><td> <code title="">xchannelselector</code> </td><td> <code title="">xChannelSelector</code>
                   3386:     </td></tr><tr><td> <code title="">ychannelselector</code> </td><td> <code title="">yChannelSelector</code>
                   3387:     </td></tr><tr><td> <code title="">zoomandpan</code> </td><td> <code title="">zoomAndPan</code>
                   3388:   </td></tr></tbody></table><p>When the steps below require the user agent to <dfn id="adjust-foreign-attributes">adjust
                   3389:   foreign attributes</dfn> for a token, then, if any of the attributes
                   3390:   on the token match the strings given in the first column of the
                   3391:   following table, let the attribute be a namespaced attribute, with
                   3392:   the prefix being the string given in the corresponding cell in the
                   3393:   second column, the local name being the string given in the
                   3394:   corresponding cell in the third column, and the namespace being the
                   3395:   namespace given in the corresponding cell in the fourth
                   3396:   column. (This fixes the use of namespaced attributes, in particular
                   3397:   <a href="dom.html#attr-xml-lang" title="attr-xml-lang"><code title="">lang</code> attributes in
                   3398:   the <span>XML namespace</span></a>.)</p>
                   3399: 
                   3400:   <table><thead><tr><th> Attribute name </th><th> Prefix </th><th> Local name </th><th> Namespace
                   3401:    </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>
                   3402:     </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>
                   3403:     </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>
                   3404:     </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>
                   3405:     </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>
                   3406:     </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>
                   3407:     </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>
                   3408:     </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 -->
                   3409:     </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>
                   3410:     </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>
                   3411:     </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>
                   3412:     </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     3413:   </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     3414:   <dfn id="generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</dfn> consist of the
                   3415:   following steps. These algorithms are always invoked in response to
                   3416:   a start tag token.</p>
                   3417: 
                   3418:   <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p></li>
                   3419: 
1.91      mike     3420:    <li><p>If the algorithm that was invoked is the <a href="#generic-raw-text-element-parsing-algorithm">generic raw
                   3421:    text element parsing algorithm</a>, switch the tokenizer's
                   3422:    <a href="#content-model-flag">content model flag</a> to the RAWTEXT state; otherwise the
1.1       mike     3423:    algorithm invoked was the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing
                   3424:    algorithm</a>, switch the tokenizer's <a href="#content-model-flag">content model
                   3425:    flag</a> to the RCDATA state.</p></li>
                   3426: 
                   3427:    <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
                   3428:    <a href="#insertion-mode">insertion mode</a>.</p>
                   3429: 
1.91      mike     3430:    </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
                   3431:    RAWTEXT/RCDATA</a>".</p></li>
1.1       mike     3432: 
                   3433:   </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>
                   3434: 
                   3435:   <p>When the steps below require the UA to <dfn id="generate-implied-end-tags">generate implied end
                   3436:   tags</dfn>, then, while the <a href="#current-node">current node</a> is a
                   3437:   <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
                   3438:   <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
                   3439:   <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
                   3440:   <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
                   3441:   pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   3442:   elements</a>.</p>
                   3443: 
                   3444:   <p>If a step requires the UA to generate implied end tags but lists
                   3445:   an element to exclude from the process, then the UA must perform the
                   3446:   above steps as if that element was not in the above list.</p>
                   3447: 
                   3448: 
                   3449:   <h5 id="foster-parenting"><span class="secno">9.2.5.3 </span>Foster parenting</h5>
                   3450: 
                   3451:   <p>Foster parenting happens when content is misnested in tables.</p>
                   3452: 
                   3453:   <p>When a node <var title="">node</var> is to be <dfn id="foster-parent" title="foster
                   3454:   parent">foster parented</dfn>, the node <var title="">node</var>
                   3455:   must be inserted into the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
                   3456: 
                   3457:   <p>The <dfn id="foster-parent-element">foster parent element</dfn> is the parent element of the
                   3458:   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
                   3459:   elements</a>, if there is a <code><a href="tabular-data.html#the-table-element">table</a></code> element and it has
                   3460:   such a parent element. If there is no <code><a href="tabular-data.html#the-table-element">table</a></code> element in
                   3461:   the <a href="#stack-of-open-elements">stack of open elements</a> (<a href="#fragment-case">fragment
                   3462:   case</a>), then the <i><a href="#foster-parent-element">foster parent element</a></i> is the first
                   3463:   element in the <a href="#stack-of-open-elements">stack of open elements</a> (the
1.159     mike     3464:   <code><a href="semantics.html#the-html-element-0">html</a></code> element). Otherwise, if there is a
1.1       mike     3465:   <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="#stack-of-open-elements">stack of open
                   3466:   elements</a>, but the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
                   3467:   <a href="#stack-of-open-elements">stack of open elements</a> has no parent, or its parent
                   3468:   node is not an element, then the <i><a href="#foster-parent-element">foster parent element</a></i> is
                   3469:   the element before the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
                   3470:   <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   3471: 
                   3472:   <p>If the <i><a href="#foster-parent-element">foster parent element</a></i> is the parent element of the
                   3473:   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
                   3474:   elements</a>, then <var title="">node</var> must be inserted
                   3475:   immediately <em>before</em> the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in
                   3476:   the <a href="#stack-of-open-elements">stack of open elements</a> in the <i><a href="#foster-parent-element">foster parent
                   3477:   element</a></i>; otherwise, <var title="">node</var> must be
                   3478:   <em>appended</em> to the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
                   3479: 
                   3480: 
                   3481: 
                   3482:   <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>
                   3483: 
                   3484:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-initial-insertion-mode" title="insertion
                   3485:   mode: initial">initial</a>", tokens must be handled as follows:</p>
                   3486: 
                   3487:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   3488:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   3489:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   3490:    <dd>
                   3491:     <p>Ignore the token.</p>
                   3492:    </dd>
                   3493: 
                   3494:    <dt>A comment token</dt>
                   3495:    <dd>
                   3496:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   3497:     object with the <code title="">data</code> attribute set to the
                   3498:     data given in the comment token.</p>
                   3499:    </dd>
                   3500: 
                   3501:    <dt>A DOCTYPE token</dt>
                   3502:    <dd>
                   3503: 
                   3504:     <p>If the DOCTYPE token's name is not a
                   3505:     <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
                   3506:     missing, or the token's system identifier is neither missing nor a
                   3507:     <a href="infrastructure.html#case-sensitive">case-sensitive</a> match for the string
                   3508:     "<code>about:legacy-compat</code>", and none of the sets of
                   3509:     conditions in the following list are matched, then there is a
                   3510:     <a href="#parse-error">parse error</a>. If one of the sets of conditions in the
                   3511:     following list is matched, then there is an <dfn id="obsolete-permitted-doctype">obsolete
                   3512:     permitted DOCTYPE</dfn>.</p>
                   3513: 
                   3514:     <ul><!-- only things that trigger no-quirks mode and were valid in
                   3515:      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     3516:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3517:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;HTML&#160;4.0//EN</code>", and the
                   3518:      token's system identifier is either missing or the
                   3519:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/REC-html40/strict.dtd</code>".</li>
                   3520: 
                   3521:      <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98      mike     3522:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3523:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;HTML&#160;4.01//EN</code>", and the
                   3524:      token's system identifier is either missing or the
                   3525:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/html4/strict.dtd</code>".</li>
                   3526: 
                   3527:      <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98      mike     3528:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3529:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;XHTML&#160;1.0&#160;Strict//EN</code>",
                   3530:      and the token's system identifier is the
                   3531:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</code>".</li>
                   3532: 
                   3533:      <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98      mike     3534:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3535:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;XHTML&#160;1.1//EN</code>", and the
                   3536:      token's system identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a>
                   3537:      string "<code title="">http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd</code>".</li>
                   3538: 
                   3539:     </ul><p>Conformance checkers may, based on the values (including
                   3540:     presence or lack thereof) of the DOCTYPE token's name, public
                   3541:     identifier, or system identifier, switch to a conformance checking
                   3542:     mode for another language (e.g. based on the DOCTYPE token a
                   3543:     conformance checker could recognize that the document is an
1.183     mike     3544:     HTML4-era document, and defer to an HTML4 conformance
1.1       mike     3545:     checker.)</p>
                   3546: 
                   3547:     <p>Append a <code>DocumentType</code> node to the
                   3548:     <code>Document</code> node, with the <code title="">name</code>
                   3549:     attribute set to the name given in the DOCTYPE token, or the empty
                   3550:     string if the name was missing; the <code title="">publicId</code>
                   3551:     attribute set to the public identifier given in the DOCTYPE token,
                   3552:     or the empty string if the public identifier was missing; the
                   3553:     <code title="">systemId</code> attribute set to the system
                   3554:     identifier given in the DOCTYPE token, or the empty string if the
                   3555:     system identifier was missing; and the other attributes specific
                   3556:     to <code>DocumentType</code> objects set to null and empty lists
                   3557:     as appropriate. Associate the <code>DocumentType</code> node with
                   3558:     the <code>Document</code> object so that it is returned as the
                   3559:     value of the <code title="">doctype</code> attribute of the
                   3560:     <code>Document</code> object.</p>
                   3561: 
                   3562:     <p id="quirks-mode-doctypes">Then, if the DOCTYPE token matches
                   3563:     one of the conditions in the following list, then set the
                   3564:     <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>:</p>
                   3565: 
                   3566:     <ul class="brief"><li> The <i>force-quirks flag</i> is set to <i>on</i>. </li>
                   3567:      <li> The name is set to anything other than "<code title="">HTML</code>". </li>
                   3568:      <li> The public identifier starts with: "<code title="">+//Silmaril//dtd html Pro v0r11 19970101//<!--EN--></code>" </li>
                   3569:      <li> The public identifier starts with: "<code title="">-//AdvaSoft Ltd//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
                   3570:      <li> The public identifier starts with: "<code title="">-//AS//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
                   3571:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 1//<!--EN--></code>" </li>
                   3572:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 2//<!--EN--></code>" </li>
                   3573:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 1//<!--EN--></code>" </li>
                   3574:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 2//<!--EN--></code>" </li>
                   3575:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict//<!--EN--></code>" </li>
                   3576:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0//<!--EN--></code>" </li>
                   3577:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.1E//<!--EN--></code>" </li>
                   3578:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.0//<!--EN--></code>" </li>
                   3579:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML 3.0//EN//</code>" </li>-->
                   3580:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2 Final//<!--EN--></code>" </li>
                   3581:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2//<!--EN--></code>" </li>
                   3582:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3//<!--EN--></code>" </li>
                   3583:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 0//<!--EN--></code>" </li>
                   3584:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 0//EN//2.0</code>" </li>-->
                   3585:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 1//<!--EN--></code>" </li>
                   3586:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 1//EN//2.0</code>" </li>-->
                   3587:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 2//<!--EN--></code>" </li>
                   3588:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 2//EN//2.0</code>" </li>-->
                   3589:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 3//<!--EN--></code>" </li>
                   3590:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 3//EN//3.0</code>" </li>-->
                   3591:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 0//<!--EN--></code>" </li>
                   3592:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 0//EN//2.0</code>" </li>-->
                   3593:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 1//<!--EN--></code>" </li>
                   3594:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 1//EN//2.0</code>" </li>-->
                   3595:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 2//<!--EN--></code>" </li>
                   3596:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 2//EN//2.0</code>" </li>-->
                   3597:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 3//<!--EN--></code>" </li>
                   3598:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 3//EN//3.0</code>" </li>-->
                   3599:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict//<!--EN--></code>" </li>
                   3600:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//2.0</code>" </li>-->
                   3601:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//3.0</code>" </li>-->
                   3602:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML//<!--EN--></code>" </li>
                   3603:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//2.0</code>" </li>-->
                   3604:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//3.0</code>" </li>-->
                   3605:      <li> The public identifier starts with: "<code title="">-//Metrius//DTD Metrius Presentational//<!--EN--></code>" </li>
                   3606:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML Strict//<!--EN--></code>" </li>
                   3607:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML//<!--EN--></code>" </li>
                   3608:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 Tables//<!--EN--></code>" </li>
                   3609:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML Strict//<!--EN--></code>" </li>
                   3610:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML//<!--EN--></code>" </li>
                   3611:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 Tables//<!--EN--></code>" </li>
                   3612:      <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD HTML//<!--EN--></code>" </li>
                   3613:      <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD Strict HTML//<!--EN--></code>" </li>
                   3614:      <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML 2.0//<!--EN--></code>" </li>
                   3615:      <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended 1.0//<!--EN--></code>" </li>
                   3616:      <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended Relaxed 1.0//<!--EN--></code>" </li>
                   3617:      <li> The public identifier starts with: "<code title="">-//SoftQuad Software//DTD HoTMetaL PRO 6.0::19990601::extensions to HTML 4.0//<!--EN--></code>" </li>
                   3618:      <li> The public identifier starts with: "<code title="">-//SoftQuad//DTD HoTMetaL PRO 4.0::19971010::extensions to HTML 4.0//<!--EN--></code>" </li>
                   3619:      <li> The public identifier starts with: "<code title="">-//Spyglass//DTD HTML 2.0 Extended//<!--EN--></code>" </li>
                   3620:      <li> The public identifier starts with: "<code title="">-//SQ//DTD HTML 2.0 HoTMetaL + extensions//<!--EN--></code>" </li>
                   3621:      <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava HTML//<!--EN--></code>" </li>
                   3622:      <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava Strict HTML//<!--EN--></code>" </li>
                   3623:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3 1995-03-24//<!--EN--></code>" </li>
                   3624:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Draft//<!--EN--></code>" </li>
                   3625:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Final//<!--EN--></code>" </li>
                   3626:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2//<!--EN--></code>" </li>
                   3627:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2S Draft//<!--EN--></code>" </li>
                   3628:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Frameset//<!--EN--></code>" </li>
                   3629:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Transitional//<!--EN--></code>" </li>
                   3630:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 19960712//<!--EN--></code>" </li>
                   3631:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 970421//<!--EN--></code>" </li>
                   3632:      <li> The public identifier starts with: "<code title="">-//W3C//DTD W3 HTML//<!--EN--></code>" </li>
                   3633:      <li> The public identifier starts with: "<code title="">-//W3O//DTD W3 HTML 3.0//<!--EN--></code>" </li>
                   3634:    <!--<li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML 3.0//EN//</code>" </li>-->
                   3635:      <li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML Strict 3.0//EN//</code>" </li>
                   3636:      <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML 2.0//<!--EN--></code>" </li>
                   3637:      <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML//<!--EN--></code>" </li>
                   3638:      <li> The public identifier is set to: "<code title="">-/W3C/DTD HTML 4.0 Transitional/EN</code>" </li>
                   3639:      <li> The public identifier is set to: "<code title="">HTML</code>" </li>
                   3640:      <li> The system identifier is set to: "<code title="">http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd</code>" </li>
                   3641:      <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
                   3642:      <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
                   3643:     </ul><p>Otherwise, if the DOCTYPE token matches one of the conditions
                   3644:     in the following list, then set the <code>Document</code> to
                   3645:     <a href="dom.html#limited-quirks-mode">limited quirks mode</a>:</p>
                   3646: 
                   3647:     <ul class="brief"><li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Frameset//<!--EN--></code>" </li>
                   3648:      <li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Transitional//<!--EN--></code>" </li>
                   3649:      <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
                   3650:      <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
                   3651:     </ul><p>The name, system identifier, and public identifier strings must
                   3652:     be compared to the values given in the lists above in an
                   3653:     <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> manner. A system identifier
                   3654:     whose value is the empty string is not considered missing for the
                   3655:     purposes of the conditions above.</p>
                   3656: 
                   3657:     <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>
                   3658: 
                   3659:    </dd>
                   3660: 
                   3661:    <dt>Anything else</dt>
                   3662:    <dd>
                   3663: 
                   3664:     <p><a href="#parse-error">Parse error</a>.</p>
                   3665: 
                   3666:     <p>Set the <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>.</p>
                   3667: 
                   3668:     <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
                   3669:     reprocess the current token.</p>
                   3670: 
                   3671:    </dd>
                   3672: 
                   3673:   </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>
                   3674: 
                   3675:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-html-insertion-mode" title="insertion
                   3676:   mode: before html">before html</a>", tokens must be handled as follows:</p>
                   3677: 
                   3678:   <dl class="switch"><dt>A DOCTYPE token</dt>
                   3679:    <dd>
                   3680:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   3681:    </dd>
                   3682: 
                   3683:    <dt>A comment token</dt>
                   3684:    <dd>
                   3685:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   3686:     object with the <code title="">data</code> attribute set to the
                   3687:     data given in the comment token.</p>
                   3688:    </dd>
                   3689: 
                   3690:    <dt>A character token that is one of U+0009 CHARACTER
                   3691:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   3692:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   3693:    <dd>
                   3694:     <p>Ignore the token.</p>
                   3695:    </dd>
                   3696: 
                   3697:    <dt>A start tag whose tag name is "html"</dt>
                   3698:    <dd>
                   3699: 
                   3700:     <p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the <a href="#html-namespace-0">HTML
                   3701:     namespace</a>. Append it to the <code>Document</code>
                   3702:     object. Put this element in the <a href="#stack-of-open-elements">stack of open
                   3703:     elements</a>.</p>
                   3704: 
                   3705:     <p id="parser-appcache">If the <code>Document</code> is being
                   3706:     loaded as part of <a href="history.html#navigate" title="navigate">navigation</a> of a
                   3707:     <a href="browsers.html#browsing-context">browsing context</a>, then: if the newly created element
                   3708:     has a <code title="attr-html-manifest"><a href="semantics.html#attr-html-manifest">manifest</a></code> attribute,
                   3709:     then <a href="infrastructure.html#resolve-a-url" title="resolve a url">resolve</a> the value of that
                   3710:     attribute to an <a href="infrastructure.html#absolute-url">absolute URL</a>, relative to the newly
                   3711:     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     3712:     algorithm</a> with the resulting <a href="infrastructure.html#absolute-url">absolute URL</a> with
                   3713:     any <a href="infrastructure.html#url-fragment" title="url-fragment">&lt;fragment&gt;</a> component
                   3714:     removed; otherwise, if there is no such attribute or resolving it
                   3715:     fails, run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application
                   3716:     cache selection algorithm</a> with no manifest. The algorithm
                   3717:     must be passed the <code>Document</code> object.</p>
1.1       mike     3718: 
                   3719:     <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>
                   3720: 
                   3721:    </dd>
                   3722: 
                   3723:    <dt>Anything else</dt>
                   3724:    <dd>
                   3725: 
1.159     mike     3726:     <p>Create an <code><a href="semantics.html#the-html-element-0">html</a></code> element. Append it to the
1.1       mike     3727:     <code>Document</code> object. Put this element in the <a href="#stack-of-open-elements">stack
                   3728:     of open elements</a>.</p>
                   3729: 
                   3730:     <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
                   3731:     context</a>, then: run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application cache selection
                   3732:     algorithm</a> with no manifest, passing it the
                   3733:     <code>Document</code> object.</p>
                   3734: 
                   3735:     <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
                   3736:     reprocess the current token.</p>
                   3737: 
                   3738:     <p class="XXX">Should probably make end tags be ignored, so
                   3739:     that "&lt;/head&gt;&lt;!-- --&gt;&lt;html&gt;" puts the comment before the
                   3740:     root node (or should we?)</p>
                   3741: 
                   3742:    </dd>
                   3743: 
                   3744:   </dl><p>The root element can end up being removed from the
                   3745:   <code>Document</code> object, e.g. by scripts; nothing in particular
                   3746:   happens in such cases, content continues being appended to the nodes
                   3747:   as described in the next section.</p>
                   3748: 
                   3749: 
                   3750:   <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>
                   3751: 
                   3752:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-head-insertion-mode" title="insertion
                   3753:   mode: before head">before head</a>", tokens must be handled as follows:</p>
                   3754: 
                   3755:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   3756:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   3757:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   3758:    <dd>
                   3759:     <p>Ignore the token.</p> <!-- :-( -->
                   3760:    </dd>
                   3761: 
                   3762:    <dt>A comment token</dt>
                   3763:    <dd>
                   3764:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   3765:     node</a> with the <code title="">data</code> attribute set to
                   3766:     the data given in the comment token.</p>
                   3767:    </dd>
                   3768: 
                   3769:    <dt>A DOCTYPE token</dt>
                   3770:    <dd>
                   3771:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   3772:    </dd>
                   3773: 
                   3774:    <dt>A start tag whose tag name is "html"</dt>
                   3775:    <dd>
                   3776:     <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
                   3777:     mode</a>.</p>
                   3778:    </dd>
                   3779: 
                   3780:    <dt>A start tag whose tag name is "head"</dt>
                   3781:    <dd>
                   3782: 
                   3783:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   3784: 
                   3785:     <p>Set the <a href="#head-element-pointer"><code title="">head</code> element pointer</a>
1.159     mike     3786:     to the newly created <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1       mike     3787: 
                   3788:     <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>
                   3789: 
                   3790:    </dd>
                   3791: 
                   3792:    <dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
                   3793:    <dd>
                   3794: 
                   3795:     <p>Act as if a start tag token with the tag name "head" and no
                   3796:     attributes had been seen, then reprocess the current token.</p>
                   3797: 
                   3798:    </dd>
                   3799: 
                   3800:    <dt>Any other end tag</dt>
                   3801:    <dd>
                   3802: 
                   3803:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   3804: 
                   3805:    </dd>
                   3806: 
                   3807:    <dt>Anything else</dt>
                   3808:    <dd>
                   3809: 
                   3810:     <p>Act as if a start tag token with the tag name "head" and no
                   3811:     attributes had been seen, then reprocess the current
                   3812:     token.</p>
                   3813: 
                   3814:    </dd>
                   3815: 
                   3816:   </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>
                   3817: 
                   3818:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inhead" title="insertion
                   3819:   mode: in head">in head</a>", tokens must be handled as follows:</p>
                   3820: 
                   3821:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   3822:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   3823:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   3824:    <dd>
                   3825:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   3826:     the <a href="#current-node">current node</a>.</p>
                   3827:    </dd>
                   3828: 
                   3829:    <dt>A comment token</dt>
                   3830:    <dd>
                   3831:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   3832:     node</a> with the <code title="">data</code> attribute set to
                   3833:     the data given in the comment token.</p>
                   3834:    </dd>
                   3835: 
                   3836:    <dt>A DOCTYPE token</dt>
                   3837:    <dd>
                   3838:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   3839:    </dd>
                   3840: 
                   3841:    <dt>A start tag whose tag name is "html"</dt>
                   3842:    <dd>
                   3843:     <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
                   3844:     mode</a>.</p>
                   3845:    </dd>
                   3846: 
                   3847:    <dt>A start tag whose tag name is one of: "base", "command",
                   3848:    "link"</dt>
                   3849:    <dd>
                   3850: 
                   3851:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   3852:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   3853:     elements</a>.</p>
                   3854: 
                   3855:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   3856:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   3857: 
                   3858:    </dd>
                   3859: 
                   3860:    <dt>A start tag whose tag name is "meta"</dt>
                   3861:    <dd>
                   3862: 
                   3863:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   3864:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   3865:     elements</a>.</p>
                   3866: 
                   3867:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   3868:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   3869: 
                   3870:     <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
                   3871:     value is a supported encoding, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   3872:     currently <i>tentative</i>, then <a href="#change-the-encoding">change the
                   3873:     encoding</a> to the encoding given by the value of the
                   3874:     <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">charset</a></code> attribute.</p>
                   3875: 
                   3876:     <p>Otherwise, if the element has a <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">content</a></code> attribute, and
                   3877:     applying the <a href="infrastructure.html#algorithm-for-extracting-an-encoding-from-a-content-type">algorithm for extracting an encoding from a
                   3878:     Content-Type</a> to its value returns a supported encoding
                   3879:     <var title="">encoding</var>, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   3880:     currently <i>tentative</i>, then <a href="#change-the-encoding">change the
                   3881:     encoding</a> to the encoding <var title="">encoding</var>.</p>
                   3882: 
                   3883:    </dd>
                   3884: 
                   3885:    <dt>A start tag whose tag name is "title"</dt>
                   3886:    <dd>
                   3887:     <p>Follow the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</a>.</p>
                   3888:    </dd>
                   3889: 
                   3890:    <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
                   3891:    <dt>A start tag whose tag name is one of: "noframes", "style"</dt>
                   3892:    <dd>
1.91      mike     3893:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     3894:    </dd>
                   3895: 
                   3896:    <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is disabled</dt>
                   3897:    <dd>
                   3898: 
                   3899:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   3900: 
                   3901:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inheadnoscript" title="insertion mode: in head noscript">in head
                   3902:     noscript</a>".</p>
                   3903: 
                   3904:    </dd>
                   3905: 
                   3906:    <dt id="scriptTag">A start tag whose tag name is "script"</dt>
                   3907:    <dd>
                   3908: 
                   3909:     <ol><li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the
                   3910:      <a href="#html-namespace-0">HTML namespace</a>.</p></li>
                   3911: 
                   3912:      <li>
                   3913: 
                   3914:       <p>Mark the element as being <a href="semantics.html#parser-inserted">"parser-inserted"</a>.</p>
                   3915: 
                   3916:       <p class="note">This ensures that, if the script is external,
1.159     mike     3917:       any <code title="dom-document-write"><a href="embedded-content-0.html#dom-document-write">document.write()</a></code>
1.1       mike     3918:       calls in the script will execute in-line, instead of blowing the
                   3919:       document away, as would happen in most other cases. It also
                   3920:       prevents the script from executing until the end tag is
                   3921:       seen.</p>
                   3922: 
                   3923:      </li>
                   3924: 
                   3925:      <li><p>If the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML
                   3926:      fragment parsing algorithm</a>, then mark the
                   3927:      <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-executed">"already
                   3928:      executed"</a>. (<a href="#fragment-case">fragment case</a>)</p></li>
                   3929: 
                   3930:      <li><p>Append the new element to the <a href="#current-node">current node</a>
                   3931:      and push it onto the <a href="#stack-of-open-elements">stack of open
                   3932:      elements</a>.</p></li>
                   3933: 
                   3934:      <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
1.91      mike     3935:      the RAWTEXT state.</p></li>
1.1       mike     3936: 
                   3937:      <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
                   3938:      <a href="#insertion-mode">insertion mode</a>.</p>
                   3939: 
1.91      mike     3940:      </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
                   3941:      RAWTEXT/RCDATA</a>".</p></li>
1.1       mike     3942: 
                   3943:     </ol></dd>
                   3944: 
                   3945:    <dt>An end tag whose tag name is "head"</dt>
                   3946:    <dd>
                   3947: 
                   3948:     <p>Pop the <a href="#current-node">current node</a> (which will be the
1.159     mike     3949:     <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     3950:     elements</a>.</p>
                   3951: 
                   3952:     <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>
                   3953: 
                   3954:    </dd>
                   3955: 
                   3956:    <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
                   3957:    <dd>
                   3958:     <p>Act as described in the "anything else" entry below.</p>
                   3959:    </dd>
                   3960: 
                   3961:    <dt>A start tag whose tag name is "head"</dt>
                   3962:    <dt>Any other end tag</dt>
                   3963:    <dd>
                   3964:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   3965:    </dd>
                   3966: 
                   3967:    <dt>Anything else</dt>
                   3968:    <dd>
                   3969: 
                   3970:     <!-- can't get here with an EOF and a fragment case -->
                   3971: 
                   3972:     <p>Act as if an end tag token with the tag name "head" had
                   3973:     been seen, and reprocess the current token.</p>
                   3974: 
                   3975:     <p class="XXX">In certain UAs, <a href="https://bugzilla.mozilla.org/attachment.cgi?id=180157&amp;action=view">some
                   3976:     elements</a> don't trigger the "in body" mode straight away,
                   3977:     but instead get put into the head. Do we want to copy
                   3978:     that?</p>
                   3979: 
                   3980:    </dd>
                   3981: 
                   3982:   </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>
                   3983: 
                   3984:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inheadnoscript" title="insertion
                   3985:   mode: in head noscript">in head noscript</a>", tokens must be handled as follows:</p>
                   3986: 
                   3987:   <dl class="switch"><dt>A DOCTYPE token</dt>
                   3988:    <dd>
                   3989:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   3990:    </dd>
                   3991: 
                   3992:    <dt>A start tag whose tag name is "html"</dt>
                   3993:    <dd>
                   3994:     <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
                   3995:     mode</a>.</p>
                   3996:    </dd>
                   3997: 
                   3998:    <dt>An end tag whose tag name is "noscript"</dt>
                   3999:    <dd>
                   4000: 
                   4001:     <p>Pop the <a href="#current-node">current node</a> (which will be a
                   4002:     <code><a href="semantics.html#the-noscript-element">noscript</a></code> element) from the <a href="#stack-of-open-elements">stack of open
                   4003:     elements</a>; the new <a href="#current-node">current node</a> will be a
1.159     mike     4004:     <code><a href="semantics.html#the-head-element-0">head</a></code> element.</p>
1.1       mike     4005: 
                   4006:     <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>
                   4007: 
                   4008:    </dd>
                   4009: 
                   4010:    <dt>A character token that is one of U+0009 CHARACTER
                   4011:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   4012:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   4013:    <dt>A comment token</dt>
                   4014:    <dt>A start tag whose tag name is one of: "link", "meta", "noframes", "style"</dt>
                   4015:    <dd>
                   4016:     <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
                   4017:     mode</a>.</p>
                   4018:    </dd>
                   4019: 
                   4020:    <dt>An end tag whose tag name is "br"</dt>
                   4021:    <dd>
                   4022:     <p>Act as described in the "anything else" entry below.</p>
                   4023:    </dd>
                   4024: 
                   4025:    <dt>A start tag whose tag name is one of: "head", "noscript"</dt>
                   4026:    <dt>Any other end tag</dt>
                   4027:    <dd>
                   4028:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4029:    </dd>
                   4030: 
                   4031:    <dt>Anything else</dt>
                   4032:    <dd>
                   4033: 
                   4034:     <!-- can't get here with an EOF and a fragment case -->
                   4035: 
                   4036:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
                   4037:     name "noscript" had been seen and reprocess the current
                   4038:     token.</p>
                   4039: 
                   4040:    </dd>
                   4041: 
                   4042:   </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>
                   4043: 
                   4044:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-head-insertion-mode" title="insertion
                   4045:   mode: after head">after head</a>", tokens must be handled as follows:</p>
                   4046: 
                   4047:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   4048:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   4049:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   4050:    <dd>
                   4051:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   4052:     the <a href="#current-node">current node</a>.</p>
                   4053:    </dd>
                   4054: 
                   4055:    <dt>A comment token</dt>
                   4056:    <dd>
                   4057:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   4058:     node</a> with the <code title="">data</code> attribute set to
                   4059:     the data given in the comment token.</p>
                   4060:    </dd>
                   4061: 
                   4062:    <dt>A DOCTYPE token</dt>
                   4063:    <dd>
                   4064:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4065:    </dd>
                   4066: 
                   4067:    <dt>A start tag whose tag name is "html"</dt>
                   4068:    <dd>
                   4069:     <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
                   4070:     mode</a>.</p>
                   4071:    </dd>
                   4072: 
                   4073:    <dt>A start tag whose tag name is "body"</dt>
                   4074:    <dd>
                   4075: 
                   4076:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4077: 
                   4078:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   4079: 
                   4080:     <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>
                   4081: 
                   4082:    </dd>
                   4083: 
                   4084:    <dt>A start tag whose tag name is "frameset"</dt>
                   4085:    <dd>
                   4086: 
                   4087:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4088: 
                   4089:     <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>
                   4090: 
                   4091:    </dd>
                   4092: 
                   4093:    <dt>A start tag token whose tag name is one of: "base", "link",
                   4094:    "meta", "noframes", "script", "style", "title"</dt>
                   4095:    <dd>
                   4096: 
                   4097:     <p><a href="#parse-error">Parse error</a>.</p>
                   4098: 
                   4099:     <p>Push the node pointed to by the <a href="#head-element-pointer"><code title="">head</code> element pointer</a> onto the
                   4100:     <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   4101: 
                   4102:     <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
                   4103:     mode</a>.</p>
                   4104: 
                   4105:     <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
                   4106:     of open elements</a>.</p>
                   4107: 
                   4108:     <p class="note">The <a href="#head-element-pointer"><code title="">head</code> element
                   4109:     pointer</a> cannot be null at this point.</p>
                   4110: 
                   4111:    </dd>
                   4112: 
                   4113:    <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
                   4114:    <dd>
                   4115:     <p>Act as described in the "anything else" entry below.</p>
                   4116:    </dd>
                   4117: 
                   4118:    <dt>A start tag whose tag name is "head"</dt>
                   4119:    <dt>Any other end tag</dt>
                   4120:    <dd>
                   4121:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4122:    </dd>
                   4123: 
                   4124:    <dt>Anything else</dt>
                   4125:    <dd>
                   4126:     <p>Act as if a start tag token with the tag name "body" and no
                   4127:     attributes had been seen, then set the <a href="#frameset-ok-flag">frameset-ok
                   4128:     flag</a> back to "ok", and then reprocess the current
                   4129:     token.</p>
                   4130:    </dd>
                   4131: 
                   4132:   </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>
                   4133: 
                   4134:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inbody" title="insertion
                   4135:   mode: in body">in body</a>", tokens must be handled as follows:</p>
                   4136: 
                   4137:   <dl class="switch"><dt>A character token</dt>
                   4138:    <dd>
                   4139: 
                   4140:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4141:     any.</p>
                   4142: 
                   4143:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   4144:     character</a> into the <a href="#current-node">current node</a>.</p>
                   4145: 
                   4146:     <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
                   4147:     LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
                   4148:     (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
                   4149:     flag</a> to "not ok".</p>
                   4150: 
                   4151:    </dd>
                   4152: 
                   4153:    <dt>A comment token</dt>
                   4154:    <dd>
                   4155:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   4156:     node</a> with the <code title="">data</code> attribute set to
                   4157:     the data given in the comment token.</p>
                   4158:    </dd>
                   4159: 
                   4160:    <dt>A DOCTYPE token</dt>
                   4161:    <dd>
                   4162:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4163:    </dd>
                   4164: 
                   4165:    <dt>A start tag whose tag name is "html"</dt>
                   4166:    <dd>
                   4167:     <p><a href="#parse-error">Parse error</a>. For each attribute on the token,
                   4168:     check to see if the attribute is already present on the top
                   4169:     element of the <a href="#stack-of-open-elements">stack of open elements</a>. If it is not,
                   4170:     add the attribute and its corresponding value to that element.</p>
                   4171:    </dd>
                   4172: 
                   4173:    <dt>A start tag token whose tag name is one of: "base", "command",
                   4174:    "link", "meta", "noframes", "script", "style", "title"</dt>
                   4175:    <dd>
                   4176:     <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
                   4177:     mode</a>.</p>
                   4178:    </dd>
                   4179: 
                   4180:    <dt>A start tag whose tag name is "body"</dt>
                   4181:    <dd>
                   4182: 
                   4183:     <p><a href="#parse-error">Parse error</a>.</p>
                   4184: 
                   4185:     <p>If the second element on the <a href="#stack-of-open-elements">stack of open
1.159     mike     4186:     elements</a> is not a <code><a href="semantics.html#the-body-element-0">body</a></code> element, or, if the
1.1       mike     4187:     <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
                   4188:     then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
                   4189: 
                   4190:     <p>Otherwise, for each attribute on the token, check to see if
1.159     mike     4191:     the attribute is already present on the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1       mike     4192:     element (the second element) on the <a href="#stack-of-open-elements">stack of open
                   4193:     elements</a>. If it is not, add the attribute and its
                   4194:     corresponding value to that element.</p>
                   4195: 
                   4196:    </dd>
                   4197: 
                   4198:    <dt>A start tag whose tag name is "frameset"</dt>
                   4199:    <dd>
                   4200: 
                   4201:     <p><a href="#parse-error">Parse error</a>.</p>
                   4202: 
                   4203:     <p>If the second element on the <a href="#stack-of-open-elements">stack of open
1.159     mike     4204:     elements</a> is not a <code><a href="semantics.html#the-body-element-0">body</a></code> element, or, if the
1.1       mike     4205:     <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
                   4206:     then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
                   4207: 
                   4208:     <p>If the <a href="#frameset-ok-flag">frameset-ok flag</a> is set to "not ok", ignore
                   4209:     the token.</p>
                   4210: 
                   4211:     <p>Otherwise, run the following steps:</p>
                   4212: 
                   4213:     <ol><li><p>Remove the second element on the <a href="#stack-of-open-elements">stack of open
                   4214:      elements</a> from its parent node, if it has one.</p></li>
                   4215: 
                   4216:      <li><p>Pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of
                   4217:      open elements</a>, from the <a href="#current-node">current node</a> up to,
1.159     mike     4218:      but not including, the root <code><a href="semantics.html#the-html-element-0">html</a></code> element.</p>
1.1       mike     4219: 
                   4220:      </li><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
                   4221:      token.</p></li>
                   4222: 
                   4223:      <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>
                   4224: 
                   4225:     </li></ol></dd>
                   4226: 
                   4227:    <dt>An end-of-file token</dt>
                   4228:    <dd>
                   4229: 
                   4230:     <p>If there is a node in the <a href="#stack-of-open-elements">stack of open elements</a>
                   4231:     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>
                   4232:     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
                   4233:     <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
                   4234:     <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
                   4235:     <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     4236:     <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     4237:     this is a <a href="#parse-error">parse error</a>.</p> <!-- (some of those are
                   4238:     fragment cases) -->
                   4239: 
                   4240:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   4241: 
                   4242:    </dd>
                   4243: 
                   4244:    <dt>An end tag whose tag name is "body"</dt>
                   4245:    <dd>
                   4246: 
                   4247:     <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
                   4248:     in scope</a>, this is a <a href="#parse-error">parse error</a>; ignore the
                   4249:     token.</p>
                   4250: 
                   4251:     <!-- if we get here, the insertion mode here is forcibly "in
                   4252:     body". -->
                   4253: 
                   4254:     <p>Otherwise, if there is a node in the <a href="#stack-of-open-elements">stack of open
                   4255:     elements</a> that is not either a <code><a href="semantics.html#the-dd-element">dd</a></code> element, a
                   4256:     <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
                   4257:     <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
                   4258:     <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
                   4259:     <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
                   4260:     <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
                   4261:     <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     4262:     <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
                   4263:     <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     4264:     error</a>.</p> <!-- (some of those are fragment cases, e.g. for
                   4265:     <tbody> you'd have hit the first paragraph since the <body>
                   4266:     wouldn't be in scope, unless it was a fragment case) -->
                   4267: 
                   4268:     <!-- If we ever change the frameset-ok flag to an insertion mode,
                   4269:     then we'd have to somehow keep track of its state when we switch
                   4270:     to after-body. -->
                   4271: 
                   4272:     <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>
                   4273: 
                   4274:    </dd>
                   4275: 
                   4276:    <dt>An end tag whose tag name is "html"</dt>
                   4277:    <dd>
                   4278: 
                   4279:     <p>Act as if an end tag with tag name "body" had been seen,
                   4280:     then, if that token wasn't ignored, reprocess the current
                   4281:     token.</p>
                   4282: 
                   4283:     <p class="note">The fake end tag token here can only be
                   4284:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   4285: 
                   4286:    </dd>
                   4287: 
                   4288:    <!-- start tags for non-phrasing flow content elements -->
                   4289: 
                   4290:    <!-- the normal ones -->
                   4291:    <dt>A start tag whose tag name is one of: "address", "article",
1.86      mike     4292:    "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
                   4293:    "details", "dialog", "dir", "div", "dl", "fieldset", "figure",
                   4294:    "footer", "header", "hgroup", "menu", "nav", "ol", "p", "section",
                   4295:    "ul"</dt>
1.1       mike     4296:    <dd>
                   4297: 
                   4298:     <!-- As of May 2008 this doesn't match any browser exactly, but is
                   4299:     as close to what IE does as I can get without doing the non-tree
                   4300:     DOM nonsense, and thus should actually afford better compatibility
                   4301:     when implemented by the other browsers. -->
                   4302: 
                   4303:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4304:     an element in scope">has a <code>p</code> element in
                   4305:     scope</a>, then act as if an end tag with the tag name
                   4306:     "p" had been seen.</p>
                   4307: 
                   4308:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4309: 
                   4310:    </dd>
                   4311: 
                   4312:    <!-- as normal, but close h1-h6 if it's the current node -->
                   4313:    <dt>A start tag whose tag name is one of: "h1", "h2", "h3", "h4",
                   4314:    "h5", "h6"</dt>
                   4315:    <dd>
                   4316: 
                   4317:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4318:     an element in scope">has a <code>p</code> element in
                   4319:     scope</a>, then act as if an end tag with the tag name
                   4320:     "p" had been seen.</p>
                   4321: 
                   4322:     <p>If the <a href="#current-node">current node</a> is an element whose tag name
                   4323:     is one of "h1", "h2", "h3", "h4", "h5", or "h6", then this is a
                   4324:     <a href="#parse-error">parse error</a>; pop the <a href="#current-node">current node</a> off
                   4325:     the <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   4326:     <!-- See https://bugs.webkit.org/show_bug.cgi?id=12646 -->
                   4327: 
                   4328:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4329: 
                   4330:    </dd>
                   4331: 
                   4332:    <!-- as normal, but drops leading newline -->
                   4333:    <dt>A start tag whose tag name is one of: "pre", "listing"</dt>
                   4334:    <dd>
                   4335: 
                   4336:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4337:     an element in scope">has a <code>p</code> element in
                   4338:     scope</a>, then act as if an end tag with the tag name
                   4339:     "p" had been seen.</p>
                   4340: 
                   4341:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4342: 
                   4343:     <p>If the next token is a U+000A LINE FEED (LF) character
                   4344:     token, then ignore that token and move on to the next
                   4345:     one. (Newlines at the start of <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are
                   4346:     ignored as an authoring convenience.)</p>
                   4347: 
                   4348:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   4349: 
                   4350:    </dd>
                   4351: 
                   4352:    <!-- as normal, but interacts with the form element pointer -->
                   4353:    <dt>A start tag whose tag name is "form"</dt>
                   4354:    <dd>
                   4355: 
                   4356:     <p>If the <a href="#form-element-pointer"><code title="form">form</code> element
                   4357:     pointer</a> is not null, then this is a <a href="#parse-error">parse
                   4358:     error</a>; ignore the token.</p>
                   4359: 
                   4360:     <p>Otherwise:</p>
                   4361: 
                   4362:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4363:     an element in scope">has a <code>p</code> element in
                   4364:     scope</a>, then act as if an end tag with the tag name
                   4365:     "p" had been seen.</p>
                   4366: 
                   4367:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, and set the
                   4368:     <a href="#form-element-pointer"><code title="form">form</code> element pointer</a> to
                   4369:     point to the element created.</p>
                   4370: 
                   4371:    </dd>
                   4372: 
                   4373:    <!-- as normal, but imply </li> when there's another <li> open in weird cases -->
                   4374:    <dt>A start tag whose tag name is "li"</dt>
                   4375:    <dd>
                   4376: 
                   4377:     <p>Run the following algorithm:</p>
                   4378: 
                   4379:     <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
                   4380: 
                   4381:      <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   4382:      node</a> (the bottommost node of the stack).</p></li>
                   4383: 
                   4384:      <li><p>If <var title="">node</var> is an <code><a href="semantics.html#the-li-element">li</a></code> element,
                   4385:      then act as if an end tag with the tag name "li" had
                   4386:      been seen, then jump to the last step.</p></li>
                   4387: 
                   4388:      <li><p><i>Loop</i>: If <var title="">node</var> is not in the
                   4389:      <a href="#formatting">formatting</a> category, and is not in the
                   4390:      <a href="#phrasing">phrasing</a> category, and is not an
                   4391:      <code><a href="semantics.html#the-address-element">address</a></code>, <code><a href="interactive-elements.html#the-div-element">div</a></code>, or <code><a href="semantics.html#the-p-element">p</a></code>
                   4392:      element, then jump to the last step.</p></li> <!-- an element
                   4393:      <foo> is in this list if the following markup:
                   4394: 
                   4395:          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><ol><li><foo><li>
                   4396: 
                   4397:      ...results in the second <li> not being (in any way) a descendant
                   4398:      of the first <li>, or if <foo> is a formatting element that gets
                   4399:      reopened later. -->
                   4400: 
                   4401:      <li><p>Otherwise, set <var title="">node</var> to the previous
                   4402:      entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
                   4403:      the step labeled <i>loop</i>.</p></li>
                   4404: 
                   4405:      <li>
                   4406: 
                   4407:       <p>This is the last step.</p>
                   4408: 
                   4409:       <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4410:       an element in scope">has a <code>p</code> element in
                   4411:       scope</a>, then act as if an end tag with the tag name
                   4412:       "p" had been seen.</p>
                   4413: 
                   4414:       <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
                   4415:       token.</p>
                   4416: 
                   4417:      </li>
                   4418: 
                   4419:     </ol></dd>
                   4420: 
                   4421:    <!-- as normal, but imply </dt> or </dd> when there's another <dt> or <dd> open in weird cases  -->
                   4422:    <dt>A start tag whose tag name is one of: "dd", "dt"</dt>
                   4423:    <dd>
                   4424: 
                   4425:     <p>Run the following algorithm:</p>
                   4426: 
                   4427:     <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
                   4428: 
                   4429:      <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   4430:      node</a> (the bottommost node of the stack).</p></li>
                   4431: 
                   4432:      <li><p><i>Loop</i>: If <var title="">node</var> is a
                   4433:      <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
                   4434:      tag with the same tag name as <var title="">node</var> had been
                   4435:      seen, then jump to the last step.</p></li>
                   4436: 
                   4437:      <li><p>If <var title="">node</var> is not in the
                   4438:      <a href="#formatting">formatting</a> category, and is not in the
                   4439:      <a href="#phrasing">phrasing</a> category, and is not an
                   4440:      <code><a href="semantics.html#the-address-element">address</a></code>, <code><a href="interactive-elements.html#the-div-element">div</a></code>, or <code><a href="semantics.html#the-p-element">p</a></code>
                   4441:      element, then jump to the last step.</p></li> <!-- an element
                   4442:      <foo> is in this list if the following markup:
                   4443: 
                   4444:          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><dl><dt><foo><dt>
                   4445: 
                   4446:      ...results in the second <dt> not being (in any way) a descendant
                   4447:      of the first <dt>, or if <foo> is a formatting element that gets
                   4448:      reopened later. -->
                   4449: 
                   4450:      <li><p>Otherwise, set <var title="">node</var> to the previous
                   4451:      entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
                   4452:      the step labeled <i>loop</i>.</p></li>
                   4453: 
                   4454:      <li>
                   4455: 
                   4456:       <p>This is the last step.</p>
                   4457: 
                   4458:       <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4459:       an element in scope">has a <code>p</code> element in
                   4460:       scope</a>, then act as if an end tag with the tag name
                   4461:       "p" had been seen.</p>
                   4462: 
                   4463:       <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
                   4464:       token.</p>
                   4465: 
                   4466:      </li>
                   4467: 
                   4468:     </ol></dd>
                   4469: 
                   4470:    <!-- same as normal, but effectively ends parsing -->
                   4471:    <dt>A start tag whose tag name is "plaintext"</dt>
                   4472:    <dd>
                   4473: 
                   4474:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4475:     an element in scope">has a <code>p</code> element in
                   4476:     scope</a>, then act as if an end tag with the tag name
                   4477:     "p" had been seen.</p>
                   4478: 
                   4479:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4480: 
                   4481:     <p>Switch the <a href="#content-model-flag">content model flag</a> to the PLAINTEXT
                   4482:     state.</p>
                   4483: 
                   4484:     <p class="note">Once a start tag with the tag name "plaintext"
                   4485:     has been seen, that will be the last token ever seen other
                   4486:     than character tokens (and the end-of-file token), because
                   4487:     there is no way to switch the <a href="#content-model-flag">content model flag</a>
                   4488:     out of the PLAINTEXT state.</p>
                   4489: 
                   4490:    </dd>
                   4491: 
                   4492:    <!-- end tags for non-phrasing flow content elements -->
                   4493: 
                   4494:    <!-- the normal ones -->
                   4495:    <dt>An end tag whose tag name is one of: "address", "article",
1.86      mike     4496:    "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
                   4497:    "details", "dialog", "dir", "div", "dl", "fieldset", "figure",
                   4498:    "footer", "header", "hgroup", "listing", "menu", "nav", "ol",
                   4499:    "pre", "section", "ul"</dt>
1.1       mike     4500:    <dd>
                   4501: 
                   4502:     <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>
                   4503:     with the same tag name as that of the token, then this is a
                   4504:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4505: 
                   4506:     <p>Otherwise, run these steps:</p>
                   4507: 
                   4508:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   4509: 
                   4510:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4511:      the same tag name as that of the token, then this is a
                   4512:      <a href="#parse-error">parse error</a>.</p></li>
                   4513: 
                   4514:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4515:      until an element with the same tag name as the token has been
                   4516:      popped from the stack.</p></li>
                   4517: 
                   4518:     </ol></dd>
                   4519: 
                   4520:    <!-- removes the form element pointer instead of the matching node -->
                   4521:    <dt>An end tag whose tag name is "form"</dt>
                   4522:    <dd>
                   4523: 
                   4524:     <p>Let <var title="">node</var> be the element that the
                   4525:     <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is set
                   4526:     to.</p>
                   4527: 
                   4528:     <p>Set the <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
                   4529:     to null.</p>
                   4530: 
                   4531:     <p>If <var title="">node</var> is null or the <a href="#stack-of-open-elements">stack of open
                   4532:     elements</a> does not <a href="#has-an-element-in-scope" title="has an element in
                   4533:     scope">have <var title="">node</var> in scope</a>, then this is
                   4534:     a <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4535: 
                   4536:     <p>Otherwise, run these steps:</p>
                   4537: 
                   4538:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   4539: 
                   4540:      <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
                   4541:      error</a>.</p></li>
                   4542: 
                   4543:      <li><p>Remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of
                   4544:      open elements</a>.</p></li>
                   4545: 
                   4546:     </ol></dd>
                   4547: 
                   4548:    <!-- as normal, except </p> implies <p> if there's no <p> in scope, and needs care as the elements have optional tags -->
                   4549:    <dt>An end tag whose tag name is "p"</dt>
                   4550:    <dd>
                   4551: 
                   4552:     <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>
                   4553:     with the same tag name as that of the token, then this is a
                   4554:     <a href="#parse-error">parse error</a>; act as if a start tag with the tag name
                   4555:     "p" had been seen, then reprocess the current token.</p>
                   4556: 
                   4557:     <p>Otherwise, run these steps:</p>
                   4558: 
                   4559:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
                   4560:      for elements with the same tag name as the token.</p></li>
                   4561: 
                   4562:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4563:      the same tag name as that of the token, then this is a
                   4564:      <a href="#parse-error">parse error</a>.</p></li>
                   4565: 
                   4566:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4567:      until an element with the same tag name as the token has been
                   4568:      popped from the stack.</p></li>
                   4569: 
                   4570:     </ol></dd>
                   4571: 
                   4572:    <!-- as normal, but needs care as the elements have optional tags -->
                   4573:    <dt>An end tag whose tag name is one of: "dd", "dt", "li"</dt>
                   4574:    <dd>
                   4575: 
                   4576:     <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>
                   4577:     with the same tag name as that of the token, then this is a
                   4578:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4579: 
                   4580:     <p>Otherwise, run these steps:</p>
                   4581: 
                   4582:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
                   4583:      for elements with the same tag name as the token.</p></li>
                   4584: 
                   4585:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4586:      the same tag name as that of the token, then this is a
                   4587:      <a href="#parse-error">parse error</a>.</p></li>
                   4588: 
                   4589:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4590:      until an element with the same tag name as the token has been
                   4591:      popped from the stack.</p></li>
                   4592: 
                   4593:     </ol></dd>
                   4594: 
                   4595:    <!-- as normal, except acts as a closer for any of the h1-h6 elements -->
                   4596:    <dt>An end tag whose tag name is one of: "h1", "h2", "h3", "h4", "h5", "h6"</dt>
                   4597:    <dd>
                   4598: 
                   4599:     <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>
                   4600:     whose tag name is one of "h1", "h2", "h3", "h4", "h5", or "h6",
                   4601:     then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4602: 
                   4603:     <p>Otherwise, run these steps:</p>
                   4604: 
                   4605:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   4606: 
                   4607:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4608:      the same tag name as that of the token, then this is a
                   4609:      <a href="#parse-error">parse error</a>.</p></li>
                   4610: 
                   4611:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4612:      until an element whose tag name is one of "h1", "h2", "h3", "h4",
                   4613:      "h5", or "h6" has been popped from the stack.</p></li>
                   4614: 
                   4615:     </ol></dd>
                   4616: 
                   4617:    <dt>An end tag whose tag name is "sarcasm"</dt>
                   4618:    <dd>
                   4619:     <p>Take a deep breath, then act as described in the "any other end
                   4620:     tag" entry below.</p>
                   4621:    </dd>
                   4622: 
                   4623:    <!-- ADOPTION AGENCY ELEMENTS
                   4624:         Mozilla-only: bdo blink del ins sub sup q
                   4625:         Safari-only: code dfn kbd nobr samp var wbr
                   4626:         Both: a b big em font i s small strike strong tt u -->
                   4627: 
                   4628:    <dt>A start tag whose tag name is "a"</dt>
                   4629:    <dd>
                   4630: 
                   4631:     <p>If the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>
                   4632:     contains an element whose tag name is "a" between the end of
                   4633:     the list and the last marker on the list (or the start of the
                   4634:     list if there is no marker on the list), then this is a
                   4635:     <a href="#parse-error">parse error</a>; act as if an end tag with the tag
                   4636:     name "a" had been seen, then remove that element from the
                   4637:     <a href="#list-of-active-formatting-elements">list of active formatting elements</a> and the
                   4638:     <a href="#stack-of-open-elements">stack of open elements</a> if the end tag didn't
                   4639:     already remove it (it might not have if the element is not
                   4640:     <a href="#has-an-element-in-table-scope" title="has an element in table scope">in table
                   4641:     scope</a>).</p>
                   4642: 
                   4643:     <p class="example">In the non-conforming stream
                   4644:     <code>&lt;a&#160;href="a"&gt;a&lt;table&gt;&lt;a&#160;href="b"&gt;b&lt;/table&gt;x</code>,
                   4645:     the first <code><a href="text-level-semantics.html#the-a-element">a</a></code> element would be closed upon seeing
                   4646:     the second one, and the "x" character would be inside a link
                   4647:     to "b", not to "a". This is despite the fact that the outer
                   4648:     <code><a href="text-level-semantics.html#the-a-element">a</a></code> element is not in table scope (meaning that a
                   4649:     regular <code>&lt;/a&gt;</code> end tag at the start of the table
                   4650:     wouldn't close the outer <code><a href="text-level-semantics.html#the-a-element">a</a></code> element).</p>
                   4651: 
                   4652:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4653:     any.</p>
                   4654: 
                   4655:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
                   4656:     element to the <a href="#list-of-active-formatting-elements">list of active formatting
                   4657:     elements</a>.</p>
                   4658: 
                   4659:    </dd>
                   4660: 
                   4661:    <dt>A start tag whose tag name is one of: "b", "big", "code", "em",
                   4662:    "font", "i", "s", "small", "strike", "strong", "tt", "u"</dt>
                   4663:    <dd>
                   4664: 
                   4665:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4666:     any.</p>
                   4667: 
                   4668:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
                   4669:     element to the <a href="#list-of-active-formatting-elements">list of active formatting
                   4670:     elements</a>.</p>
                   4671: 
                   4672:    </dd>
                   4673: 
                   4674:    <dt>A start tag whose tag name is "nobr"</dt>
                   4675:    <dd>
                   4676: 
                   4677:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4678:     any.</p>
                   4679: 
                   4680:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
                   4681:     element in scope">has a <code>nobr</code> element in scope</a>,
                   4682:     then this is a <a href="#parse-error">parse error</a>; act as if an end tag with
                   4683:     the tag name "nobr" had been seen, then once again
                   4684:     <a href="#reconstruct-the-active-formatting-elements">reconstruct the active formatting elements</a>, if
                   4685:     any.</p>
                   4686: 
                   4687:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
                   4688:     element to the <a href="#list-of-active-formatting-elements">list of active formatting
                   4689:     elements</a>.</p>
                   4690: 
                   4691:    </dd>
                   4692: 
                   4693:    <dt id="adoptionAgency">An end tag whose tag name is one of: "a",
                   4694:    "b", "big", "code", "em", "font", "i", "nobr", "s", "small",
                   4695:    "strike", "strong", "tt", "u"</dt>
                   4696:    <dd>
                   4697: 
                   4698:     <p>Follow these steps:</p>
                   4699: 
                   4700:     <ol><li>
                   4701: 
                   4702:       <p>Let the <var title="">formatting element</var> be the
                   4703:       last element in the <a href="#list-of-active-formatting-elements">list of active formatting
                   4704:       elements</a> that:</p>
                   4705: 
                   4706:       <ul><li>is between the end of the list and the last scope
                   4707:        marker in the list, if any, or the start of the list
                   4708:        otherwise, and</li>
                   4709: 
                   4710:        <li>has the same tag name as the token.</li>
                   4711: 
                   4712:       </ul><p>If there is no such node, or, if that node is also in the
                   4713:       <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
                   4714:       <a href="#parse-error">parse error</a>; ignore the token, and abort these
                   4715:       steps.</p>
                   4716: 
                   4717:       <p>Otherwise, if there is such a node, but that node is not
                   4718:       in the <a href="#stack-of-open-elements">stack of open elements</a>, then this is a
                   4719:       <a href="#parse-error">parse error</a>; remove the element from the list,
                   4720:       and abort these steps.</p>
                   4721: 
                   4722:       <p>Otherwise, there is a <var title="">formatting
                   4723:       element</var> and that element is in <a href="#stack-of-open-elements" title="stack of
                   4724:       open elements">the stack</a> and is <a href="#has-an-element-in-scope" title="has an
                   4725:       element in scope">in scope</a>. If the element is not the
                   4726:       <a href="#current-node">current node</a>, this is a <a href="#parse-error">parse
                   4727:       error</a>. In any case, proceed with the algorithm as
                   4728:       written in the following steps.</p>
                   4729: 
                   4730:      </li>
                   4731: 
                   4732:      <li><p>Let the <var title="">furthest block</var> be the
                   4733:      topmost node in the <a href="#stack-of-open-elements">stack of open elements</a> that
                   4734:      is lower in the stack than the <var title="">formatting
                   4735:      element</var>, and is not an element in the
                   4736:      <a href="#phrasing">phrasing</a> or <a href="#formatting">formatting</a>
                   4737:      categories. There might not be one.</p></li>
                   4738: 
                   4739:      <li><p>If there is no <var title="">furthest block</var>,
                   4740:      then the UA must skip the subsequent steps and instead just
                   4741:      pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of open
                   4742:      elements</a>, from the <a href="#current-node">current node</a> up to and
                   4743:      including the <var title="">formatting element</var>, and
                   4744:      remove the <var title="">formatting element</var> from the
                   4745:      <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</p></li>
                   4746: 
                   4747:      <li><p>Let the <var title="">common ancestor</var> be the element
                   4748:      immediately above the <var title="">formatting element</var> in the
                   4749:      <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
                   4750: 
                   4751:      <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
                   4752:      formatting elements</a> relative to the elements on either
                   4753:      side of it in the list.</p></li>
                   4754: 
                   4755:      <li>
                   4756: 
                   4757:       <p>Let <var title="">node</var> and <var title="">last node</var> be the
                   4758:       <var title="">furthest block</var>. Follow these steps:</p>
                   4759: 
                   4760:       <ol><li>Let <var title="">node</var> be the element immediately
                   4761:        above <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
                   4762:        elements</a>.</li>
                   4763: 
                   4764:        <li>If <var title="">node</var> is not in the <a href="#list-of-active-formatting-elements">list of
                   4765:        active formatting elements</a>, then remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of open
                   4766:        elements</a> and then go back to step 1.</li>
                   4767: 
                   4768:        <li>Otherwise, if <var title="">node</var> is the <var title="">formatting element</var>, then go to the next step
                   4769:        in the overall algorithm.</li>
                   4770: 
                   4771:        <li>Otherwise, if <var title="">last node</var> is the <var title="">furthest block</var>, then move the aforementioned
                   4772:        bookmark to be immediately after the <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
                   4773:        elements</a>.</li>
                   4774: 
                   4775:        <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
                   4776:        element <var title="">node</var> was created, replace the entry
                   4777:        for <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active
                   4778:        formatting elements</a> with an entry for the new element,
                   4779:        replace the entry for <var title="">node</var> in the
                   4780:        <a href="#stack-of-open-elements">stack of open elements</a> with an entry for the new
                   4781:        element, and let <var title="">node</var> be the new
                   4782:        element.</li>
                   4783: 
                   4784:        <li>Insert <var title="">last node</var> into <var title="">node</var>, first removing it from its previous
                   4785:        parent node if any.</li>
                   4786: 
                   4787:        <li>Let <var title="">last node</var> be <var title="">node</var>.</li>
                   4788: 
                   4789:        <li>Return to step 1 of this inner set of steps.</li>
                   4790: 
                   4791:       </ol></li>
                   4792: 
                   4793:      <li>
                   4794: 
                   4795:       <p>If the <var title="">common ancestor</var> node is a
                   4796:       <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>,
                   4797:       <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,
                   4798:       <a href="#foster-parent">foster parent</a> whatever <var title="">last
                   4799:       node</var> ended up being in the previous step, first removing
                   4800:       it from its previous parent node if any.</p>
                   4801: 
                   4802:       <p>Otherwise, append whatever <var title="">last node</var>
                   4803:       ended up being in the previous step to the <var title="">common
                   4804:       ancestor</var> node, first removing it from its previous parent
                   4805:       node if any.</p>
                   4806: 
                   4807:      </li>
                   4808: 
                   4809:      <li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
                   4810:      <var title="">formatting element</var> was created.</p></li>
                   4811: 
                   4812:      <li><p>Take all of the child nodes of the <var title="">furthest
                   4813:      block</var> and append them to the element created in the last
                   4814:      step.</p></li>
                   4815: 
                   4816:      <li><p>Append that new element to the <var title="">furthest
                   4817:      block</var>.</p></li>
                   4818: 
                   4819:      <li><p>Remove the <var title="">formatting element</var> from the
                   4820:      <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, and insert the
                   4821:      new element into the <a href="#list-of-active-formatting-elements">list of active formatting
                   4822:      elements</a> at the position of the aforementioned
                   4823:      bookmark.</p></li>
                   4824: 
                   4825:      <li><p>Remove the <var title="">formatting element</var> from the
                   4826:      <a href="#stack-of-open-elements">stack of open elements</a>, and insert the new element
                   4827:      into the <a href="#stack-of-open-elements">stack of open elements</a> immediately below
                   4828:      the position of the <var title="">furthest block</var> in that
                   4829:      stack.</p></li>
                   4830: 
                   4831:      <li><p>Jump back to step 1 in this series of steps.</p></li>
                   4832: 
                   4833:     </ol><!--XXX
                   4834:     <div class="example">
                   4835:      <p class="XXX">Need an example.</p>
                   4836:     </div>
                   4837: --><p class="note">Because of the way this algorithm causes elements to
                   4838:     change parents, it has been dubbed the "adoption agency algorithm"
                   4839:     (in contrast with other possibly algorithms for dealing with
                   4840:     misnested content, which included the "incest algorithm", the
                   4841:     "secret affair algorithm", and the "Heisenberg algorithm").</p>
                   4842: 
                   4843:    </dd>
                   4844: 
                   4845:    <dt>A start tag whose tag name is "button"</dt>
                   4846:    <dd>
                   4847: 
                   4848:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4849:     an element in scope">has a <code>button</code> element in
                   4850:     scope</a>, then this is a <a href="#parse-error">parse error</a>;
                   4851:     act as if an end tag with the tag name "button" had been seen,
                   4852:     then reprocess the token.</p>
                   4853: 
                   4854:     <p>Otherwise:</p>
                   4855: 
                   4856:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4857:     any.</p>
                   4858: 
                   4859:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4860: 
                   4861:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   4862:     formatting elements</a>.</p>
                   4863: 
                   4864:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   4865: 
                   4866:    </dd>
                   4867: 
                   4868:    <dt>A start tag token whose tag name is one of: "applet",
                   4869:    "marquee", "object"</dt>
                   4870:    <dd>
                   4871: 
                   4872:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4873:     any.</p>
                   4874: 
                   4875:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4876: 
                   4877:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   4878:     formatting elements</a>.</p>
                   4879: 
                   4880:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   4881: 
                   4882:    </dd>
                   4883: 
                   4884:    <dt>An end tag token whose tag name is one of: "applet", "button",
                   4885:    "marquee", "object"</dt>
                   4886:    <dd>
                   4887: 
                   4888:     <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>
                   4889:     with the same tag name as that of the token, then this is a
                   4890:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4891: 
                   4892:     <p>Otherwise, run these steps:</p>
                   4893: 
                   4894:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   4895: 
                   4896:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4897:      the same tag name as that of the token, then this is a
                   4898:      <a href="#parse-error">parse error</a>.</p></li>
                   4899: 
                   4900:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4901:      until an element with the same tag name as the token has been
                   4902:      popped from the stack.</p></li>
                   4903: 
                   4904:      <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
                   4905:      last marker</a>.</li>
                   4906: 
                   4907:     </ol></dd>
                   4908: 
                   4909:    <dt>A start tag whose tag name is "table"</dt>
                   4910:    <dd>
                   4911: 
                   4912:     <p>If the <code>Document</code> is <em>not</em> set to
                   4913:     <a href="dom.html#quirks-mode">quirks mode</a>, and the <a href="#stack-of-open-elements">stack of open
                   4914:     elements</a> <a href="#has-an-element-in-scope" title="has an element in scope">has a
                   4915:     <code>p</code> element in scope</a>, then act as if an end tag
                   4916:     with the tag name "p" had been seen.</p> <!-- i hate myself (this
                   4917:     quirk was basically caused by acid2; if i'd realised we could
                   4918:     change the specs when i wrote acid2, we could have avoided having
                   4919:     any parsing-mode quirks) -Hixie -->
                   4920: 
                   4921:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4922: 
                   4923:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   4924: 
                   4925:     <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>
                   4926: 
                   4927:    </dd>
                   4928: 
                   4929:    <dt>A start tag whose tag name is one of: "area", "basefont",
                   4930:    "bgsound", "br", "embed", "img", "input", "keygen", "spacer",
                   4931:    "wbr"</dt>
                   4932:    <dd>
                   4933: 
                   4934:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4935:     any.</p>
                   4936: 
                   4937:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   4938:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   4939:     elements</a>.</p>
                   4940: 
                   4941:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   4942:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   4943: 
                   4944:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p> <!--
                   4945:     shouldn't really do it for <area>, <basefont>, <bgsound>, and
                   4946:     <spacer> -->
                   4947: 
                   4948:    </dd>
                   4949: 
                   4950:    <dt>A start tag whose tag name is one of: "param", "source"</dt>
                   4951:    <dd>
                   4952: 
                   4953:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   4954:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   4955:     elements</a>.</p>
                   4956: 
                   4957:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   4958:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   4959: 
                   4960:    </dd>
                   4961: 
                   4962:    <dt>A start tag whose tag name is "hr"</dt>
                   4963:    <dd>
                   4964: 
                   4965:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4966:     an element in scope">has a <code>p</code> element in
                   4967:     scope</a>, then act as if an end tag with the tag name
                   4968:     "p" had been seen.</p>
                   4969: 
                   4970:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   4971:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   4972:     elements</a>.</p>
                   4973: 
                   4974:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   4975:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   4976: 
                   4977:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   4978: 
                   4979:    </dd>
                   4980: 
                   4981:    <dt>A start tag whose tag name is "image"</dt>
                   4982:    <dd>
                   4983:     <p><a href="#parse-error">Parse error</a>. Change the token's tag name
                   4984:     to "img" and reprocess it. (Don't ask.)</p> <!-- As of
                   4985:     2005-12, studies showed that around 0.2% of pages used the
                   4986:     <image> element. -->
                   4987:    </dd>
                   4988: 
                   4989:    <dt id="isindex">A start tag whose tag name is "isindex"</dt>
                   4990:    <dd>
                   4991: 
                   4992:     <p><a href="#parse-error">Parse error</a>.</p>
                   4993: 
                   4994:     <p>If the <a href="#form-element-pointer"><code title="">form</code> element
                   4995:     pointer</a> is not null, then ignore the token.</p>
                   4996: 
                   4997:     <p>Otherwise:</p>
                   4998: 
                   4999:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5000:     token's <i>self-closing flag</i></a>, if it is set.</p> <!--
                   5001:     purely to reduce the number of errors (we don't care if they
                   5002:     included the /, they're not supposed to be including the tag at
                   5003:     all! -->
                   5004: 
                   5005:     <p>Act as if a start tag token with the tag name "form" had been seen.</p>
                   5006: 
                   5007:     <p>If the token has an attribute called "action", set the
                   5008:     <code title="attr-form-action">action</code> attribute on the
                   5009:     resulting <code><a href="forms.html#the-form-element">form</a></code> element to the value of the
                   5010:     "action" attribute of the token.</p>
                   5011: 
                   5012:     <p>Act as if a start tag token with the tag name "hr" had been
                   5013:     seen.</p>
                   5014: 
                   5015:     <p>Act as if a start tag token with the tag name "label" had been
                   5016:     seen.</p>
                   5017: 
                   5018:     <p>Act as if a stream of character tokens had been seen (see below
                   5019:     for what they should say).</p>
                   5020: 
                   5021:     <p>Act as if a start tag token with the tag name "input" had been
                   5022:     seen, with all the attributes from the "isindex" token except
                   5023:     "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
                   5024:     <code><a href="forms.html#the-input-element">input</a></code> element to the value "<code title="">isindex</code>".</p>
                   5025: 
                   5026:     <p>Act as if a stream of character tokens had been seen (see
                   5027:     below for what they should say).</p>
                   5028: 
                   5029:     <p>Act as if an end tag token with the tag name "label" had been
                   5030:     seen.</p>
                   5031: 
                   5032:     <p>Act as if a start tag token with the tag name "hr" had been
                   5033:     seen.</p>
                   5034: 
                   5035:     <p>Act as if an end tag token with the tag name "form" had been
                   5036:     seen.</p>
                   5037: 
                   5038:     <p>If the token has an attribute with the name "prompt", then the
                   5039:     first stream of characters must be the same string as given in
                   5040:     that attribute, and the second stream of characters must be
                   5041:     empty. Otherwise, the two streams of character tokens together
                   5042:     should, together with the <code><a href="forms.html#the-input-element">input</a></code> element, express the
                   5043:     equivalent of "This is a searchable index. Insert your search
                   5044:     keywords here: (input field)" in the user's preferred
                   5045:     language.</p>
                   5046: 
                   5047:    </dd>
                   5048: 
                   5049:    <dt>A start tag whose tag name is "textarea"</dt>
                   5050:    <dd>
                   5051: 
                   5052:     <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
                   5053:      token.</p></li>
                   5054: 
                   5055:      <li><p>If the next token is a U+000A LINE FEED (LF) character
                   5056:      token, then ignore that token and move on to the next
                   5057:      one. (Newlines at the start of <code><a href="forms.html#the-textarea-element">textarea</a></code> elements are
                   5058:      ignored as an authoring convenience.)</p></li>
                   5059: 
                   5060:      <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
                   5061:      the RCDATA state.</p></li>
                   5062: 
                   5063:      <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the
                   5064:      current <a href="#insertion-mode">insertion mode</a>.</p>
                   5065: 
                   5066:      </li><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not
                   5067:      ok".</p></li>
                   5068: 
1.91      mike     5069:      <li><p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: in RAWTEXT/RCDATA">in
                   5070:      RAWTEXT/RCDATA</a>".</p></li>
1.1       mike     5071: 
                   5072:     </ol></dd>
                   5073: 
                   5074:    <dt>A start tag whose tag name is "xmp"</dt>
                   5075:    <dd>
                   5076: 
                   5077:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5078:     any.</p>
                   5079: 
                   5080:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5081: 
1.91      mike     5082:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     5083: 
                   5084:    </dd>
                   5085: 
                   5086:    <dt>A start tag whose tag name is "iframe"</dt>
                   5087:    <dd>
                   5088: 
                   5089:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5090: 
1.91      mike     5091:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     5092: 
                   5093:    </dd>
                   5094: 
                   5095:    <dt>A start tag whose tag name is "noembed"</dt>
                   5096:    <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
                   5097:    <dd>
                   5098: 
1.91      mike     5099:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     5100: 
                   5101:    </dd>
                   5102: 
                   5103:    <dt>A start tag whose tag name is "select"</dt>
                   5104:    <dd>
                   5105: 
                   5106:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5107:     any.</p>
                   5108: 
                   5109:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5110: 
                   5111:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5112: 
                   5113:     <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>",
                   5114:     "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   5115:     body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in
                   5116:     row</a>", or "<a href="#parsing-main-intd" title="insertion mode: in cell">in
                   5117:     cell</a>", then switch the <a href="#insertion-mode">insertion mode</a> to
                   5118:     "<a href="#parsing-main-inselectintable" title="insertion mode: in select in table">in select in
                   5119:     table</a>". Otherwise, switch the <a href="#insertion-mode">insertion mode</a>
                   5120:     to "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>".</p>
                   5121: 
                   5122:    </dd>
                   5123: 
                   5124:    <dt>A start tag whose tag name is one of: "optgroup", "option"</dt>
                   5125:    <dd>
                   5126: 
                   5127:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
                   5128:     element in scope">has an <code>option</code> element in
                   5129:     scope</a>, then act as if an end tag with the tag name "option"
                   5130:     had been seen.</p>
                   5131: 
                   5132:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5133:     any.</p>
                   5134: 
                   5135:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5136: 
                   5137:    </dd>
                   5138: 
                   5139:    <dt>A start tag whose tag name is one of: "rp", "rt"</dt>
                   5140:    <dd>
                   5141: 
                   5142:     <!-- the parsing rules for ruby really don't match IE much at all,
                   5143:          but in practice the markup used is very simple and so strict
                   5144:          compatibility with IE isn't required. For example, as defined
                   5145:          here we get very, very different behaviour than IE for
                   5146:          pathological cases like:
                   5147: 
                   5148:            <ruby><ol><li><p>a<rt>b
                   5149:            <ruby>a<rt>b<p>c
                   5150: 
                   5151:          But in practice most ruby markup falls into these cases:
                   5152: 
                   5153:            <ruby>a<rt>b</ruby>
                   5154:            <ruby>a<rp>b<rt>c<rp>d</ruby>
                   5155:            <ruby>a<rt>b</rt></ruby>
                   5156:            <ruby>a<rp>b</rp><rt>c</rt><rp>d</rp></ruby>
                   5157: 
                   5158:     -->
                   5159: 
                   5160:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
                   5161:     element in scope">has a <code>ruby</code> element in scope</a>,
                   5162:     then <a href="#generate-implied-end-tags">generate implied end tags</a>. If the <a href="#current-node">current
                   5163:     node</a> is not then a <code><a href="text-level-semantics.html#the-ruby-element">ruby</a></code> element, this is a
                   5164:     <a href="#parse-error">parse error</a>; pop all the nodes from the <a href="#current-node">current
                   5165:     node</a> up to the node immediately before the bottommost
                   5166:     <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
                   5167:     elements</a>.</p>
                   5168: 
                   5169:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5170: 
                   5171:    </dd>
                   5172: 
                   5173:    <dt>An end tag whose tag name is "br"</dt>
                   5174:    <dd>
                   5175:     <p><a href="#parse-error">Parse error</a>. Act as if a start tag token with
                   5176:     the tag name "br" had been seen. Ignore the end tag token.</p>
                   5177:    </dd>
                   5178: 
                   5179:    <dt>A start tag whose tag name is "math"</dt>
                   5180:    <dd>
                   5181: 
                   5182:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5183:     any.</p>
                   5184: 
                   5185:     <p><a href="#adjust-mathml-attributes">Adjust MathML attributes</a> for the token. (This
                   5186:     fixes the case of MathML attributes that are not all
                   5187:     lowercase.)</p>
                   5188: 
                   5189:     <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
                   5190:     fixes the use of namespaced attributes, in particular XLink.)</p>
                   5191: 
                   5192:     <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
                   5193:     <a href="#mathml-namespace">MathML namespace</a>.</p>
                   5194: 
                   5195:     <!-- If we ever change the frameset-ok flag to an insertion mode,
                   5196:     the following change would be implied, except we'd have to do it
                   5197:     even in the face of a self-closed tag:
                   5198:     <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
                   5199:     -->
                   5200: 
                   5201:     <p>If the token has its <i>self-closing flag</i> set, pop the
                   5202:     <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5203:     elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
                   5204:     flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
                   5205: 
                   5206:     <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
                   5207:     "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
                   5208:     content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
                   5209:     the current <a href="#insertion-mode">insertion mode</a>, and then switch the
                   5210:     <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
                   5211:     foreign content">in foreign content</a>".</p>
                   5212: 
                   5213:    </dd>
                   5214: 
                   5215:    <dt>A start tag whose tag name is "svg"</dt>
                   5216:    <dd>
                   5217: 
                   5218:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5219:     any.</p>
                   5220: 
                   5221:     <p><a href="#adjust-svg-attributes">Adjust SVG attributes</a> for the token. (This fixes
                   5222:     the case of SVG attributes that are not all lowercase.)</p>
                   5223: 
                   5224:     <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
                   5225:     fixes the use of namespaced attributes, in particular XLink in
                   5226:     SVG.)</p>
                   5227: 
                   5228:     <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
                   5229:     <a href="#svg-namespace">SVG namespace</a>.</p>
                   5230: 
                   5231:     <!-- If we ever change the frameset-ok flag to an insertion mode,
                   5232:     the following change would be implied, except we'd have to do it
                   5233:     even in the face of a self-closed tag:
                   5234:     <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
                   5235:     -->
                   5236: 
                   5237:     <p>If the token has its <i>self-closing flag</i> set, pop the
                   5238:     <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5239:     elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
                   5240:     flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
                   5241: 
                   5242:     <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
                   5243:     "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
                   5244:     content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
                   5245:     the current <a href="#insertion-mode">insertion mode</a>, and then switch the
                   5246:     <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
                   5247:     foreign content">in foreign content</a>".</p>
                   5248: 
                   5249:    </dd>
                   5250: 
                   5251:    <dt>A start <!--or end--> tag whose tag name is one of: "caption",
                   5252:    "col", "colgroup", "frame", "head", "tbody", "td", "tfoot", "th",
                   5253:    "thead", "tr"</dt>
                   5254:    <!--<dt>An end tag whose tag name is one of: "area", "base",
                   5255:    "basefont", "bgsound", "command", "embed", "hr", "iframe", "image",
                   5256:    "img", "input", "isindex", "keygen", "link", "meta", "noembed",
                   5257:    "noframes", "param", "script", "select", "source", "spacer",
                   5258:    "style", "table", "textarea", "title", "wbr"</dt>-->
                   5259:    <!--<dt>An end tag whose tag name is "noscript", if the
                   5260:    <span>scripting flag</span> is enabled</dt>-->
                   5261:    <dd>
                   5262:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5263:     <!-- end tags are commented out because since they can never end
                   5264:     up on the stack anyway, the default end tag clause will
                   5265:     automatically handle them. we don't want to have text in the spec
                   5266:     that is just an optimisation, as that detracts from the spec
                   5267:     itself -->
                   5268:    </dd>
                   5269: 
                   5270:    <dt>Any other start tag</dt>
                   5271:    <dd>
                   5272: 
                   5273:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5274:     any.</p>
                   5275: 
                   5276:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5277: 
                   5278:     <p class="note">This element will be a <a href="#phrasing">phrasing</a>
                   5279:     element.</p>
                   5280: 
                   5281:    </dd>
                   5282: 
                   5283:    <dt>Any other end tag</dt>
                   5284:    <dd>
                   5285: 
                   5286:     <p>Run the following steps:</p>
                   5287: 
                   5288:     <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   5289:      node</a> (the bottommost node of the stack).</p></li>
                   5290: 
                   5291:      <li><p>If <var title="">node</var> has the same tag name as
                   5292:      the end tag token, then:</p>
                   5293: 
                   5294:       <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   5295: 
                   5296:        <li><p>If the tag name of the end tag token does not match
                   5297:        the tag name of the <a href="#current-node">current node</a>, this is a
                   5298:        <a href="#parse-error">parse error</a>.</p></li>
                   5299: 
                   5300:        <li><p>Pop all the nodes from the <a href="#current-node">current node</a> up
                   5301:        to <var title="">node</var>, including <var title="">node</var>, then stop these steps.</p></li>
                   5302: 
                   5303:       </ol></li>
                   5304: 
                   5305:      <li><p>Otherwise, if <var title="">node</var> is in neither the
                   5306:      <a href="#formatting">formatting</a> category nor the <a href="#phrasing">phrasing</a>
                   5307:      category, then this is a <a href="#parse-error">parse error</a>; ignore the
                   5308:      token, and abort these steps.</p></li>
                   5309: 
                   5310:      <li><p>Set <var title="">node</var> to the previous entry in the
                   5311:      <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
                   5312: 
                   5313:      <li><p>Return to step 2.</p></li>
                   5314: 
                   5315:     </ol></dd>
                   5316: 
1.91      mike     5317:   </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     5318: 
                   5319:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incdata" title="insertion
1.91      mike     5320:   mode: in RAWTEXT/RCDATA">in RAWTEXT/RCDATA</a>", tokens must be
1.1       mike     5321:   handled as follows:</p>
                   5322: 
                   5323:   <dl class="switch"><dt>A character token</dt>
                   5324:    <dd>
                   5325: 
                   5326:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   5327:     character</a> into the <a href="#current-node">current node</a>.</p>
                   5328: 
                   5329:    </dd>
                   5330: 
                   5331:    <dt>An end-of-file token</dt>
                   5332:    <dd>
                   5333: 
                   5334:     <!-- can't be the fragment case -->
                   5335:     <p><a href="#parse-error">Parse error</a>.</p>
                   5336: 
                   5337:     <p>If the <a href="#current-node">current node</a> is a <code><a href="semantics.html#script">script</a></code>
                   5338:     element, mark the <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-executed">"already
                   5339:     executed"</a>.</p>
                   5340: 
                   5341:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5342:     elements</a>.</p>
                   5343: 
                   5344:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5345:     insertion mode</a> and reprocess the current token.</p>
                   5346: 
                   5347:    </dd>
                   5348: 
                   5349:    <dt>An end tag whose tag name is "script"</dt>
                   5350:    <dd>
                   5351: 
                   5352:     <p>Let <var title="">script</var> be the <a href="#current-node">current node</a>
                   5353:     (which will be a <code><a href="semantics.html#script">script</a></code> element).</p>
                   5354: 
                   5355:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5356:     elements</a>.</p>
                   5357: 
                   5358:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5359:     insertion mode</a>.</p>
                   5360: 
                   5361:     <p>Let the <var title="">old insertion point</var> have the
                   5362:     same value as the current <a href="#insertion-point">insertion point</a>. Let
                   5363:     the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
                   5364:     input character</a>.</p>
                   5365: 
                   5366:     <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
                   5367:     one.</p>
                   5368: 
                   5369:     <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     5370:     which might cause <a href="embedded-content-0.html#dom-document-write" title="dom-document-write">new characters
1.1       mike     5371:     to be inserted into the tokenizer</a>, and might cause the
                   5372:     tokenizer to output more tokens, resulting in a <a href="#nestedParsing">reentrant invocation of the parser</a>.</p>
                   5373: 
                   5374:     <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
                   5375:     one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
                   5376:     then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
                   5377: 
                   5378:     <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
                   5379:     <a href="#insertion-point">insertion point</a> to its previous value. This value
                   5380:     might be the "undefined" value.)</p>
                   5381: 
                   5382:     <p id="scriptTagParserResumes">At this stage, if there is a
                   5383:     <a href="semantics.html#pending-external-script">pending external script</a>, then:</p>
                   5384: 
                   5385:     <dl class="switch"><dt>If the <a href="#script-nesting-level">script nesting level</a> is not zero:</dt>
                   5386: 
                   5387:      <dd>
                   5388: 
                   5389:       <p>Set the <a href="#parser-pause-flag">parser pause flag</a> to true, and abort the
                   5390:       processing of any nested invocations of the tokenizer, yielding
                   5391:       control back to the caller. (Tokenization will resume when the
                   5392:       caller returns to the "outer" tree construction stage.)</p>
                   5393: 
                   5394:       <p class="note">The tree construction stage of this particular
                   5395:       parser is <a href="#nestedParsing">being called reentrantly</a>,
1.159     mike     5396:       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     5397: 
                   5398:      </dd>
                   5399: 
                   5400: 
                   5401:      <dt>Otherwise:</dt>
                   5402: 
                   5403:      <dd>
                   5404: 
                   5405:       <p>Follow these steps:</p>
                   5406: 
                   5407:       <ol><li><p>Let <var title="">the script</var> be the <a href="semantics.html#pending-external-script">pending
                   5408:        external script</a>. There is no longer a <a href="semantics.html#pending-external-script">pending
                   5409:        external script</a>.</p></li>
                   5410: 
                   5411:        <li><p><a href="browsers.html#pause">Pause</a> until the script has <a href="semantics.html#completed-loading">completed
                   5412:        loading</a>.</p></li>
                   5413: 
                   5414:        <li><p>Let the <a href="#insertion-point">insertion point</a> be just before the
                   5415:        <a href="#next-input-character">next input character</a>.</p></li>
                   5416: 
                   5417:        <li><p>Increment the parser's <a href="#script-nesting-level">script nesting level</a>
                   5418:        by one (it should be zero before this step, so this sets it to
                   5419:        one).</p></li>
                   5420: 
                   5421:        <li><p><a href="semantics.html#executing-a-script-block" title="executing a script block">Execute the
                   5422:        script</a>.</p></li>
                   5423: 
                   5424:        <li><p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a>
                   5425:        by one. If the parser's <a href="#script-nesting-level">script nesting level</a> is
                   5426:        zero (which it always should be at this point), then set the
                   5427:        <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
                   5428: 
                   5429:        </li><li><p>Let the <a href="#insertion-point">insertion point</a> be undefined
                   5430:        again.</p></li>
                   5431: 
                   5432:        <li><p>If there is once again a <a href="semantics.html#pending-external-script">pending external
                   5433:        script</a>, then repeat these steps from step 1.</p></li>
                   5434: 
                   5435:       </ol></dd>
                   5436: 
                   5437:     </dl></dd>
                   5438: 
                   5439:    <dt>Any other end tag</dt>
                   5440:    <dd>
                   5441: 
                   5442:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5443:     elements</a>.</p>
                   5444: 
                   5445:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5446:     insertion mode</a>.</p>
                   5447: 
                   5448:    </dd>
                   5449: 
                   5450:   </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>
                   5451: 
                   5452:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion
                   5453:   mode: in table">in table</a>", tokens must be handled as follows:</p>
                   5454: 
                   5455:   <dl class="switch"><dt>A character token</dt>
                   5456:    <dd>
                   5457: 
                   5458:      <p>Let the <dfn id="pending-table-character-tokens"><var>pending table character tokens</var></dfn>
                   5459:      be an empty list of tokens.</p>
                   5460: 
                   5461:      <p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
                   5462:      <a href="#insertion-mode">insertion mode</a>.</p>
                   5463: 
                   5464:      <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
                   5465:      reprocess the token.</p>
                   5466: 
                   5467:    </dd>
                   5468: 
                   5469:    <dt>A comment token</dt>
                   5470:    <dd>
                   5471:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   5472:     node</a> with the <code title="">data</code> attribute set to
                   5473:     the data given in the comment token.</p>
                   5474:    </dd>
                   5475: 
                   5476:    <dt>A DOCTYPE token</dt>
                   5477:    <dd>
                   5478:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5479:    </dd>
                   5480: 
                   5481:    <dt>A start tag whose tag name is "caption"</dt>
                   5482:    <dd>
                   5483: 
                   5484:     <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
                   5485:     below.)</p>
                   5486: 
                   5487:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   5488:     formatting elements</a>.</p>
                   5489: 
                   5490:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
                   5491:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>".</p>
                   5492: 
                   5493:    </dd>
                   5494: 
                   5495:    <dt>A start tag whose tag name is "colgroup"</dt>
                   5496:    <dd>
                   5497: 
                   5498:     <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
                   5499:     below.)</p>
                   5500: 
                   5501:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
                   5502:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column
                   5503:     group</a>".</p>
                   5504: 
                   5505:    </dd>
                   5506: 
                   5507:    <dt>A start tag whose tag name is "col"</dt>
                   5508:    <dd>
                   5509:     <p>Act as if a start tag token with the tag name "colgroup"
                   5510:     had been seen, then reprocess the current token.</p>
                   5511:    </dd>
                   5512: 
                   5513:    <dt>A start tag whose tag name is one of: "tbody", "tfoot", "thead"</dt>
                   5514:    <dd>
                   5515: 
                   5516:     <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
                   5517:     below.)</p>
                   5518: 
                   5519:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
                   5520:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   5521:     body</a>".</p>
                   5522: 
                   5523:    </dd>
                   5524: 
                   5525:    <dt>A start tag whose tag name is one of: "td", "th", "tr"</dt>
                   5526:    <dd>
                   5527:     <p>Act as if a start tag token with the tag name "tbody" had
                   5528:     been seen, then reprocess the current token.</p>
                   5529:    </dd>
                   5530: 
                   5531:    <dt>A start tag whose tag name is "table"</dt>
                   5532:    <dd>
                   5533: 
                   5534:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag token with
                   5535:     the tag name "table" had been seen, then, if that token wasn't
                   5536:     ignored, reprocess the current token.</p>
                   5537: 
                   5538:     <p class="note">The fake end tag token here can only be
                   5539:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   5540: 
                   5541:    </dd>
                   5542: 
                   5543:    <dt>An end tag whose tag name is "table"</dt>
                   5544:    <dd>
                   5545: 
                   5546:     <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
                   5547:     scope</a> with the same tag name as the token, this is a
                   5548:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   5549:     case</a>)</p>
                   5550: 
                   5551:     <p>Otherwise:</p>
                   5552: 
                   5553:     <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-table-element">table</a></code>
                   5554:     element has been popped from the stack.</p>
                   5555: 
                   5556:     <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
                   5557: 
                   5558:    </dd>
                   5559: 
                   5560:    <dt>An end tag whose tag name is one of: "body", "caption",
                   5561:    "col", "colgroup", "html", "tbody", "td", "tfoot", "th",
                   5562:    "thead", "tr"</dt>
                   5563:    <dd>
                   5564:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5565:    </dd>
                   5566: 
                   5567:    <dt>A start tag whose tag name is one of: "style", "script"</dt>
                   5568:    <dd>
                   5569: 
                   5570:     <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
                   5571:     mode</a>.</p>
                   5572: 
                   5573:    </dd>
                   5574: 
                   5575:    <dt>A start tag whose tag name is "input"</dt>
                   5576:    <dd>
                   5577: 
                   5578:     <p>If the token does not have an attribute with the name "type",
                   5579:     or if it does, but that attribute's value is not an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   5580:     case-insensitive</a> match for the string "<code title="">hidden</code>", then: act as described in the "anything
                   5581:     else" entry below.</p>
                   5582: 
                   5583:     <p>Otherwise:</p>
                   5584: 
                   5585:     <p><a href="#parse-error">Parse error</a>.</p>
                   5586: 
                   5587:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5588: 
                   5589:     <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
                   5590:     open elements</a>.</p>
                   5591: 
                   5592:    </dd>
                   5593: 
                   5594:    <dt>An end-of-file token</dt>
                   5595:    <dd>
                   5596: 
                   5597:     <p>If the <a href="#current-node">current node</a> is not the root
1.159     mike     5598:     <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     5599:     error</a>.</p>
                   5600: 
                   5601:     <p class="note">It can only be the <a href="#current-node">current node</a> in
                   5602:     the <a href="#fragment-case">fragment case</a>.</p>
                   5603: 
                   5604:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   5605: 
                   5606:    </dd>
                   5607: 
                   5608:    <dt>Anything else</dt>
                   5609:    <dd>
                   5610: 
                   5611:     <p><a href="#parse-error">Parse error</a>. Process the token <a href="#using-the-rules-for">using the
                   5612:     rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   5613:     body</a>" <a href="#insertion-mode">insertion mode</a>, except that if the
                   5614:     <a href="#current-node">current node</a> is a <code><a href="tabular-data.html#the-table-element">table</a></code>,
                   5615:     <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
                   5616:     <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then, whenever a node would be inserted
                   5617:     into the <a href="#current-node">current node</a>, it must instead be <a href="#foster-parent" title="foster parent">foster parented</a>.</p>
                   5618: 
                   5619:    </dd>
                   5620: 
                   5621:   </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-context">clear the stack
                   5622:   back to a table context</dfn>, it means that the UA must, while
                   5623:   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     5624:   element or an <code><a href="semantics.html#the-html-element-0">html</a></code> element, pop elements from the
1.1       mike     5625:   <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   5626: 
                   5627:   <p class="note">The <a href="#current-node">current node</a> being an
1.159     mike     5628:   <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     5629:   case</a>.</p>
                   5630: 
                   5631: 
                   5632: 
                   5633:   <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>
                   5634: 
                   5635:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intabletext" title="insertion
                   5636:   mode: in table text">in table text</a>", tokens must be handled
                   5637:   as follows:</p>
                   5638: 
                   5639:   <dl class="switch"><dt>A character token</dt>
                   5640:    <dd>
                   5641: 
                   5642:     <p>Append the character token to the <var><a href="#pending-table-character-tokens">pending table character
                   5643:     tokens</a></var> list.</p>
                   5644: 
                   5645:    </dd>
                   5646: 
                   5647: 
                   5648:    <dt>Anything else</dt>
                   5649:    <dd>
                   5650: 
                   5651:     <p>If any of the tokens in the <var><a href="#pending-table-character-tokens">pending table character
                   5652:     tokens</a></var> list are character tokens that are not one of U+0009
                   5653:     CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED
                   5654:     (FF), <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE, then
                   5655:     reprocess those character tokens using the rules given in the
                   5656:     "anything else" entry in the <a href="#parsing-main-intable" title="insertion mode: in
                   5657:     table">in table</a>" insertion mode.</p>
                   5658: 
                   5659:     <p>Otherwise, <a href="#insert-a-character" title="insert a character">insert the
                   5660:     characters</a> given by the <var><a href="#pending-table-character-tokens">pending table character
                   5661:     tokens</a></var> list into the <a href="#current-node">current node</a>.</p>
                   5662: 
                   5663:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5664:     insertion mode</a> and reprocess the token.</p>
                   5665: 
                   5666:    </dd>
                   5667: 
                   5668:   </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>
                   5669: 
                   5670:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incaption" title="insertion
                   5671:   mode: in caption">in caption</a>", tokens must be handled as follows:</p>
                   5672: 
                   5673:   <dl class="switch"><dt>An end tag whose tag name is "caption"</dt>
                   5674:    <dd>
                   5675: 
                   5676:     <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
                   5677:     scope</a> with the same tag name as the token, this is a
                   5678:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   5679:     case</a>)</p>
                   5680: 
                   5681:     <p>Otherwise:</p>
                   5682: 
                   5683:     <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
                   5684: 
                   5685:     <p>Now, if the <a href="#current-node">current node</a> is not a
                   5686:     <code><a href="tabular-data.html#the-caption-element">caption</a></code> element, then this is a <a href="#parse-error">parse
                   5687:     error</a>.</p>
                   5688: 
                   5689:     <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-caption-element">caption</a></code>
                   5690:     element has been popped from the stack.</p>
                   5691: 
                   5692:     <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
                   5693:     the last marker</a>.</p>
                   5694: 
                   5695:     <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>
                   5696: 
                   5697:    </dd>
                   5698: 
                   5699:    <dt>A start tag whose tag name is one of: "caption", "col",
                   5700:    "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
                   5701:    <dt>An end tag whose tag name is "table"</dt>
                   5702:    <dd>
                   5703: 
                   5704:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
                   5705:     name "caption" had been seen, then, if that token wasn't
                   5706:     ignored, reprocess the current token.</p>
                   5707: 
                   5708:     <p class="note">The fake end tag token here can only be
                   5709:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   5710: 
                   5711:    </dd>
                   5712: 
                   5713:    <dt>An end tag whose tag name is one of: "body", "col",
                   5714:    "colgroup", "html", "tbody", "td", "tfoot", "th", "thead",
                   5715:    "tr"</dt>
                   5716:    <dd>
                   5717:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5718:    </dd>
                   5719: 
                   5720:    <dt>Anything else</dt>
                   5721:    <dd>
                   5722:     <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
                   5723:     mode</a>.</p>
                   5724:    </dd>
                   5725: 
                   5726:   </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>
                   5727: 
                   5728:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incolgroup" title="insertion
                   5729:   mode: in column group">in column group</a>", tokens must be handled as follows:</p>
                   5730: 
                   5731:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   5732:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   5733:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   5734:    <dd>
                   5735:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   5736:     the <a href="#current-node">current node</a>.</p>
                   5737:    </dd>
                   5738: 
                   5739:    <dt>A comment token</dt>
                   5740:    <dd>
                   5741:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   5742:     node</a> with the <code title="">data</code> attribute set to
                   5743:     the data given in the comment token.</p>
                   5744:    </dd>
                   5745: 
                   5746:    <dt>A DOCTYPE token</dt>
                   5747:    <dd>
                   5748:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5749:    </dd>
                   5750: 
                   5751:    <dt>A start tag whose tag name is "html"</dt>
                   5752:    <dd>
                   5753:     <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
                   5754:     mode</a>.</p>
                   5755:    </dd>
                   5756: 
                   5757:    <dt>A start tag whose tag name is "col"</dt>
                   5758:    <dd>
                   5759: 
                   5760:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5761:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5762:     elements</a>.</p>
                   5763: 
                   5764:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5765:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5766: 
                   5767:    </dd>
                   5768: 
                   5769:    <dt>An end tag whose tag name is "colgroup"</dt>
                   5770:    <dd>
                   5771: 
                   5772:     <p>If the <a href="#current-node">current node</a> is the root
1.159     mike     5773:     <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     5774:     error</a>; ignore the token. (<a href="#fragment-case">fragment
                   5775:     case</a>)</p>
                   5776: 
                   5777:     <p>Otherwise, pop the <a href="#current-node">current node</a> (which will be
                   5778:     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
                   5779:     elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
                   5780:     "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
                   5781: 
                   5782:    </dd>
                   5783: 
                   5784:    <dt>An end tag whose tag name is "col"</dt>
                   5785:    <dd>
                   5786:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5787:    </dd>
                   5788: 
                   5789:    <dt>An end-of-file token</dt>
                   5790:    <dd>
                   5791: 
1.159     mike     5792:     <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     5793:     element, then <a href="#stop-parsing">stop parsing</a>. (<a href="#fragment-case">fragment
                   5794:     case</a>)</p>
                   5795: 
                   5796:     <p>Otherwise, act as described in the "anything else" entry
                   5797:     below.</p>
                   5798: 
                   5799:    </dd>
                   5800: 
                   5801:    <dt>Anything else</dt>
                   5802:    <dd>
                   5803: 
                   5804:     <p>Act as if an end tag with the tag name "colgroup" had been
                   5805:     seen, and then, if that token wasn't ignored, reprocess the
                   5806:     current token.</p>
                   5807: 
                   5808:     <p class="note">The fake end tag token here can only be
                   5809:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   5810: 
                   5811:    </dd>
                   5812: 
                   5813:   </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>
                   5814: 
                   5815:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion
                   5816:   mode: in table body">in table body</a>", tokens must be handled as follows:</p>
                   5817: 
                   5818:   <dl class="switch"><dt>A start tag whose tag name is "tr"</dt>
                   5819:    <dd>
                   5820: 
                   5821:     <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
                   5822:     context</a>. (See below.)</p>
                   5823: 
                   5824:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
                   5825:     the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion mode:
                   5826:     in row">in row</a>".</p>
                   5827: 
                   5828:    </dd>
                   5829: 
                   5830:    <dt>A start tag whose tag name is one of: "th", "td"</dt>
                   5831:    <dd>
                   5832:     <p><a href="#parse-error">Parse error</a>. Act as if a start tag with
                   5833:     the tag name "tr" had been seen, then reprocess the current
                   5834:     token.</p>
                   5835:    </dd>
                   5836: 
                   5837:    <dt>An end tag whose tag name is one of: "tbody", "tfoot",
                   5838:    "thead"</dt>
                   5839:    <dd>
                   5840: 
                   5841:     <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
                   5842:     scope</a> with the same tag name as the token, this is a
                   5843:     <a href="#parse-error">parse error</a>. Ignore the token.</p>
                   5844: 
                   5845:     <p>Otherwise:</p>
                   5846: 
                   5847:     <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
                   5848:     context</a>. (See below.)</p>
                   5849: 
                   5850:     <p>Pop the <a href="#current-node">current node</a> from the <a href="#stack-of-open-elements">stack of
                   5851:     open elements</a>. Switch the <a href="#insertion-mode">insertion mode</a>
                   5852:     to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
                   5853: 
                   5854:    </dd>
                   5855: 
                   5856:    <dt>A start tag whose tag name is one of: "caption", "col",
                   5857:    "colgroup", "tbody", "tfoot", "thead"</dt>
                   5858:    <dt>An end tag whose tag name is "table"</dt>
                   5859:    <dd>
                   5860: 
                   5861:     <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
                   5862:     <code>tbody</code>, <code>thead</code>, or <code>tfoot</code>
                   5863:     element in table scope</a>, this is a <a href="#parse-error">parse
                   5864:     error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   5865:     case</a>)</p>
                   5866: 
                   5867:     <p>Otherwise:</p>
                   5868: 
                   5869:     <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
                   5870:     context</a>. (See below.)</p>
                   5871: 
                   5872:     <p>Act as if an end tag with the same tag name as the
                   5873:     <a href="#current-node">current node</a> ("tbody", "tfoot", or "thead") had
                   5874:     been seen, then reprocess the current token.</p>
                   5875: 
                   5876:    </dd>
                   5877: 
                   5878:    <dt>An end tag whose tag name is one of: "body", "caption",
                   5879:    "col", "colgroup", "html", "td", "th", "tr"</dt>
                   5880:    <dd>
                   5881:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5882:    </dd>
                   5883: 
                   5884:    <dt>Anything else</dt>
                   5885:    <dd>
                   5886:     <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
                   5887:     mode</a>.</p>
                   5888:    </dd>
                   5889: 
                   5890:   </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-body-context">clear the stack
                   5891:   back to a table body context</dfn>, it means that the UA must,
                   5892:   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     5893:   <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     5894:   element, pop elements from the <a href="#stack-of-open-elements">stack of open
                   5895:   elements</a>.</p>
                   5896: 
                   5897:   <p class="note">The <a href="#current-node">current node</a> being an
1.159     mike     5898:   <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     5899:   case</a>.</p>
                   5900: 
                   5901: 
                   5902:   <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>
                   5903: 
                   5904:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
                   5905:   mode: in row">in row</a>", tokens must be handled as follows:</p>
                   5906: 
                   5907:   <dl class="switch"><dt>A start tag whose tag name is one of: "th", "td"</dt>
                   5908:    <dd>
                   5909: 
                   5910:     <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
                   5911:     context</a>. (See below.)</p>
                   5912: 
                   5913:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
                   5914:     the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion mode:
                   5915:     in cell">in cell</a>".</p>
                   5916: 
                   5917:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   5918:     formatting elements</a>.</p>
                   5919: 
                   5920:    </dd>
                   5921: 
                   5922:    <dt>An end tag whose tag name is "tr"</dt>
                   5923:    <dd>
                   5924: 
                   5925:     <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
                   5926:     scope</a> with the same tag name as the token, this is a
                   5927:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   5928:     case</a>)</p>
                   5929: 
                   5930:     <p>Otherwise:</p>
                   5931: 
                   5932:     <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
                   5933:     context</a>. (See below.)</p>
                   5934: 
                   5935:     <p>Pop the <a href="#current-node">current node</a> (which will be a
                   5936:     <code><a href="tabular-data.html#the-tr-element">tr</a></code> element) from the <a href="#stack-of-open-elements">stack of open
                   5937:     elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
                   5938:     "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   5939:     body</a>".</p>
                   5940: 
                   5941:    </dd>
                   5942: 
                   5943:    <dt>A start tag whose tag name is one of: "caption", "col",
                   5944:    "colgroup", "tbody", "tfoot", "thead", "tr"</dt>
                   5945:    <dt>An end tag whose tag name is "table"</dt>
                   5946:    <dd>
                   5947: 
                   5948:     <p>Act as if an end tag with the tag name "tr" had been seen,
                   5949:     then, if that token wasn't ignored, reprocess the current
                   5950:     token.</p>
                   5951: 
                   5952:     <p class="note">The fake end tag token here can only be
                   5953:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   5954: 
                   5955:    </dd>
                   5956: 
                   5957:    <dt>An end tag whose tag name is one of: "tbody", "tfoot",
                   5958:    "thead"</dt>
                   5959:    <dd>
                   5960: 
                   5961:     <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
                   5962:     scope</a> with the same tag name as the token, this is a
                   5963:     <a href="#parse-error">parse error</a>. Ignore the token.</p>
                   5964: 
                   5965:     <p>Otherwise, act as if an end tag with the tag name "tr" had
                   5966:     been seen, then reprocess the current token.</p>
                   5967: 
                   5968:    </dd>
                   5969: 
                   5970:    <dt>An end tag whose tag name is one of: "body", "caption",
                   5971:    "col", "colgroup", "html", "td", "th"</dt>
                   5972:    <dd>
                   5973:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5974:    </dd>
                   5975: 
                   5976:    <dt>Anything else</dt>
                   5977:    <dd>
                   5978:     <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
                   5979:     mode</a>.</p>
                   5980:    </dd>
                   5981: 
                   5982:   </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-row-context">clear the stack
                   5983:   back to a table row context</dfn>, it means that the UA must,
                   5984:   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     5985:   element or an <code><a href="semantics.html#the-html-element-0">html</a></code> element, pop elements from the
1.1       mike     5986:   <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   5987: 
                   5988:   <p class="note">The <a href="#current-node">current node</a> being an
1.159     mike     5989:   <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     5990:   case</a>.</p>
                   5991: 
                   5992: 
                   5993:   <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>
                   5994: 
                   5995:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intd" title="insertion
                   5996:   mode: in cell">in cell</a>", tokens must be handled as follows:</p>
                   5997: 
                   5998:   <dl class="switch"><dt>An end tag whose tag name is one of: "td", "th"</dt>
                   5999:    <dd>
                   6000: 
                   6001:     <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
                   6002:     scope</a> with the same tag name as that of the token, then
                   6003:     this is a <a href="#parse-error">parse error</a> and the token must be
                   6004:     ignored.</p>
                   6005: 
                   6006:     <p>Otherwise:</p>
                   6007: 
                   6008:     <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
                   6009: 
                   6010:     <p>Now, if the <a href="#current-node">current node</a> is not an element
                   6011:     with the same tag name as the token, then this is a
                   6012:     <a href="#parse-error">parse error</a>.</p>
                   6013: 
                   6014:     <p>Pop elements from this stack until an element with the same
                   6015:     tag name as the token has been popped from the stack.</p>
                   6016: 
                   6017:     <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
                   6018:     the last marker</a>.</p>
                   6019: 
                   6020:     <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
                   6021:     <a href="#current-node">current node</a> will be a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element at
                   6022:     this point.)</p>
                   6023: 
                   6024:    </dd>
                   6025: 
                   6026:    <dt>A start tag whose tag name is one of: "caption", "col",
                   6027:    "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
                   6028:    <dd>
                   6029: 
                   6030:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does
                   6031:     <em>not</em> <a href="#has-an-element-in-table-scope" title="has an element in table scope">have
                   6032:     a <code>td</code> or <code>th</code> element in table
                   6033:     scope</a>, then this is a <a href="#parse-error">parse error</a>; ignore
                   6034:     the token. (<a href="#fragment-case">fragment case</a>)</p>
                   6035: 
                   6036:     <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
                   6037:     reprocess the current token.</p>
                   6038: 
                   6039:    </dd>
                   6040: 
                   6041:    <dt>An end tag whose tag name is one of: "body", "caption",
                   6042:    "col", "colgroup", "html"</dt>
                   6043:    <dd>
                   6044:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6045:    </dd>
                   6046: 
                   6047:    <dt>An end tag whose tag name is one of: "table", "tbody",
                   6048:    "tfoot", "thead", "tr"</dt>
                   6049:    <dd>
                   6050: 
                   6051:     <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
                   6052:     scope</a> with the same tag name as that of the token
                   6053:     (which can only happen for "tbody", "tfoot" and "thead", or,
                   6054:     in the <a href="#fragment-case">fragment case</a>), then this is a <a href="#parse-error">parse
                   6055:     error</a> and the token must be ignored.</p>
                   6056: 
                   6057:     <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
                   6058:     reprocess the current token.</p>
                   6059: 
                   6060:    </dd>
                   6061: 
                   6062:    <dt>Anything else</dt>
                   6063:    <dd>
                   6064:     <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
                   6065:     mode</a>.</p>
                   6066:    </dd>
                   6067: 
                   6068:   </dl><p>Where the steps above say to <dfn id="close-the-cell">close the cell</dfn>, they
                   6069:   mean to run the following algorithm:</p>
                   6070: 
                   6071:   <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>
                   6072:    element in table scope</a>, then act as if an end tag token
                   6073:    with the tag name "td" had been seen.</p></li>
                   6074: 
                   6075:    <li><p>Otherwise, the <a href="#stack-of-open-elements">stack of open elements</a> will
                   6076:    <a href="#has-an-element-in-table-scope" title="has an element in table scope">have a
                   6077:    <code>th</code> element in table scope</a>; act as if an end
                   6078:    tag token with the tag name "th" had been seen.</p></li>
                   6079: 
                   6080:   </ol><p class="note">The <a href="#stack-of-open-elements">stack of open elements</a> cannot
                   6081:   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
                   6082:   the same time, nor can it have neither when the <a href="#insertion-mode">insertion
                   6083:   mode</a> is "<a href="#parsing-main-intd" title="insertion mode: in cell">in
                   6084:   cell</a>".</p>
                   6085: 
                   6086: 
                   6087:   <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>
                   6088: 
                   6089:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselect" title="insertion
                   6090:   mode: in select">in select</a>", tokens must be handled as follows:</p>
                   6091: 
                   6092:   <dl class="switch"><dt>A character token</dt>
                   6093:    <dd>
                   6094:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   6095:     character</a> into the <a href="#current-node">current node</a>.</p>
                   6096:    </dd>
                   6097: 
                   6098:    <dt>A comment token</dt>
                   6099:    <dd>
                   6100:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6101:     node</a> with the <code title="">data</code> attribute set to
                   6102:     the data given in the comment token.</p>
                   6103:    </dd>
                   6104: 
                   6105:    <dt>A DOCTYPE token</dt>
                   6106:    <dd>
                   6107:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6108:    </dd>
                   6109: 
                   6110:    <dt>A start tag whose tag name is "html"</dt>
                   6111:    <dd>
                   6112:     <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
                   6113:     mode</a>.</p>
                   6114:    </dd>
                   6115: 
                   6116:    <dt>A start tag whose tag name is "option"</dt>
                   6117:    <dd>
                   6118: 
                   6119:     <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
                   6120:     element, act as if an end tag with the tag name "option" had
                   6121:     been seen.</p>
                   6122: 
                   6123:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   6124: 
                   6125:    </dd>
                   6126: 
                   6127:    <dt>A start tag whose tag name is "optgroup"</dt>
                   6128:    <dd>
                   6129: 
                   6130:     <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
                   6131:     element, act as if an end tag with the tag name "option" had
                   6132:     been seen.</p>
                   6133: 
                   6134:     <p>If the <a href="#current-node">current node</a> is an
                   6135:     <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, act as if an end tag with the
                   6136:     tag name "optgroup" had been seen.</p>
                   6137: 
                   6138:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   6139: 
                   6140:    </dd>
                   6141: 
                   6142:    <dt>An end tag whose tag name is "optgroup"</dt>
                   6143:    <dd>
                   6144: 
                   6145:     <p>First, if the <a href="#current-node">current node</a> is an
                   6146:     <code><a href="forms.html#the-option-element">option</a></code> element, and the node immediately before
                   6147:     it in the <a href="#stack-of-open-elements">stack of open elements</a> is an
                   6148:     <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then act as if an end tag with
                   6149:     the tag name "option" had been seen.</p>
                   6150: 
                   6151:     <p>If the <a href="#current-node">current node</a> is an
                   6152:     <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then pop that node from the
                   6153:     <a href="#stack-of-open-elements">stack of open elements</a>. Otherwise, this is a
                   6154:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   6155: 
                   6156:    </dd>
                   6157: 
                   6158:    <dt>An end tag whose tag name is "option"</dt>
                   6159:    <dd>
                   6160: 
                   6161:     <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
                   6162:     element, then pop that node from the <a href="#stack-of-open-elements">stack of open
                   6163:     elements</a>. Otherwise, this is a <a href="#parse-error">parse
                   6164:     error</a>; ignore the token.</p>
                   6165: 
                   6166:    </dd>
                   6167: 
                   6168:    <dt>An end tag whose tag name is "select"</dt>
                   6169:    <dd>
                   6170: 
                   6171:     <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
                   6172:     scope</a> with the same tag name as the token, this is a
                   6173:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   6174:     case</a>)</p>
                   6175: 
                   6176:     <p>Otherwise:</p>
                   6177: 
                   6178:     <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   6179:     until a <code><a href="forms.html#the-select-element">select</a></code> element has been popped from the
                   6180:     stack.</p>
                   6181: 
                   6182:     <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
                   6183: 
                   6184:    </dd>
                   6185: 
                   6186:    <dt>A start tag whose tag name is "select"</dt>
                   6187:    <dd>
                   6188: 
                   6189:     <p><a href="#parse-error">Parse error</a>. Act as if the token had been
                   6190:     an end tag with the tag name "select" instead.</p>
                   6191: 
                   6192:    </dd>
                   6193: 
                   6194:    <dt>A start tag whose tag name is one of: "input", "keygen", "textarea"</dt>
                   6195:    <dd>
1.73      mike     6196: 
                   6197:     <p><a href="#parse-error">Parse error</a>.</p>
                   6198: 
1.124     mike     6199:     <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>
                   6200:     element in table scope</a>, ignore the token. (<a href="#fragment-case">fragment
                   6201:     case</a>)</p>
1.73      mike     6202: 
                   6203:     <p>Otherwise, act as if an end tag with the tag name "select" had
                   6204:     been seen, and reprocess the token.</p>
                   6205: 
1.1       mike     6206:    </dd>
                   6207: 
                   6208:    <dt>A start tag token whose tag name is "script"</dt>
                   6209:    <dd>
                   6210:     <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
                   6211:     mode</a>.</p>
                   6212:    </dd>
                   6213: 
                   6214:    <dt>An end-of-file token</dt>
                   6215:    <dd>
                   6216: 
                   6217:     <p>If the <a href="#current-node">current node</a> is not the root
1.159     mike     6218:     <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     6219:     error</a>.</p>
                   6220: 
                   6221:     <p class="note">It can only be the <a href="#current-node">current node</a> in
                   6222:     the <a href="#fragment-case">fragment case</a>.</p>
                   6223: 
                   6224:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6225: 
                   6226:    </dd>
                   6227: 
                   6228:    <dt>Anything else</dt>
                   6229:    <dd>
                   6230:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6231:    </dd>
                   6232: 
                   6233:   </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>
                   6234: 
                   6235:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselectintable" title="insertion
                   6236:   mode: in select in table">in select in table</a>", tokens must be handled as follows:</p>
                   6237: 
                   6238:   <dl class="switch"><dt>A start tag whose tag name is one of: "caption", "table",
                   6239:    "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
                   6240:    <dd>
                   6241:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
                   6242:     name "select" had been seen, and reprocess the token.</p>
                   6243:    </dd>
                   6244: 
                   6245:    <dt>An end tag whose tag name is one of: "caption", "table",
                   6246:    "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
                   6247:    <dd>
                   6248: 
                   6249:     <p><a href="#parse-error">Parse error</a>.</p>
                   6250: 
                   6251:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-table-scope">has an
                   6252:     element in table scope</a> with the same tag name as that
                   6253:     of the token, then act as if an end tag with the tag name
                   6254:     "select" had been seen, and reprocess the token. Otherwise,
                   6255:     ignore the token.</p>
                   6256: 
                   6257:    </dd>
                   6258: 
                   6259:    <dt>Anything else</dt>
                   6260:    <dd>
                   6261:     <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
                   6262:     mode</a>.</p>
                   6263:    </dd>
                   6264: 
1.168     mike     6265:   </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     6266: 
                   6267:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inforeign" title="insertion
                   6268:   mode: in foreign content">in foreign content</a>", tokens must be
                   6269:   handled as follows:</p>
                   6270: 
                   6271:   <dl class="switch"><dt>A character token</dt>
                   6272:    <dd>
                   6273: 
                   6274:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   6275:     character</a> into the <a href="#current-node">current node</a>.</p>
                   6276: 
                   6277:     <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
                   6278:     LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
                   6279:     (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
                   6280:     flag</a> to "not ok".</p>
                   6281: 
                   6282:    </dd>
                   6283: 
                   6284:    <dt>A comment token</dt>
                   6285:    <dd>
                   6286:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6287:     node</a> with the <code title="">data</code> attribute set to
                   6288:     the data given in the comment token.</p>
                   6289:    </dd>
                   6290: 
                   6291:    <dt>A DOCTYPE token</dt>
                   6292:    <dd>
                   6293:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6294:    </dd>
                   6295: 
                   6296:    <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>
                   6297:    <dd>
                   6298: 
                   6299:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   6300:     elements</a>.</p>
                   6301: 
                   6302:     <p>Let the <var title="">old insertion point</var> have the
                   6303:     same value as the current <a href="#insertion-point">insertion point</a>. Let
                   6304:     the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
                   6305:     input character</a>.</p>
                   6306: 
                   6307:     <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
                   6308:     one. Set the <a href="#parser-pause-flag">parser pause flag</a> to true.</p>
                   6309: 
                   6310:     <p><a href="http://www.w3.org/TR/SVGMobile12/script.html#ScriptContentProcessing">Process
                   6311:     the <code title="">script</code> element</a> according to the SVG
1.187     mike     6312:     rules, if the user agent supports SVG. <a href="references.html#refsSVG">[SVG]</a></p>
1.1       mike     6313: 
1.159     mike     6314:     <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     6315:     tokenizer</a>, the parser will not be executed reentrantly,
                   6316:     since the <a href="#parser-pause-flag">parser pause flag</a> is true.</p>
                   6317: 
                   6318:     <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
                   6319:     one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
                   6320:     then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
                   6321: 
                   6322:     <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
                   6323:     <a href="#insertion-point">insertion point</a> to its previous value. This value
                   6324:     might be the "undefined" value.)</p>
                   6325: 
                   6326:    </dd>
                   6327: 
                   6328:    <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>
                   6329:    <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>
                   6330:    <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>
                   6331:    <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>
                   6332:    <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>
                   6333:    <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>
                   6334:    <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>
                   6335:    <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>
                   6336:    <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>
                   6337:    <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>
                   6338:    <dt>An end tag</dt>
                   6339:    <dd>
                   6340: 
                   6341:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the
                   6342:     <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
                   6343: 
                   6344:     <p>If, after doing so, the <a href="#insertion-mode">insertion mode</a> is still
                   6345:     "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
                   6346:     content</a>", but there is no element in scope that has a
                   6347:     namespace other than the <a href="#html-namespace-0">HTML namespace</a><!-- XXX this
                   6348:     isn't well-defined; it means check to see if the bottom-most HTML
                   6349:     element on the stack is in scope -->, switch the <a href="#insertion-mode">insertion
                   6350:     mode</a> to the <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
                   6351: 
                   6352:    </dd>
                   6353: 
                   6354:    <dt>A start tag whose tag name is one of: <!--"a",--> "b", "big",
                   6355:    "blockquote", "body"<!--by inspection-->, "br", "center", "code",
                   6356:    "dd", "div", "dl", "dt"<!-- so that dd and dt can be handled
                   6357:    uniformly throughout the parser -->, "em", "embed", "h1", "h2",
                   6358:    "h3", "h4"<!--for completeness-->, "h5", "h6"<!--for
                   6359:    completeness-->, "head"<!--by inspection-->, "hr", "i", "img",
                   6360:    "li", "listing"<!-- so that pre and listing can be handled
                   6361:    uniformly throughout the parser -->, "menu", "meta", "nobr",
                   6362:    "ol"<!-- so that dl, ul, and ol can be handled uniformly throughout
                   6363:    the parser -->, "p", "pre", "ruby", "s", <!--"script",--> "small",
                   6364:    "span", "strong", "strike"<!-- so that s and strike can be handled
                   6365:    uniformly throughout the parser -->, <!--"style",--> "sub", "sup",
                   6366:    "table"<!--by inspection-->, "tt", "u", "ul", "var"</dt>
                   6367:    <!-- this list was determined empirically by studying over
                   6368:    6,000,000,000 pages that were specifically not XML pages -->
                   6369:    <dt>A start tag whose tag name is "font", if the token has
                   6370:    any attributes named "color", "face", or "size"</dt>
                   6371:    <!-- the attributes here are required so that SVG <font> will go
                   6372:    through as SVG but legacy <font>s won't -->
                   6373:    <dt>An end-of-file token</dt>
                   6374:    <dd>
                   6375: 
                   6376:     <p><a href="#parse-error">Parse error</a>.</p>
                   6377: 
                   6378:     <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a> until
                   6379:     the <a href="#current-node">current node</a> is in the <a href="#html-namespace-0">HTML
                   6380:     namespace</a>.</p>
                   6381: 
                   6382:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#secondary-insertion-mode">secondary
                   6383:     insertion mode</a>, and reprocess the token.</p>
                   6384: 
                   6385:    </dd>
                   6386: 
                   6387:    <dt>Any other start tag</dt>
                   6388:    <dd>
                   6389: 
                   6390:     <p>If the <a href="#current-node">current node</a> is an element in the
                   6391:     <a href="#mathml-namespace">MathML namespace</a>, <a href="#adjust-mathml-attributes">adjust MathML
                   6392:     attributes</a> for the token. (This fixes the case of MathML
                   6393:     attributes that are not all lowercase.)</p>
                   6394: 
                   6395:     <p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
                   6396:     namespace</a>, and the token's tag name is one of the ones in
                   6397:     the first column of the following table, change the tag name to
                   6398:     the name given in the corresponding cell in the second
                   6399:     column. (This fixes the case of SVG elements that are not all
                   6400:     lowercase.)</p>
                   6401: 
                   6402:     <table><thead><tr><th> Tag name </th><th> Element name
                   6403:      </th></tr></thead><tbody><tr><td> <code title="">altglyph</code> </td><td> <code title="">altGlyph</code>
                   6404:       </td></tr><tr><td> <code title="">altglyphdef</code> </td><td> <code title="">altGlyphDef</code>
                   6405:       </td></tr><tr><td> <code title="">altglyphitem</code> </td><td> <code title="">altGlyphItem</code>
                   6406:       </td></tr><tr><td> <code title="">animatecolor</code> </td><td> <code title="">animateColor</code>
                   6407:       </td></tr><tr><td> <code title="">animatemotion</code> </td><td> <code title="">animateMotion</code>
                   6408:       </td></tr><tr><td> <code title="">animatetransform</code> </td><td> <code title="">animateTransform</code>
                   6409:       </td></tr><tr><td> <code title="">clippath</code> </td><td> <code title="">clipPath</code>
                   6410:       </td></tr><tr><td> <code title="">feblend</code> </td><td> <code title="">feBlend</code>
                   6411:       </td></tr><tr><td> <code title="">fecolormatrix</code> </td><td> <code title="">feColorMatrix</code>
                   6412:       </td></tr><tr><td> <code title="">fecomponenttransfer</code> </td><td> <code title="">feComponentTransfer</code>
                   6413:       </td></tr><tr><td> <code title="">fecomposite</code> </td><td> <code title="">feComposite</code>
                   6414:       </td></tr><tr><td> <code title="">feconvolvematrix</code> </td><td> <code title="">feConvolveMatrix</code>
                   6415:       </td></tr><tr><td> <code title="">fediffuselighting</code> </td><td> <code title="">feDiffuseLighting</code>
                   6416:       </td></tr><tr><td> <code title="">fedisplacementmap</code> </td><td> <code title="">feDisplacementMap</code>
                   6417:       </td></tr><tr><td> <code title="">fedistantlight</code> </td><td> <code title="">feDistantLight</code>
                   6418:       </td></tr><tr><td> <code title="">feflood</code> </td><td> <code title="">feFlood</code>
                   6419:       </td></tr><tr><td> <code title="">fefunca</code> </td><td> <code title="">feFuncA</code>
                   6420:       </td></tr><tr><td> <code title="">fefuncb</code> </td><td> <code title="">feFuncB</code>
                   6421:       </td></tr><tr><td> <code title="">fefuncg</code> </td><td> <code title="">feFuncG</code>
                   6422:       </td></tr><tr><td> <code title="">fefuncr</code> </td><td> <code title="">feFuncR</code>
                   6423:       </td></tr><tr><td> <code title="">fegaussianblur</code> </td><td> <code title="">feGaussianBlur</code>
                   6424:       </td></tr><tr><td> <code title="">feimage</code> </td><td> <code title="">feImage</code>
                   6425:       </td></tr><tr><td> <code title="">femerge</code> </td><td> <code title="">feMerge</code>
                   6426:       </td></tr><tr><td> <code title="">femergenode</code> </td><td> <code title="">feMergeNode</code>
                   6427:       </td></tr><tr><td> <code title="">femorphology</code> </td><td> <code title="">feMorphology</code>
                   6428:       </td></tr><tr><td> <code title="">feoffset</code> </td><td> <code title="">feOffset</code>
                   6429:       </td></tr><tr><td> <code title="">fepointlight</code> </td><td> <code title="">fePointLight</code>
                   6430:       </td></tr><tr><td> <code title="">fespecularlighting</code> </td><td> <code title="">feSpecularLighting</code>
                   6431:       </td></tr><tr><td> <code title="">fespotlight</code> </td><td> <code title="">feSpotLight</code>
                   6432:       </td></tr><tr><td> <code title="">fetile</code> </td><td> <code title="">feTile</code>
                   6433:       </td></tr><tr><td> <code title="">feturbulence</code> </td><td> <code title="">feTurbulence</code>
                   6434:       </td></tr><tr><td> <code title="">foreignobject</code> </td><td> <code title="">foreignObject</code>
                   6435:       </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
                   6436:       </td></tr><tr><td> <code title="">lineargradient</code> </td><td> <code title="">linearGradient</code>
                   6437:       </td></tr><tr><td> <code title="">radialgradient</code> </td><td> <code title="">radialGradient</code>
                   6438:       <!--<tr> <td> <code title="">solidcolor</code> <td> <code title="">solidColor</code> (SVG 1.2)-->
                   6439:       </td></tr><tr><td> <code title="">textpath</code> </td><td> <code title="">textPath</code>
                   6440:     </td></tr></tbody></table><p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
                   6441:     namespace</a>, <a href="#adjust-svg-attributes">adjust SVG attributes</a> for the
                   6442:     token. (This fixes the case of SVG attributes that are not all
                   6443:     lowercase.)</p>
                   6444: 
                   6445:     <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
                   6446:     fixes the use of namespaced attributes, in particular XLink in
                   6447:     SVG.)</p>
                   6448: 
                   6449:     <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
                   6450:     same namespace as the <a href="#current-node">current node</a>.</p>
                   6451: 
                   6452:     <p>If the token has its <i>self-closing flag</i> set, pop the
                   6453:     <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   6454:     elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
                   6455:     flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
                   6456: 
                   6457:    </dd>
                   6458: 
                   6459:   </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>
                   6460: 
                   6461:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterbody" title="insertion
                   6462:   mode: after body">after body</a>", tokens must be handled as follows:</p>
                   6463: 
                   6464:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   6465:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6466:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6467:    <dd>
                   6468:     <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
                   6469:     mode</a>.</p>
                   6470:    </dd>
                   6471: 
                   6472:    <dt>A comment token</dt>
                   6473:    <dd>
                   6474:     <p>Append a <code>Comment</code> node to the first element in
1.159     mike     6475:     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     6476:     element), with the <code title="">data</code> attribute set to
                   6477:     the data given in the comment token.</p>
                   6478:    </dd>
                   6479: 
                   6480:    <dt>A DOCTYPE token</dt>
                   6481:    <dd>
                   6482:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6483:    </dd>
                   6484: 
                   6485:    <dt>A start tag whose tag name is "html"</dt>
                   6486:    <dd>
                   6487:     <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
                   6488:     mode</a>.</p>
                   6489:    </dd>
                   6490: 
                   6491:    <dt>An end tag whose tag name is "html"</dt>
                   6492:    <dd>
                   6493: 
                   6494:     <p>If the parser was originally created as part of the <a href="#html-fragment-parsing-algorithm">HTML
                   6495:     fragment parsing algorithm</a>, this is a <a href="#parse-error">parse
                   6496:     error</a>; ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
                   6497: 
                   6498:     <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
                   6499:     body</a>".</p>
                   6500: 
                   6501:    </dd>
                   6502: 
                   6503:    <dt>An end-of-file token</dt>
                   6504:    <dd>
                   6505:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6506:    </dd>
                   6507: 
                   6508:    <dt>Anything else</dt>
                   6509:    <dd>
                   6510: 
                   6511:     <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion
                   6512:     mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   6513:     body</a>" and reprocess the token.</p>
                   6514: 
                   6515:    </dd>
                   6516: 
                   6517:   </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>
                   6518: 
                   6519:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inframeset" title="insertion
                   6520:   mode: in frameset">in frameset</a>", tokens must be handled as follows:</p>
                   6521: 
                   6522:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   6523:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6524:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6525:    <dd>
                   6526:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   6527:     the <a href="#current-node">current node</a>.</p>
                   6528:    </dd>
                   6529: 
                   6530:    <dt>A comment token</dt>
                   6531:    <dd>
                   6532:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6533:     node</a> with the <code title="">data</code> attribute set to
                   6534:     the data given in the comment token.</p>
                   6535:    </dd>
                   6536: 
                   6537:    <dt>A DOCTYPE token</dt>
                   6538:    <dd>
                   6539:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6540:    </dd>
                   6541: 
                   6542:    <dt>A start tag whose tag name is "html"</dt>
                   6543:    <dd>
                   6544:     <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
                   6545:     mode</a>.</p>
                   6546:    </dd>
                   6547: 
                   6548:    <dt>A start tag whose tag name is "frameset"</dt>
                   6549:    <dd>
                   6550:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   6551:    </dd>
                   6552: 
                   6553:    <dt>An end tag whose tag name is "frameset"</dt>
                   6554:    <dd>
                   6555: 
                   6556:     <p>If the <a href="#current-node">current node</a> is the root
1.159     mike     6557:     <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     6558:     error</a>; ignore the token. (<a href="#fragment-case">fragment
                   6559:     case</a>)</p>
                   6560: 
                   6561:     <p>Otherwise, pop the <a href="#current-node">current node</a> from the
                   6562:     <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   6563: 
                   6564:     <p>If the parser was <em>not</em> originally created as part
                   6565:     of the <a href="#html-fragment-parsing-algorithm">HTML fragment parsing algorithm</a>
                   6566:     (<a href="#fragment-case">fragment case</a>), and the <a href="#current-node">current
1.5       mike     6567:     node</a> is no longer a <code><a href="obsolete.html#frameset">frameset</a></code> element, then
1.1       mike     6568:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-afterframeset" title="insertion mode: after frameset">after
                   6569:     frameset</a>".</p>
                   6570: 
                   6571:    </dd>
                   6572: 
                   6573:    <dt>A start tag whose tag name is "frame"</dt>
                   6574:    <dd>
                   6575: 
                   6576:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.
                   6577:     Immediately pop the <a href="#current-node">current node</a> off the
                   6578:     <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   6579: 
                   6580:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   6581:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   6582: 
                   6583:    </dd>
                   6584: 
                   6585:    <dt>A start tag whose tag name is "noframes"</dt>
                   6586:    <dd>
                   6587:     <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
                   6588:     mode</a>.</p>
                   6589:    </dd>
                   6590: 
                   6591:    <dt>An end-of-file token</dt>
                   6592:    <dd>
                   6593: 
                   6594:     <p>If the <a href="#current-node">current node</a> is not the root
1.159     mike     6595:     <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     6596:     error</a>.</p>
                   6597: 
                   6598:     <p class="note">It can only be the <a href="#current-node">current node</a> in
                   6599:     the <a href="#fragment-case">fragment case</a>.</p>
                   6600: 
                   6601:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6602: 
                   6603:    </dd>
                   6604: 
                   6605:    <dt>Anything else</dt>
                   6606:    <dd>
                   6607:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6608:    </dd>
                   6609: 
                   6610:   </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>
                   6611: 
                   6612:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterframeset" title="insertion
                   6613:   mode: after frameset">after frameset</a>", tokens must be handled as follows:</p>
                   6614: 
                   6615:   <!-- due to rules in the "in frameset" mode, this can't be entered in the fragment case -->
                   6616:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   6617:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6618:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6619:    <dd>
                   6620:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   6621:     the <a href="#current-node">current node</a>.</p>
                   6622:    </dd>
                   6623: 
                   6624:    <dt>A comment token</dt>
                   6625:    <dd>
                   6626:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6627:     node</a> with the <code title="">data</code> attribute set to
                   6628:     the data given in the comment token.</p>
                   6629:    </dd>
                   6630: 
                   6631:    <dt>A DOCTYPE token</dt>
                   6632:    <dd>
                   6633:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6634:    </dd>
                   6635: 
                   6636:    <dt>A start tag whose tag name is "html"</dt>
                   6637:    <dd>
                   6638:     <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
                   6639:     mode</a>.</p>
                   6640:    </dd>
                   6641: 
                   6642:    <dt>An end tag whose tag name is "html"</dt>
                   6643:    <dd>
                   6644:     <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
                   6645:     frameset</a>".</p>
                   6646:    </dd>
                   6647: 
                   6648:    <dt>A start tag whose tag name is "noframes"</dt>
                   6649:    <dd>
                   6650:     <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
                   6651:     mode</a>.</p>
                   6652:    </dd>
                   6653: 
                   6654:    <dt>An end-of-file token</dt>
                   6655:    <dd>
                   6656:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6657:    </dd>
                   6658: 
                   6659:    <dt>Anything else</dt>
                   6660:    <dd>
                   6661:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6662:    </dd>
                   6663: 
                   6664:   </dl><p class="XXX">This doesn't handle UAs that don't support
                   6665:   frames, or that do support frames but want to show the NOFRAMES
                   6666:   content. Supporting the former is easy; supporting the latter is
                   6667:   harder.</p>
                   6668: 
                   6669: 
                   6670:   <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>
                   6671: 
                   6672:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-body-insertion-mode" title="insertion
                   6673:   mode: after after body">after after body</a>", tokens must be handled as follows:</p>
                   6674: 
                   6675:   <dl class="switch"><dt>A comment token</dt>
                   6676:    <dd>
                   6677:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   6678:     object with the <code title="">data</code> attribute set to the
                   6679:     data given in the comment token.</p>
                   6680:    </dd>
                   6681: 
                   6682:    <dt>A DOCTYPE token</dt>
                   6683:    <dt>A character token that is one of U+0009 CHARACTER
                   6684:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6685:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6686:    <dt>A start tag whose tag name is "html"</dt>
                   6687:    <dd>
                   6688:     <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
                   6689:     mode</a>.</p>
                   6690:    </dd>
                   6691: 
                   6692:    <dt>An end-of-file token</dt>
                   6693:    <dd>
                   6694:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6695:    </dd>
                   6696: 
                   6697:    <dt>Anything else</dt>
                   6698:    <dd>
                   6699:     <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion mode</a>
                   6700:     to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" and
                   6701:     reprocess the token.</p>
                   6702:    </dd>
                   6703: 
                   6704:   </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>
                   6705: 
                   6706:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-frameset-insertion-mode" title="insertion
                   6707:   mode: after after frameset">after after frameset</a>", tokens must be handled as follows:</p>
                   6708: 
                   6709:   <dl class="switch"><dt>A comment token</dt>
                   6710:    <dd>
                   6711:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   6712:     object with the <code title="">data</code> attribute set to the
                   6713:     data given in the comment token.</p>
                   6714:    </dd>
                   6715: 
                   6716:    <dt>A DOCTYPE token</dt>
                   6717:    <dt>A character token that is one of U+0009 CHARACTER
                   6718:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6719:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6720:    <dt>A start tag whose tag name is "html"</dt>
                   6721:    <dd>
                   6722:     <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
                   6723:     mode</a>.</p>
                   6724:    </dd>
                   6725: 
                   6726:    <dt>An end-of-file token</dt>
                   6727:    <dd>
                   6728:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6729:    </dd>
                   6730: 
                   6731:    <dt>A start tag whose tag name is "noframes"</dt>
                   6732:    <dd>
                   6733:     <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
                   6734:     mode</a>.</p>
                   6735:    </dd>
                   6736: 
                   6737:    <dt>Anything else</dt>
                   6738:    <dd>
                   6739:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6740:    </dd>
                   6741: 
                   6742:   </dl><h4 id="the-end"><span class="secno">9.2.6 </span>The end</h4>
                   6743: 
                   6744:   <p>Once the user agent <dfn id="stop-parsing" title="stop parsing">stops parsing</dfn>
                   6745:   the document, the user agent must follow the steps in this
                   6746:   section.</p>
                   6747: 
1.10      mike     6748:   <!-- this happens as part of one of the tasks that runs the parser -->
1.1       mike     6749: 
1.10      mike     6750:   <p>First, the user agent must set the <a href="dom.html#current-document-readiness">current document
                   6751:   readiness</a> to "interactive" and the <a href="#insertion-point">insertion
                   6752:   point</a> to undefined.</p>
                   6753: 
                   6754:   <p>Then, the user agent must then make a list of all the scripts
                   6755:   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
                   6756:   document has finished parsing</a>, the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts that
                   6757:   will execute asynchronously</a>, and the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts
                   6758:   that will execute as soon as possible</a>. This is the <dfn id="list-of-scripts-pending-after-the-parser-stopped">list
                   6759:   of scripts pending after the parser stopped</dfn>.</p>
                   6760: 
                   6761:   <p>The rules for <a href="semantics.html#when-a-script-completes-loading">when a script completes loading</a> start
                   6762:   applying (script execution is no longer managed by the parser).</p>
1.1       mike     6763: 
                   6764:   <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
                   6765:   execute as soon as possible</a> have <a href="semantics.html#completed-loading">completed
                   6766:   loading</a>, or if the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts that will execute
                   6767:   asynchronously</a> is not empty and the first script in that list
                   6768:   has <a href="semantics.html#completed-loading">completed loading</a>, then the user agent must act as
                   6769:   if those scripts just completed loading, following the rules given
                   6770:   for that in the <code><a href="semantics.html#script">script</a></code> element definition.</p>
                   6771: 
1.10      mike     6772:   <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
                   6773:   has finished parsing</a> is not empty, and the first item in this
                   6774:   list has already <a href="semantics.html#completed-loading">completed loading</a>, then the user agent
                   6775:   must act as if that script just finished loading.</p>
                   6776: 
                   6777:   <p class="note">By this point, there will be no scripts that have
                   6778:   loaded but have not yet been executed.</p>
                   6779: 
                   6780:   <hr><!-- async --><p>Once all the scripts on the <a href="#list-of-scripts-pending-after-the-parser-stopped">list of scripts pending after
                   6781:   the parser stopped</a> have <a href="semantics.html#completed-loading">completed loading</a> and
                   6782:   been <a href="semantics.html#executing-a-script-block" title="executing a script block">executed</a>, the
                   6783:   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
                   6784:   event</a> called <code title="event-DOMContentLoaded">DOMContentLoaded</code> at the
                   6785:   <code>Document</code>. (If the list is empty, this happens
                   6786:   immediately.)</p>
1.1       mike     6787: 
1.10      mike     6788:   <hr><!-- async --><p>Once everything that <dfn id="delay-the-load-event" title="delay the load event">delays the
1.1       mike     6789:   load event</dfn> of the document has completed, the user agent must
                   6790:   run the following steps:</p>
                   6791: 
                   6792:   <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
                   6793:    readiness</a> to "complete".</li>
                   6794: 
                   6795:    <li>If the <code>Document</code> is in a <a href="browsers.html#browsing-context">browsing
                   6796:    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
                   6797:    simple event</a> called <code title="event-load"><a href="video.html#event-load">load</a></code> at
                   6798:    the <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object, but with
                   6799:    its <code title="dom-event-target">target</code> set to the
                   6800:    <code>Document</code> object (and the <code title="dom-event-currentTarget">currentTarget</code> set to the
                   6801:    <code><a href="browsers.html#window">Window</a></code> object).</li>
                   6802: 
                   6803:    <li>If the <code>Document</code> has a <a href="history.html#pending-state-object">pending state
                   6804:    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
                   6805:    <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object using the
                   6806:    <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
                   6807:    current value of the <a href="history.html#pending-state-object">pending state object</a>. This event
                   6808:    must bubble but not be cancelable and has no default action.</li>
                   6809: 
                   6810:   </ol><p>The <a href="browsers.html#task-source">task source</a> for these tasks is the <a href="browsers.html#dom-manipulation-task-source">DOM
                   6811:   manipulation task source</a>.</p>
                   6812: 
                   6813:   <!-- XXX make sure things "delay the load event", e.g. applet and
                   6814:   object element's frame contents -->
                   6815: 
                   6816:   <p class="XXX">delaying the load event for things like image
                   6817:   loads allows for intranet port scans (even without
                   6818:   javascript!). Should we really encode that into the spec?</p>
                   6819: 
                   6820: 
                   6821: <!--XXX need to handle
                   6822: http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#2354
                   6823: 2354           // Don't open transient styles if it makes the stack deep, bug 58917.
                   6824: -->
                   6825: 
                   6826: <!--XXX
                   6827: http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/nsHTMLTokenizer.cpp#749
                   6828: -->
                   6829: 
                   6830: <!--
                   6831: see also  CTextToken::ConsumeCharacterData()  for CDATA parsing?
                   6832: 
                   6833: 1212                      1  Here's a tricky case from bug 22596:  <h5><li><h5>
                   6834: 1213                         How do we know that the 2nd <h5> should close the <LI> rather than nest inside the <LI>?
                   6835: 1214                         (Afterall, the <h5> is a legal child of the <LI>).
                   6836: 1215
                   6837: 1216                         The way you know is that there is no root between the two, so the <h5> binds more
                   6838: 1217                         tightly to the 1st <h5> than to the <LI>.
                   6839: 1218                      2. Also, bug 6148 shows this case: <SPAN><DIV><SPAN>
                   6840: 1219                         From this case we learned not to execute this logic if the parent is a block.
                   6841: 1220
                   6842: 1221                      3. Fix for 26583
                   6843: 1222                         Ex. <A href=foo.html><B>foo<A href-bar.html>bar</A></B></A>  <- A legal HTML
                   6844: 1223                         In the above example clicking on "foo" or "bar" should link to
                   6845: 1224                         foo.html or bar.html respectively. That is, the inner <A> should be informed
                   6846: 1225                         about the presence of an open <A> above <B>..so that the inner <A> can close out
                   6847: 1226                         the outer <A>. The following code does it for us.
                   6848: 1227
                   6849: 1228                      4. Fix for 27865 [ similer to 22596 ]. Ex: <DL><DD><LI>one<DD><LI>two
                   6850:  - http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#1211
                   6851: 
                   6852: 815             // Here's a problem.  If theTag is legal in here, we don't move it
                   6853: 816             // out.  So if we're moving stuff out of here, the parent of theTag
                   6854: 817             // gets closed at this point.  But some things are legal
                   6855: 818             // _everywhere_ and hence would effectively close out misplaced
                   6856: 819             // content in tables.  This is undesirable, so treat them as
                   6857: 820             // illegal here so they'll be shipped out with their parents and
                   6858: 821             // siblings.  See bug 40855 for an explanation (that bug was for
                   6859: 822             // comments, but the same issues arise with whitespace, newlines,
                   6860: 823             // noscript, etc).  Script is special, though.  Shipping it out
                   6861: 824             // breaks document.write stuff.  See bug 243064.
                   6862:  - http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#825
                   6863: 
                   6864: 
                   6865: 1326     /**************************************************************************************
                   6866: 1327      *
                   6867: 1328      * Now a little code to deal with bug #49687 (crash when layout stack gets too deep)
                   6868: 1329      * I've also opened this up to any container (not just inlines): re bug 55095
                   6869: 1330      * Improved to handle bug 55980 (infinite loop caused when DEPTH is exceeded and
                   6870: 1331      * </P> is encountered by itself (<P>) is continuously produced.
                   6871: 1332      *
                   6872: 1333      **************************************************************************************/
                   6873: 
                   6874: 1912               // Oh boy!! we found a "stray" tag. Nav4.x and IE introduce line break in
                   6875: 1913               // such cases. So, let's simulate that effect for compatibility.
                   6876: 1914               // Ex. <html><body>Hello</P>There</body></html>
                   6877: http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#1912
                   6878: 
                   6879: http://lxr.mozilla.org/seamonkey/search?string=nested
                   6880: /parser/htmlparser/src/CNavDTD.cpp, line 791 - * 2. <CENTER><DL><DT><A><CENTER> allow nested <CENTER>
                   6881: /parser/htmlparser/src/CNavDTD.cpp, line 792 - * 3. <TABLE><TR><TD><TABLE>... allow nested <TABLE>
                   6882: /parser/htmlparser/src/CNavDTD.cpp, line 2562 - // Discard nested forms - bug 72639
                   6883: /parser/htmlparser/src/nsElementTable.cpp, line 1453 - * 2. <CENTER><DL><DT><A><CENTER> allow nested <CENTER>
                   6884: /parser/htmlparser/src/nsElementTable.cpp, line 1454 - * 3. <TABLE><TR><TD><TABLE>... allow nested <TABLE>
                   6885: /parser/htmlparser/src/nsElementTable.cpp, line 1901 - // Ex: <H1><LI><H1><LI>. Inner LI has the potential of getting nested
                   6886: -->
                   6887: 
                   6888: 
                   6889:   <h4 id="coercing-an-html-dom-into-an-infoset"><span class="secno">9.2.7 </span>Coercing an HTML DOM into an infoset</h4>
                   6890: 
                   6891:   <p>When an application uses an <a href="#html-parser">HTML parser</a> in
                   6892:   conjunction with an XML pipeline, it is possible that the
                   6893:   constructed DOM is not compatible with the XML tool chain in certain
                   6894:   subtle ways. For example, an XML toolchain might not be able to
                   6895:   represent attributes with the name <code title="">xmlns</code>,
                   6896:   since they conflict with the Namespaces in XML syntax. There is also
                   6897:   some data that the <a href="#html-parser">HTML parser</a> generates that isn't
                   6898:   included in the DOM itself. This section specifies some rules for
                   6899:   handling these issues.</p>
                   6900: 
                   6901:   <p>If the XML API being used doesn't support DOCTYPEs, the tool may
                   6902:   drop DOCTYPEs altogether.</p>
                   6903: 
                   6904:   <p>If the XML API doesn't support attributes in no namespace that
                   6905:   are named "<code title="">xmlns</code>", attributes whose names
                   6906:   start with "<code title="">xmlns:</code>", or attributes in the
                   6907:   <a href="#xmlns-namespace">XMLNS namespace</a>, then the tool may drop such
                   6908:   attributes.</p>
                   6909: 
                   6910:   <p>The tool may annotate the output with any namespace declarations
                   6911:   required for proper operation.</p>
                   6912: 
                   6913:   <p>If the XML API being used restricts the allowable characters in
                   6914:   the local names of elements and attributes, then the tool may map
                   6915:   all element and attribute local names that the API wouldn't support
                   6916:   to a set of names that <em>are</em> allowed, by replacing any
                   6917:   character that isn't supported with the uppercase letter U and the
                   6918:   six digits of the character's Unicode code point when expressed in
                   6919:   hexadecimal, using digits 0-9 and capital letters A-F as the
                   6920:   symbols, in increasing numeric order.</p>
                   6921: 
                   6922:   <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
                   6923:   parser</a>, though it is neither a legal HTML element name nor a
                   6924:   well-formed XML element name, would be converted into <code title="">fooU00003Cbar</code>, which <em>is</em> a well-formed XML
                   6925:   element name (though it's still not legal in HTML by any means).</p>
                   6926: 
                   6927:   <p class="example">As another example, consider the attribute
                   6928:   <code>xlink:href</code>. Used on a MathML element, it becomes, after
                   6929:   being <a href="#adjust-foreign-attributes" title="adjust foreign attributes">adjusted</a>, an
                   6930:   attribute with a prefix "<code title="">xlink</code>" and a local
                   6931:   name "<code title="">href</code>". However, used on an HTML element,
                   6932:   it becomes an attribute with no prefix and the local name "<code title="">xlink:href</code>", which is not a valid NCName, and thus
                   6933:   might not be accepted by an XML API. It could thus get converted,
                   6934:   becoming "<code title="">xlinkU00003Ahref</code>".</p>
                   6935: 
                   6936:   <p class="note">The resulting names from this conversion
                   6937:   conveniently can't clash with any attribute generated by the
                   6938:   <a href="#html-parser">HTML parser</a>, since those are all either lowercase or
                   6939:   those listed in the <a href="#adjust-foreign-attributes">adjust foreign attributes</a>
                   6940:   algorithm's table.</p>
                   6941: 
                   6942:   <p>If the XML API restricts comments from having two consecutive
                   6943:   U+002D HYPHEN-MINUS characters (--), the tool may insert a single
                   6944:   U+0020 SPACE character between any such offending characters.</p>
                   6945: 
                   6946:   <p>If the XML API restricts comments from ending in a
                   6947:   U+002D HYPHEN-MINUS character (-), the tool may insert a single
                   6948:   U+0020 SPACE character at the end of such comments.</p>
                   6949: 
                   6950:   <p>If the XML API restricts allowed characters in character data,
                   6951:   the tool may replace any U+000C FORM FEED (FF) character with a
                   6952:   U+0020 SPACE character, and any other literal non-XML character with
                   6953:   a U+FFFD REPLACEMENT CHARACTER.</p>
                   6954: 
                   6955:   <p>If the tool has no way to convey out-of-band information, then
                   6956:   the tool may drop the following information:</p>
                   6957: 
                   6958:   <ul><li>Whether the document is set to <i><a href="dom.html#no-quirks-mode">no quirks mode</a></i>,
                   6959:    <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>
                   6960: 
                   6961:    <li>The association between form controls and forms that aren't
                   6962:    their nearest <code><a href="forms.html#the-form-element">form</a></code> element ancestor (use of the
                   6963:    <a href="#form-element-pointer"><code>form</code> element pointer</a> in the parser)</li>
                   6964: 
                   6965:   </ul><p class="note">The mutations allowed by this section apply
                   6966:   <em>after</em> the <a href="#html-parser">HTML parser</a>'s rules have been
                   6967:   applied. For example, a <code title="">&lt;a::&gt;</code> start tag
                   6968:   will be closed by a <code title="">&lt;/a::&gt;</code> end tag, and
                   6969:   never by a <code title="">&lt;/aU00003AU00003A&gt;</code> end tag, even
                   6970:   if the user agent is using the rules above to then generate an
                   6971:   actual element in the DOM with the name <code title="">aU00003AU00003A</code> for that start tag.</p>
                   6972: 
                   6973: 
                   6974: 
1.35      mike     6975:   <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     6976: 
                   6977:   <p><i>This section is non-normative.</i></p>
                   6978: 
                   6979:   <p>This section examines some erroneous markup and discusses how
                   6980:   the <a href="#html-parser">HTML parser</a> handles these cases.</p>
                   6981: 
                   6982: 
                   6983:   <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>
                   6984: 
                   6985:   <p><i>This section is non-normative.</i></p>
                   6986: 
                   6987:   <p>The most-often discussed example of erroneous markup is as
                   6988:   follows:</p>
                   6989: 
                   6990:   <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>
                   6991: 
                   6992:   <p>The parsing of this markup is straightforward up to the "3". At
                   6993:   this point, the DOM looks like this:</p>
                   6994: 
1.159     mike     6995:   <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
                   6996:   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     6997:   <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
                   6998:   formatting elements</a> just has two: <code><a href="text-level-semantics.html#the-b-element">b</a></code> and
                   6999:   <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>
                   7000: 
                   7001:   <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is
                   7002:   invoked. This is a simple case, in that the <var title="">formatting
                   7003:   element</var> is the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element, and there is no
                   7004:   <var title="">furthest block</var>. Thus, the <a href="#stack-of-open-elements">stack of open
1.159     mike     7005:   elements</a> ends up with just three elements: <code><a href="semantics.html#the-html-element-0">html</a></code>,
                   7006:   <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     7007:   active formatting elements</a> has just one: <code><a href="text-level-semantics.html#the-i-element">i</a></code>. The
                   7008:   DOM tree is unmodified at this point.</p>
                   7009: 
                   7010:   <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
                   7011:   the active formatting elements</a>, in this case just the
                   7012:   <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
                   7013:   for the "4" text node. After the end tag token for the "i" is also
                   7014:   received, and the "5" text node is inserted, the DOM looks as
                   7015:   follows:</p>
                   7016: 
1.159     mike     7017:   <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     7018: 
                   7019:   <p><i>This section is non-normative.</i></p>
                   7020: 
                   7021:   <p>A case similar to the previous one is the following:</p>
                   7022: 
                   7023:   <pre>&lt;b&gt;1&lt;p&gt;2&lt;/b&gt;3&lt;/p&gt;</pre>
                   7024: 
                   7025:   <p>Up to the "2" the parsing here is straightforward:</p>
                   7026: 
1.159     mike     7027:   <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     7028:   "b" is parsed.</p>
                   7029: 
                   7030:   <p>Before that token is seen, the <a href="#stack-of-open-elements">stack of open
1.159     mike     7031:   elements</a> has four elements on it: <code><a href="semantics.html#the-html-element-0">html</a></code>,
                   7032:   <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     7033:   <a href="#list-of-active-formatting-elements">list of active formatting elements</a> just has the one:
                   7034:   <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>
                   7035: 
                   7036:   <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is invoked, as
                   7037:   in the previous example. However, in this case, there <em>is</em> a
                   7038:   <var title="">furthest block</var>, namely the <code><a href="semantics.html#the-p-element">p</a></code> element. Thus,
                   7039:   this time the adoption agency algorithm isn't skipped over.</p>
                   7040: 
1.159     mike     7041:   <p>The <var title="">common ancestor</var> is the <code><a href="semantics.html#the-body-element-0">body</a></code>
1.1       mike     7042:   element. A conceptual "bookmark" marks the position of the
                   7043:   <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
                   7044:   elements</a>, but since that list has only one element in it,
                   7045:   it won't have much effect.</p>
                   7046: 
                   7047:   <p>As the algorithm progresses, <var title="">node</var> ends up set
                   7048:   to the formatting element (<code><a href="text-level-semantics.html#the-b-element">b</a></code>), and <var title="">last
                   7049:   node</var> ends up set to the <var title="">furthest block</var>
                   7050:   (<code><a href="semantics.html#the-p-element">p</a></code>).</p>
                   7051: 
                   7052:   <p>The <var title="">last node</var> gets appended (moved) to the
                   7053:   <var title="">common ancestor</var>, so that the DOM looks like:</p>
                   7054: 
1.159     mike     7055:   <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     7056:   <code><a href="semantics.html#the-p-element">p</a></code> element are moved to it:</p>
                   7057: 
1.159     mike     7058:   <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     7059:   <code><a href="semantics.html#the-p-element">p</a></code> element, so that the DOM looks like:</p>
                   7060: 
1.159     mike     7061:   <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     7062:   active formatting elements</a> and the <a href="#stack-of-open-elements">stack of open
                   7063:   elements</a>, so that when the "3" is parsed, it is appended to
                   7064:   the <code><a href="semantics.html#the-p-element">p</a></code> element:</p>
                   7065: 
1.159     mike     7066:   <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     7067: 
                   7068:   <p><i>This section is non-normative.</i></p>
                   7069: 
                   7070:   <p>Error handling in tables is, for historical reasons, especially
                   7071:   strange. For example, consider the following markup:</p>
                   7072: 
                   7073:   <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>
                   7074: 
                   7075:   <p>The highlighted <code><a href="text-level-semantics.html#the-b-element">b</a></code> element start tag is not allowed
                   7076:   directly inside a table like that, and the parser handles this case
                   7077:   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
                   7078:   examining the DOM tree as it stands just after the
                   7079:   <code><a href="tabular-data.html#the-table-element">table</a></code> element's start tag has been seen:</p>
                   7080: 
1.159     mike     7081:   <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     7082:   tag has been seen:</p>
                   7083: 
1.159     mike     7084:   <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
                   7085:   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     7086:   <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
                   7087:   resulting DOM tree); the <a href="#list-of-active-formatting-elements">list of active formatting
                   7088:   elements</a> just has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it; and the
                   7089:   <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion mode: in
                   7090:   table">in table</a>".</p>
                   7091: 
                   7092:   <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
                   7093:   to be popped off the stack and a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> start tag to be
                   7094:   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
                   7095:   then handled in a rather straight-forward manner, taking the parser
                   7096:   through the "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   7097:   body</a>" and "<a href="#parsing-main-intr" title="insertion mode: in row">in
                   7098:   row</a>" insertion modes, after which the DOM looks as
                   7099:   follows:</p>
                   7100: 
1.159     mike     7101:   <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
                   7102:   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     7103:   <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
                   7104:   formatting elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in
                   7105:   it; and the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
                   7106:   mode: in row">in row</a>".</p>
                   7107: 
                   7108:   <p>The <code><a href="tabular-data.html#the-td-element">td</a></code> element start tag token, after putting a
                   7109:   <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
                   7110:   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
                   7111:   mode</a>).</p>
                   7112: 
1.159     mike     7113:   <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     7114:   no <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created to hold the resulting text
                   7115:   node:</p>
                   7116: 
1.159     mike     7117:   <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     7118:   handling them, the <a href="#stack-of-open-elements">stack of open elements</a> has on it the
1.159     mike     7119:   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     7120:   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
                   7121:   elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it (the
                   7122:   marker having been removed by the "td" end tag token); and the
                   7123:   <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion mode: in
                   7124:   table body">in table body</a>".</p>
                   7125: 
                   7126:   <p>Thus it is that the "bbb" character tokens are found. These
                   7127:   trigger the "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table
                   7128:   text</a>" insertion mode to be used (with the <a href="#original-insertion-mode">original
                   7129:   insertion mode</a> set to "<a href="#parsing-main-intbody" title="insertion mode: in table
                   7130:   body">in table body</a>"). The character tokens are collected,
                   7131:   and when the next token (the <code><a href="tabular-data.html#the-table-element">table</a></code> element end tag) is
                   7132:   seen, they are processed as a group. Since they are not all spaces,
                   7133:   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,
                   7134:   which defer to the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   7135:   body</a>" insertion mode but with <a href="#foster-parent" title="foster
                   7136:   parent">foster parenting</a>.</p>
                   7137: 
                   7138:   <p>When <a href="#reconstruct-the-active-formatting-elements" title="reconstruct the active formatting elements">the
                   7139:   active formatting elements are reconstructed</a>, a
                   7140:   <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created and <a href="#foster-parent" title="foster
                   7141:   parent">foster parented</a>, and then the "bbb" text node is
                   7142:   appended to it:</p>
                   7143: 
1.159     mike     7144:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="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
                   7145:   <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     7146:   <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
                   7147:   this doesn't match the resulting tree!); the <a href="#list-of-active-formatting-elements">list of active
                   7148:   formatting elements</a> has the new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it;
                   7149:   and the <a href="#insertion-mode">insertion mode</a> is still "<a href="#parsing-main-intbody" title="insertion
                   7150:   mode: in table body">in table body</a>".</p>
                   7151: 
                   7152:   <p>Had the character tokens been only <a href="infrastructure.html#space-character" title="space
                   7153:   character">space characters</a> instead of "bbb", then those
                   7154:   <a href="infrastructure.html#space-character" title="space character">space characters</a> would just be
                   7155:   appended to the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element.</p>
                   7156: 
                   7157:   <p>Finally, the <code><a href="tabular-data.html#the-table-element">table</a></code> is closed by a "table" end
                   7158:   tag. This pops all the nodes from the <a href="#stack-of-open-elements">stack of open
                   7159:   elements</a> up to and including the <code><a href="tabular-data.html#the-table-element">table</a></code> element,
                   7160:   but it doesn't affect the <a href="#list-of-active-formatting-elements">list of active formatting
                   7161:   elements</a>, so the "ccc" character tokens after the table
                   7162:   result in yet another <code><a href="text-level-semantics.html#the-b-element">b</a></code> element being created, this
                   7163:   time after the table:</p>
                   7164: 
1.159     mike     7165:   <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     7166: 
                   7167:   <p><i>This section is non-normative.</i></p>
                   7168: 
                   7169:   <p>Consider the following markup, which for this example we will
                   7170:   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     7171:   content of an <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code> in another document with the
1.1       mike     7172:   <a href="infrastructure.html#url">URL</a> <code title="">http://example.com/outer</code>:</p>
                   7173: 
                   7174:   <pre>&lt;div id=a&gt;
                   7175:  &lt;script&gt;
                   7176:   var div = document.getElementById('a');
                   7177:   parent.document.body.appendChild(div);
                   7178:  &lt;/script&gt;
                   7179:  &lt;script&gt;
                   7180:   alert(document.URL);
                   7181:  &lt;/script&gt;
                   7182: &lt;/div&gt;
                   7183: &lt;script&gt;
                   7184:  alert(document.URL);
                   7185: &lt;/script&gt;</pre>
                   7186: 
                   7187:   <p>Up to the first "script" end tag, before the script is parsed,
                   7188:   the result is relatively straightforward:</p>
                   7189: 
1.159     mike     7190:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element-0">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element-0">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element-0">body</a></code><ul><li class="t1"><code><a href="interactive-elements.html#the-div-element">div</a></code> <span class="t2" title=""><code class="attribute name">id</code>="<code class="attribute value"><a href="text-level-semantics.html#the-a-element">a</a></code>"</span><ul><li class="t3"><code>#text</code>: <span title="">
1.1       mike     7191:  </span></li><li class="t1"><code><a href="semantics.html#script">script</a></code><ul><li class="t3"><code>#text</code>: <span title="">var div = document.getElementById('a'); &#9166; parent.document.body.appendChild(div);</span></li></ul></li></ul></li></ul></li></ul></li></ul><p>After the script is parsed, though, the <code><a href="interactive-elements.html#the-div-element">div</a></code> element
                   7192:   and its child <code><a href="semantics.html#script">script</a></code> element are gone:</p>
                   7193: 
1.159     mike     7194:   <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     7195:   aforementioned outer <a href="browsers.html#browsing-context">browsing context</a>. However, the
                   7196:   <a href="#stack-of-open-elements">stack of open elements</a> <em>still contains the
                   7197:   <code><a href="interactive-elements.html#the-div-element">div</a></code> element</em>.</p>
                   7198: 
                   7199:   <p>Thus, when the second <code><a href="semantics.html#script">script</a></code> element is parsed, it
                   7200:   is inserted <em>into the outer <code>Document</code>
                   7201:   object</em>.</p>
                   7202: 
                   7203:   <p>This also means that the <a href="browsers.html#script-s-global-object">script's global object</a> is
                   7204:   the outer <a href="browsers.html#browsing-context">browsing context</a>'s <code><a href="browsers.html#window">Window</a></code>
                   7205:   object, <em>not</em> the <code><a href="browsers.html#window">Window</a></code> object inside the
1.159     mike     7206:   <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>.</p>
1.1       mike     7207: 
                   7208:   <p class="note">This isn't a security problem since the script that
                   7209:   moves the <code><a href="interactive-elements.html#the-div-element">div</a></code> into the outer <code>Document</code> can
                   7210:   only do so because they have the two <code>Document</code> object
1.159     mike     7211:   have the same <a href="browsers.html#origin">origin</a>.</p>
1.1       mike     7212: 
                   7213:   <p>Thus, the first alert says "http://example.com/outer".</p>
                   7214: 
                   7215:   <p>Once the <code><a href="interactive-elements.html#the-div-element">div</a></code> element's end tag is parsed, the
                   7216:   <code><a href="interactive-elements.html#the-div-element">div</a></code> element is popped off the stack, and so the next
                   7217:   <code><a href="semantics.html#script">script</a></code> element is in the inner <code>Document</code>:</p>
                   7218: 
1.159     mike     7219:   <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     7220: 
                   7221: 
                   7222: 
1.159     mike     7223:   <h3 id="namespaces"><span class="secno">9.3 </span>Namespaces</h3><p class="XXX annotation"><span><a href="http://www.w3.org/html/wg/tracker/issues/60">ISSUE-60</a> (html5-xhtml-namespace) blocks progress to Last Call</span></p>
1.1       mike     7224: 
                   7225:   <p>The <dfn id="html-namespace-0">HTML namespace</dfn> is: <code>http://www.w3.org/1999/xhtml</code></p>
                   7226: 
                   7227:   <p>The <dfn id="mathml-namespace">MathML namespace</dfn> is: <code>http://www.w3.org/1998/Math/MathML</code></p>
                   7228: 
                   7229:   <p>The <dfn id="svg-namespace">SVG namespace</dfn> is: <code>http://www.w3.org/2000/svg</code></p>
                   7230: 
                   7231:   <p>The <dfn id="xlink-namespace">XLink namespace</dfn> is: <code>http://www.w3.org/1999/xlink</code></p>
                   7232: 
                   7233:   <p>The <dfn id="xml-namespace">XML namespace</dfn> is: <code>http://www.w3.org/XML/1998/namespace</code></p>
                   7234: 
                   7235:   <p>The <dfn id="xmlns-namespace">XMLNS namespace</dfn> is: <code>http://www.w3.org/2000/xmlns/</code></p>
                   7236: 
                   7237:   <hr><p>Data mining tools and other user agents that perform operations
1.83      mike     7238:   on <code><a href="iana-considerations.html#text-html">text/html</a></code> content without running scripts,
1.1       mike     7239:   evaluating CSS or XPath expressions, or otherwise exposing the
                   7240:   resulting DOM to arbitrary content, may "support namespaces" by just
                   7241:   asserting that their DOM node analogues are in certain namespaces,
                   7242:   without actually exposing the above strings.</p>
                   7243: 
                   7244: 
                   7245: 
                   7246: 
                   7247:   <h3 id="serializing-html-fragments"><span class="secno">9.4 </span>Serializing HTML fragments</h3>
                   7248: 
                   7249:   <p>The following steps form the <dfn id="html-fragment-serialization-algorithm">HTML fragment serialization
                   7250:   algorithm</dfn>. The algorithm takes as input a DOM
                   7251:   <code>Element</code> or <code>Document</code>, referred to as <var title="">the node</var>, and either returns a string or raises an
                   7252:   exception.</p>
                   7253: 
                   7254:   <p class="note">This algorithm serializes the <em>children</em> of
                   7255:   the node being serialized, not the node itself.</p>
                   7256: 
                   7257:   <ol><li><p>Let <var title="">s</var> be a string, and initialize it to
                   7258:    the empty string.</p></li>
                   7259: 
                   7260:    <li>
                   7261: 
                   7262:     <p>For each child node of <var title="">the node</var>, in
                   7263:     <a href="infrastructure.html#tree-order">tree order</a>, run the following steps:
                   7264: 
                   7265:     </p><ol><li><p>Let <var title="">current node</var> be the child node
                   7266:      being processed.</p></li>
                   7267: 
                   7268:      <li>
                   7269: 
                   7270:       <p>Append the appropriate string from the following list to
                   7271:       <var title="">s</var>:</p>
                   7272: 
                   7273:       <dl class="switch"><dt>If <var title="">current node</var> is an <code title="">Element</code></dt>
                   7274: 
                   7275:        <dd>
                   7276: 
                   7277:         <p>Append a U+003C LESS-THAN SIGN (<code title="">&lt;</code>)
                   7278:         character, followed by the element's tag name. (For nodes
                   7279:         created by the <a href="#html-parser">HTML parser</a> or <code title="">Document.createElement()</code>, the tag name will be
                   7280:         lowercase.)</p>
                   7281: 
                   7282:         <p>For each attribute that the element has, append a U+0020
                   7283:         SPACE character, the attribute's name (which, for attributes
                   7284:         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
                   7285:         U+003D EQUALS SIGN (<code title="">=</code>) character, a
                   7286:         U+0022 QUOTATION MARK (<code title="">"</code>)
                   7287:         character, the attribute's value, <a href="#escapingString" title="escaping a
                   7288:         string">escaped as described below</a> in <i>attribute
                   7289:         mode</i>, and a second U+0022 QUOTATION MARK (<code title="">"</code>) character.</p>
                   7290: 
                   7291:         <p>While the exact order of attributes is UA-defined, and may
                   7292:         depend on factors such as the order that the attributes were
                   7293:         given in the original markup, the sort order must be stable,
                   7294:         such that consecutive invocations of this algorithm serialize an
                   7295:         element's attributes in the same order.</p>
                   7296: 
                   7297:         <p>Append a U+003E GREATER-THAN SIGN (<code title="">&gt;</code>)
                   7298:         character.</p>
                   7299: 
                   7300:         <p>If <var title="">current node</var> is an
1.5       mike     7301:         <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     7302:         <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     7303:         <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>,
                   7304:         <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>,
                   7305:         <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     7306:         <code><a href="obsolete.html#spacer">spacer</a></code>, or <code>wbr</code> element, then
1.1       mike     7307:         continue on to the next child node at this point.</p> <!--
                   7308:         also, i guess: image and isindex, but we don't list those
                   7309:         because we don't consider those "elements", more "macros", and
                   7310:         thus we should never serialize them -->
                   7311: 
                   7312:         <p>If <var title="">current node</var> is a <code><a href="semantics.html#the-pre-element">pre</a></code>,
1.42      mike     7313:         <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     7314:         a U+000A LINE FEED (LF) character.</p>
                   7315: 
                   7316:         <p>Append the value of running the <a href="#html-fragment-serialization-algorithm">HTML fragment
                   7317:         serialization algorithm</a> on the <var title="">current
                   7318:         node</var> element (thus recursing into this algorithm for
                   7319:         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,
                   7320:         and finally a U+003E GREATER-THAN SIGN (<code title="">&gt;</code>) character.</p>
                   7321: 
                   7322:        </dd>
                   7323: 
                   7324: 
                   7325:        <dt>If <var title="">current node</var> is a <code title="">Text</code> or <code title="">CDATASection</code>
                   7326:        node</dt>
                   7327: 
                   7328:        <dd>
                   7329: 
1.19      mike     7330:         <p>If the parent of <var title="">current node</var> is a
1.42      mike     7331:         <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     7332:         <code><a href="text-level-semantics.html#the-iframe-element">iframe</a></code>, <code><a href="obsolete.html#noembed">noembed</a></code>,
1.5       mike     7333:         <code><a href="obsolete.html#noframes">noframes</a></code>, <code><a href="semantics.html#the-noscript-element">noscript</a></code>, or
1.192     mike     7334:         <code><a href="obsolete.html#plaintext">plaintext</a></code> element, then append the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1       mike     7335:         attribute literally.</p> <!-- note about noscript: we're
                   7336:         assuming here that scripting is enabled. If this algorithm is
1.19      mike     7337:         used with scripting disabled, this won't work
                   7338:         right. (e.g. This might affect calling innerHTML on nodes in a
                   7339:         document that is being designMode'd) -->
1.1       mike     7340: 
                   7341:         <p>Otherwise, append the value of <var title="">current
1.192     mike     7342:         node</var>'s <code title="">data</code> IDL attribute, <a href="#escapingString" title="escaping a string">escaped as described
1.1       mike     7343:         below</a>.</p>
                   7344: 
                   7345:        </dd>
                   7346: 
                   7347: 
                   7348:        <dt>If <var title="">current node</var> is a <code title="">Comment</code></dt>
                   7349: 
                   7350:        <dd>
                   7351: 
                   7352:         <p>Append the literal string <code>&lt;!--</code> (U+003C
                   7353:         LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS,
1.192     mike     7354:         U+002D HYPHEN-MINUS), followed by the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1       mike     7355:         attribute, followed by the literal string <code>--&gt;</code>
                   7356:         (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN
                   7357:         SIGN).</p>
                   7358: 
                   7359:        </dd>
                   7360: 
                   7361: 
                   7362:        <dt>If <var title="">current node</var> is a <code title="">ProcessingInstruction</code></dt>
                   7363: 
                   7364:        <dd>
                   7365: 
                   7366:         <p>Append the literal string <code>&lt;?</code> (U+003C
                   7367:         LESS-THAN SIGN, U+003F QUESTION MARK), followed by the value
1.192     mike     7368:         of <var title="">current node</var>'s <code title="">target</code> IDL attribute, followed by a single
                   7369:         U+0020 SPACE character, followed by the value of <var title="">current node</var>'s <code title="">data</code> IDL
1.1       mike     7370:         attribute, followed by a single U+003E GREATER-THAN SIGN
                   7371:         character ('&gt;').</p>
                   7372: 
                   7373:        </dd>
                   7374: 
                   7375: 
                   7376:        <dt>If <var title="">current node</var> is a <code title="">DocumentType</code></dt>
                   7377: 
                   7378:        <dd>
                   7379: 
                   7380:         <p>Append the literal string <code>&lt;!DOCTYPE</code> (U+003C
                   7381:         LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+0044 LATIN CAPITAL
                   7382:         LETTER D, U+004F LATIN CAPITAL LETTER O, U+0043 LATIN CAPITAL
                   7383:         LETTER C, U+0054 LATIN CAPITAL LETTER T, U+0059 LATIN CAPITAL
                   7384:         LETTER Y, U+0050 LATIN CAPITAL LETTER P, U+0045 LATIN CAPITAL
                   7385:         LETTER E), followed by a space (U+0020 SPACE), followed by the
1.192     mike     7386:         value of <var title="">current node</var>'s <code title="">name</code> IDL attribute, followed by the literal
1.1       mike     7387:         string <code>&gt;</code> (U+003E GREATER-THAN SIGN).</p>
                   7388: 
                   7389:        </dd>
                   7390: 
                   7391: 
                   7392:       </dl><p>Other node types (e.g. <code title="">Attr</code>) cannot
                   7393:       occur as children of elements. If, despite this, they somehow do
                   7394:       occur, this algorithm must raise an
                   7395:       <code><a href="infrastructure.html#invalid_state_err">INVALID_STATE_ERR</a></code> exception.</p>
                   7396: 
                   7397:      </li>
                   7398: 
                   7399:     </ol></li>
                   7400: 
                   7401:    <li><p>The result of the algorithm is the string <var title="">s</var>.</p></li>
                   7402: 
                   7403:   </ol><p><dfn id="escapingString">Escaping a string</dfn> (for the
                   7404:   purposes of the algorithm above) consists of replacing any
                   7405:   occurrences of the "<code title="">&amp;</code>" character by the
                   7406:   string "<code title="">&amp;amp;</code>", any occurrences of the
                   7407:   U+00A0 NO-BREAK SPACE character by the string "<code title="">&amp;nbsp;</code>", and, if the algorithm was invoked in
                   7408:   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
                   7409:   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>
                   7410: 
                   7411:   <p class="note">Entity reference nodes are <a href="infrastructure.html#entity-references">assumed to be expanded</a> by the user
                   7412:   agent, and are therefore not covered in the algorithm above.</p>
                   7413: 
                   7414:   <p class="note">It is possible that the output of this algorithm, if
                   7415:   parsed with an <a href="#html-parser">HTML parser</a>, will not return the
                   7416:   original tree structure. For instance, if a <code><a href="forms.html#the-textarea-element">textarea</a></code>
                   7417:   element to which a <code title="">Comment</code> node has been
                   7418:   appended is serialized and the output is then reparsed, the comment
                   7419:   will end up being displayed in the text field. Similarly, if, as a
                   7420:   result of DOM manipulation, an element contains a comment that
                   7421:   contains the literal string "<code title="">--&gt;</code>", then
                   7422:   when the result of serializing the element is parsed, the comment
                   7423:   will be truncated at that point and the rest of the comment will be
                   7424:   interpreted as markup. More examples would be making a
                   7425:   <code><a href="semantics.html#script">script</a></code> element contain a text node with the text string
                   7426:   "<code>&lt;/script&gt;</code>", or having a <code><a href="semantics.html#the-p-element">p</a></code> element that
                   7427:   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
                   7428:   <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> would imply the end
                   7429:   tag for the <code><a href="semantics.html#the-p-element">p</a></code>).</p>
                   7430: 
                   7431: 
                   7432:   <h3 id="parsing-html-fragments"><span class="secno">9.5 </span>Parsing HTML fragments</h3>
                   7433: 
                   7434:   <p>The following steps form the <dfn id="html-fragment-parsing-algorithm">HTML fragment parsing
                   7435:   algorithm</dfn>. The algorithm optionally takes as input an
                   7436:   <code>Element</code> node, referred to as the <var title="">context</var> element, which gives the context for the
                   7437:   parser, as well as <var title="">input</var>, a string to parse, and
                   7438:   returns a list of zero or more nodes.</p>
                   7439: 
                   7440:   <p class="note">Parts marked <dfn id="fragment-case">fragment case</dfn> in algorithms
                   7441:   in the parser section are parts that only occur if the parser was
                   7442:   created for the purposes of this algorithm (and with a <var title="">context</var> element). The algorithms have been annotated
                   7443:   with such markings for informational purposes only; such markings
                   7444:   have no normative weight. If it is possible for a condition
                   7445:   described as a <a href="#fragment-case">fragment case</a> to occur even when the
                   7446:   parser wasn't created for the purposes of handling this algorithm,
                   7447:   then that is an error in the specification.</p>
                   7448: 
                   7449:   <ol><li>
                   7450: 
                   7451:     <p>Create a new <code>Document</code> node, and mark it as being
                   7452:     an <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
                   7453: 
                   7454:    </li>
                   7455: 
                   7456:    <li>
                   7457: 
                   7458:     <p>If there is a <var title="">context</var> element, and the
                   7459:     <code>Document</code> of the <var title="">context</var> element
                   7460:     is in <a href="dom.html#quirks-mode">quirks mode</a>, then let the <code>Document</code>
                   7461:     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
                   7462:     the <var title="">context</var> element is in <a href="dom.html#limited-quirks-mode">limited quirks
                   7463:     mode</a>, then let the <code>Document</code> be in
                   7464:     <a href="dom.html#limited-quirks-mode">limited quirks mode</a>. Otherwise, leave the
                   7465:     <code>Document</code> in <a href="dom.html#no-quirks-mode">no quirks mode</a>.</p>
                   7466: 
                   7467:    </li>
                   7468: 
                   7469:    <li>
                   7470: 
                   7471:     <p>Create a new <a href="#html-parser">HTML parser</a>, and associate it with
                   7472:     the just created <code>Document</code> node.</p>
                   7473: 
                   7474:    </li>
                   7475: 
                   7476:    <li>
                   7477: 
                   7478:     <p>If there is a <var title="">context</var> element, run these
                   7479:     substeps:</p>
                   7480: 
                   7481:     <ol><li>
                   7482: 
                   7483:       <p>Set the <a href="#html-parser">HTML parser</a>'s <a href="#tokenization">tokenization</a>
                   7484:       stage's <a href="#content-model-flag">content model flag</a> according to the <var title="">context</var> element, as follows:</p>
                   7485: 
1.159     mike     7486:       <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     7487:        element</dt>
                   7488: 
                   7489:        <dd>Set the <a href="#content-model-flag">content model flag</a> to
                   7490:        the RCDATA state.</dd>
                   7491: 
                   7492: 
                   7493:        <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     7494:        <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     7495:        <code><a href="obsolete.html#noframes">noframes</a></code> element</dt>
1.1       mike     7496: 
                   7497:        <dd>Set the <a href="#content-model-flag">content model flag</a> to
1.91      mike     7498:        the RAWTEXT state.</dd>
1.1       mike     7499: 
                   7500: 
                   7501:        <dt>If it is a <code><a href="semantics.html#the-noscript-element">noscript</a></code> element</dt>
                   7502: 
                   7503:        <dd>If the <a href="#scripting-flag">scripting flag</a> is enabled, set the
1.91      mike     7504:        <a href="#content-model-flag">content model flag</a> to the RAWTEXT
1.1       mike     7505:        state. Otherwise, set the <a href="#content-model-flag">content model flag</a> to the
                   7506:        PCDATA state.</dd>
                   7507: 
                   7508: 
1.42      mike     7509:        <dt>If it is a <code><a href="obsolete.html#plaintext">plaintext</a></code> element</dt>
1.1       mike     7510: 
                   7511:        <dd>Set the <a href="#content-model-flag">content model flag</a> to
                   7512:        PLAINTEXT.</dd>
                   7513: 
                   7514: 
                   7515:        <dt>Otherwise</dt>
                   7516: 
                   7517:        <dd>Leave the <a href="#content-model-flag">content model flag</a> in the PCDATA
                   7518:        state.</dd>
                   7519: 
                   7520:       </dl></li>
                   7521: 
                   7522:      <li>
                   7523: 
1.159     mike     7524:       <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     7525:       with no attributes.</p>
                   7526: 
                   7527:      </li>
                   7528: 
                   7529:      <li>
                   7530: 
                   7531:       <p>Append the element <var title="">root</var> to the
                   7532:       <code>Document</code> node created above.</p>
                   7533: 
                   7534:      </li>
                   7535: 
                   7536:      <li>
                   7537: 
                   7538:       <p>Set up the parser's <a href="#stack-of-open-elements">stack of open elements</a> so that
                   7539:       it contains just the single element <var title="">root</var>.</p>
                   7540: 
                   7541:      </li>
                   7542: 
                   7543:      <li>
                   7544: 
                   7545:       <p><a href="#reset-the-insertion-mode-appropriately" title="reset the insertion mode appropriately">Reset the
                   7546:       parser's insertion mode appropriately</a>.</p>
                   7547: 
                   7548:       <p class="note">The parser will reference the <var title="">context</var> element as part of that algorithm.</p>
                   7549: 
                   7550:      </li>
                   7551: 
                   7552:      <li>
                   7553: 
                   7554:       <p>Set the parser's <a href="#form-element-pointer"><code>form</code> element pointer</a>
                   7555:       to the nearest node to the <var title="">context</var> element
                   7556:       that is a <code><a href="forms.html#the-form-element">form</a></code> element (going straight up the
                   7557:       ancestor chain, and including the element itself, if it is a
                   7558:       <code><a href="forms.html#the-form-element">form</a></code> element), or, if there is no such
                   7559:       <code><a href="forms.html#the-form-element">form</a></code> element, to null.</p>
                   7560: 
                   7561:      </li>
                   7562: 
                   7563:     </ol></li>
                   7564: 
                   7565:    <li>
                   7566: 
                   7567:     <p>Place into the <a href="#the-input-stream">input stream</a> for the <a href="#html-parser">HTML
                   7568:     parser</a> just created the <var title="">input</var>. The
                   7569:     encoding <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   7570:     <i>irrelevant</i>.</p>
                   7571: 
                   7572:    </li>
                   7573: 
                   7574:    <li>
                   7575: 
                   7576:     <p>Start the parser and let it run until it has consumed all the
                   7577:     characters just inserted into the input stream.</p>
                   7578: 
                   7579:    </li>
                   7580: 
                   7581:    <li>
                   7582: 
                   7583:     <p>If there is a <var title="">context</var> element, return the
                   7584:     child nodes of <var title="">root</var>, in <a href="infrastructure.html#tree-order">tree
                   7585:     order</a>.</p>
                   7586: 
                   7587:     <p>Otherwise, return the children of the <code>Document</code>
                   7588:     object, in <a href="infrastructure.html#tree-order">tree order</a>.</p>
                   7589: 
                   7590:    </li>
                   7591: 
1.123     mike     7592:   </ol></div></body></html>

Webmaster