Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. <!DOCTYPE HTML>
  2.  
  3.  
  4. <html lang="en-GB-hixie">
  5.  <head>
  6.   <title>HTML 5</title>
  7.   <link href="/style/specification" type="text/css" rel="stylesheet">
  8.   <link href="/images/icon" rel="icon">
  9.  
  10.   <style type="text/css">
  11.    h4 + .element { margin-top: -2.5em; padding-top: 2em; }
  12.    h4 + p + .element { margin-top: -5em; padding-top: 4em; }
  13.    .element { background: #EEFFEE; color: black; margin: 0 0 1em -1em; padding: 0 1em 0.25em 0.75em; border-left: solid #99FF99 0.25em; -padding: 0; /* that last decl is for IE6. Try removing it, it's hilarious! */ }
  14.   .proposal { border: blue solid; padding: 1em; }
  15.   table.matrix, table.matrix td { border: none; text-align: right; }
  16.   table.matrix { margin-left: 2em; }
  17.  </style>
  18.  
  19. <link href="section-tokenisation.html#nav-bar" rel="prev" title="8.2.3. Tokenisation"><link href="index.html#contents" rel="index" title="Table of contents"><link href="section-namespaces.html#nav-bar" rel="next" title="8.3. Namespaces"></head><body class="draft"><div class="head">
  20.   <p><a href="http://www.whatwg.org/" class="logo" rel="home"><img src="/images/logo" alt="WHATWG"></a></p>
  21.  
  22.   <h1 id="html-5">HTML 5</h1>
  23.  
  24.   <h2 id="working" class="no-num no-toc">Working Draft — 12 June 2007</h2></div><nav id="nav-bar"><a href="section-tokenisation.html#nav-bar">&lt; 8.2.3. Tokenisation</a> – <a href="index.html#contents">Table of contents</a> – <a href="section-namespaces.html#nav-bar">8.3. Namespaces &gt;</a></nav><h4 id="tree-construction"><span class="secno">8.2.4. </span><dfn id="tree-construction0">Tree construction</dfn></h4>
  25.  
  26.  <p>The input to the tree construction stage is a sequence of tokens from
  27.   the <a href="section-tokenisation.html#tokenisation0">tokenisation</a> stage. The tree construction
  28.   stage is associated with a DOM <code>Document</code> object when a parser
  29.   is created. The &quot;output&quot; of this stage consists of dynamically modifying
  30.   or extending that document's DOM tree.
  31.  
  32.   </p><p>Tree construction passes through several phases. Initially, UAs must act
  33.    according to the steps described as being those of <a href="#the-initial0">the initial phase</a>.
  34.  
  35.   </p><p>This specification does not define when an interactive user agent has to
  36.    render the <code>Document</code> available to the user, or when it has to
  37.    begin accepting user input.
  38.  
  39.   </p><p>When the steps below require the UA to <dfn id="append">append a
  40.    character</dfn> to a node, the UA must collect it and all subsequent
  41.    consecutive characters that would be appended to that node, and insert one
  42.    <code>Text</code> node whose data is the concatenation of all those
  43.    characters.
  44.  
  45.   </p><p id="mutation-during-parsing">DOM mutation events must not fire for changes
  46.    caused by the UA parsing the document. (Conceptually, the parser is not
  47.    mutating the DOM, it is constructing it.) This includes the parsing of any
  48.    content inserted using <code title="dom-document-write-HTML"><a href="section-dynamic.html#document.write0">document.write()</a></code> and <code title="dom-document-writeln"><a href="section-dynamic.html#document.writeln">document.writeln()</a></code> calls.<!--
  49.   XXX xref -->
  50.    <a href="#refsDOM3EVENTS">[DOM3EVENTS]</a></p>
  51.   <!-- XXX
  52.   what abotu innerHTML? -->
  53.  
  54.   <p class="note">Not all of the tag names mentioned below are conformant tag
  55.    names in this specification; many are included to handle legacy content.
  56.    They still form part of the algorithm that implementations are required to
  57.    implement to claim conformance.
  58.  
  59.   </p><p class="note">The algorithm described below places no limit on the depth of
  60.    the DOM tree generated, or on the length of tag names, attribute names,
  61.    attribute values, text nodes, etc. While implementators are encouraged to
  62.    avoid arbitrary limits, it is recognised that <a href="section-conformance.html#hardwareLimitations">practical concerns</a> will likely force user
  63.    agents to impose nesting depths.
  64.  
  65.   </p><h5 id="the-initial"><span class="secno">8.2.4.1. </span><dfn id="the-initial0">The initial phase</dfn></h5>
  66.  
  67.   <p>Initially, the tree construction stage must handle each token emitted
  68.    from the <a href="section-tokenisation.html#tokenisation0">tokenisation</a> stage as follows:
  69.  
  70.   </p><dl class="switch">
  71.    <dt>A DOCTYPE token that is marked as being in error
  72.  
  73.    </dt><dt>A comment token
  74.  
  75.    </dt><dt>A start tag token
  76.  
  77.    </dt><dt>An end tag token
  78.  
  79.    </dt><dt>A character token that is not one of one of U+0009 CHARACTER
  80.     TABULATION, U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM
  81.     FEED (FF), U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
  82.  
  83.    </dt><dt>An end-of-file token
  84.  
  85.    </dt><dd>
  86.     <p>This specification does not define how to handle this case. In
  87.      particular, user agents may ignore the entirety of this specification
  88.      altogether for such documents, and instead invoke special parse modes
  89.      with a greater emphasis on backwards compatibility.</p>
  90.  
  91.     <div class="note">
  92.      <p>Browsers in particular have generally used DOCTYPE-based sniffing to
  93.       invoke an &quot;alternative conformance mode&quot; known as <em>quirks mode</em>
  94.       on certain documents. In this mode, emphasis is put on legacy
  95.       compatibility rather than on standards compliance. This specification
  96.       takes no position on this behaviour; documents without DOCTYPEs or with
  97.       DOCTYPEs that do not conform to the syntax allowed by this
  98.       specification are considered to be out of scope of this specification.</p>
  99.     </div>
  100.  
  101.     <div class="big-issue">
  102.      <p>As far as parsing goes, the quirks I know of are:</p>
  103.  
  104.      <ul>
  105.       <li>Comment parsing is different.
  106.  
  107.       </li><li>The following is considered one script block (!):
  108.        <pre>&lt;script&gt;&lt;!-- document.write('&lt;/script&gt;'); --&gt;&lt;/script&gt;</pre>
  109.  
  110.       </li><li><code title="">&lt;/br&gt;</code> and <code title="">&lt;/p&gt;</code> do
  111.        magical things.
  112.  
  113.       </li><li><code><a href="section-prose.html#p">p</a></code> can contain <code><a href="section-tabular.html#table">table</a></code>
  114.  
  115.       </li><li>Safari and IE have special parsing rules for &lt;% ... %&gt; (even
  116.        in standards mode, though clearly this should be quirks-only).
  117.      </li></ul>
  118.  
  119.      <p>Maybe we should just adopt all those and be done with it. One parsing
  120.       mode to rule them all. Or legitimise/codify the quirks mode parsing in
  121.       some way.</p>
  122.  
  123.      <p>Would be interesting to do a search to see how many pages hit each of
  124.       the above.</p>
  125.      <!-- biased by page rank? --></div>
  126.  
  127.    </dd><dt>A DOCTYPE token marked as being correct
  128.  
  129.    </dt><dd>
  130.     <p>Append a <code>DocumentType</code> node to the <code>Document</code>
  131.      node, with the <code title="">name</code> attribute set to the name
  132.      given in the DOCTYPE token (which will be &quot;HTML&quot;), and the other
  133.      attributes specific to <code>DocumentType</code> objects set to null,
  134.      empty lists, or the empty string as appropriate.</p>
  135.  
  136.     <p>Then, switch to <a href="#the-root1">the root element phase</a> of the
  137.      tree construction stage.</p>
  138.     <!-- XXX should set doctype on the Document object, too, unless
  139.     spec is defined to already point to it if you append -->
  140.    
  141.  
  142.    </dd><dt>A character token that <em>is</em> one of one of U+0009 CHARACTER
  143.     TABULATION, U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM
  144.     FEED (FF), U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
  145.  
  146.    </dt><dd>
  147.     <p><a href="#append" title="append a character">Append that character</a>
  148.      to the <code>Document</code> node.</p>
  149.   </dd></dl>
  150.  
  151.   <h5 id="the-root0"><span class="secno">8.2.4.2. </span><dfn id="the-root1">The
  152.    root element phase</dfn></h5>
  153.  
  154.   <p>After <a href="#the-initial0">the initial phase</a>, as each token is
  155.    emitted from the <a href="section-tokenisation.html#tokenisation0">tokenisation</a> stage, it must
  156.    be processed as described in this section.
  157.  
  158.   </p><dl class="switch">
  159.    <dt>A DOCTYPE token
  160.  
  161.    </dt><dd>
  162.     <p><a href="section-parsing.html#parse">Parse error</a>. Ignore the token.</p>
  163.  
  164.    </dd><dt>A comment token
  165.  
  166.    </dt><dd>
  167.     <p>Append a <code>Comment</code> node to the <code>Document</code> object
  168.      with the <code title="">data</code> attribute set to the data given in
  169.      the comment token.</p>
  170.  
  171.    </dd><dt>A character token that is one of one of U+0009 CHARACTER TABULATION,
  172.     U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
  173.     U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
  174.  
  175.    </dt><dd>
  176.     <p><a href="#append" title="append a character">Append that character</a>
  177.      to the <code>Document</code> node.</p>
  178.  
  179.    </dd><dt>A character token that is <em>not</em> one of U+0009 CHARACTER
  180.     TABULATION, U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM
  181.     FEED (FF), U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
  182.  
  183.    </dt><dt>A start tag token
  184.  
  185.    </dt><dt>An end tag token
  186.  
  187.    </dt><dt>An end-of-file token
  188.  
  189.    </dt><dd>
  190.     <p>Create an <code><a href="section-elements.html#htmlelement">HTMLElement</a></code> node
  191.      with the tag name <code><a href="section-the-root.html#html">html</a></code>, in the <a href="section-namespaces.html#html-namespace0">HTML namespace</a>. Append it to the
  192.      <code>Document</code> object. Switch to <a href="#the-main0">the main
  193.      phase</a> and reprocess the current token.</p>
  194.  
  195.     <p class="big-issue">Should probably make end tags be ignored, so that
  196.      &quot;&lt;/head&gt;&lt;!-- --&gt;&lt;html&gt;&quot; puts the comment befor the root node
  197.      (or should we?)</p>
  198.   </dd></dl>
  199.  
  200.   <p>The root element can end up being removed from the <code>Document</code>
  201.    object, e.g. by scripts; nothing in particular happens in such cases,
  202.    content continues being appended to the nodes as described in the next
  203.    section.
  204.  
  205.   </p><h5 id="the-main"><span class="secno">8.2.4.3. </span><dfn id="the-main0">The
  206.    main phase</dfn></h5>
  207.  
  208.   <p>After <a href="#the-root1">the root element phase</a>, each token
  209.    emitted from the <a href="section-tokenisation.html#tokenisation0">tokenisation</a> stage must be
  210.    processed as described in <em>this</em> section. This is by far the most
  211.    involved part of parsing an HTML document.
  212.  
  213.   </p><p>The tree construction stage in this phase has several pieces of state: a
  214.    <a href="#stack">stack of open elements</a>, a <a href="#list-of4">list of
  215.    active formatting elements</a>, a <a href="#head-element"><code title="">head</code> element pointer</a>, a <a href="#form-element"><code title="">form</code> element pointer</a>, and an <a href="#insertion0">insertion mode</a>.
  216.  
  217.   </p><p class="big-issue">We could just fold insertion modes and phases into one
  218.    concept (and duplicate the two rules common to all insertion modes into
  219.    all of them).
  220.  
  221.   </p><h6 id="the-stack"><span class="secno">8.2.4.3.1. </span>The stack of open
  222.    elements</h6>
  223.  
  224.   <p>Initially the <dfn id="stack">stack of open elements</dfn> contains just
  225.    the <code><a href="section-the-root.html#html">html</a></code> root element node created in the
  226.    <a href="#the-root1" title="the root element phase">last phase</a> before
  227.    switching to <em>this</em> phase (or, in the <a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>, the <code><a href="section-the-root.html#html">html</a></code> element created to represent the element
  228.    whose <code title="dom-innerHTML-HTML"><a href="section-dynamic.html#innerhtml0">innerHTML</a></code> attribute is being set). That's
  229.   the topmost node of the stack. It never gets popped off the stack. (This
  230.   stack grows downwards.)
  231.  
  232.  </p><p>The <dfn id="current4">current node</dfn> is the bottommost node in this
  233.   stack.
  234.  
  235.  </p><p>Elements in the stack fall into the following categories:
  236.  
  237.  </p><dl>
  238.   <dt><dfn id="special">Special</dfn>
  239.  
  240.   </dt><dd>
  241.    <p>The following HTML elements have varying levels of special parsing
  242.     rules: <code><a href="section-sections.html#address">address</a></code>, <code><a href="section-the-canvas.html#area">area</a></code>, <code><a href="section-document.html#base">base</a></code>,
  243.     <code>basefont</code>, <code>bgsound</code>, <code><a href="section-sections.html#blockquote">blockquote</a></code>, <code><a href="section-sections.html#body0">body</a></code>, <code><a href="section-prose.html#br">br</a></code>,
  244.     <code>center</code>, <code><a href="section-tabular.html#col">col</a></code>, <code><a href="section-tabular.html#colgroup">colgroup</a></code>, <code><a href="section-lists0.html#dd">dd</a></code>,
  245.     <code>dir</code>, <code><a href="section-miscellaneous.html#div">div</a></code>, <code><a href="section-lists0.html#dl">dl</a></code>, <code><a href="section-lists0.html#dt">dt</a></code>, <code><a href="section-embedded.html#embed">embed</a></code>, <code>fieldset</code>,
  246.     <code>form</code>, <code>frame</code>, <code>frameset</code>, <code><a href="section-sections.html#h1">h1</a></code>, <code><a href="section-sections.html#h2">h2</a></code>, <code><a href="section-sections.html#h3">h3</a></code>, <code><a href="section-sections.html#h4">h4</a></code>, <code><a href="section-sections.html#h5">h5</a></code>, <code><a href="section-sections.html#h6">h6</a></code>, <code><a href="section-document.html#head">head</a></code>, <code><a href="section-prose.html#hr">hr</a></code>,
  247.     <code><a href="section-embedded.html#iframe">iframe</a></code>,
  248.     <code>image</code><!-- XXX ? this isn't an element that can end up
  249.    on the stack-->,
  250.      <code><a href="section-embedded.html#img">img</a></code>, <code>input</code>,
  251.      <code>isindex</code>, <code><a href="section-lists0.html#li">li</a></code>, <code><a href="section-document.html#link">link</a></code>, <code>listing</code>, <code><a href="section-the-command.html#menu">menu</a></code>, <code><a href="section-document.html#meta0">meta</a></code>,
  252.      <code>noembed</code>, <code>noframes</code>, <code><a href="section-scripting0.html#noscript">noscript</a></code>, <code><a href="section-lists0.html#ol">ol</a></code>,
  253.      <code>optgroup</code>, <code>option</code>, <code><a href="section-prose.html#p">p</a></code>, <code><a href="section-embedded.html#param">param</a></code>,
  254.      <code>plaintext</code>, <code><a href="section-preformatted.html#pre">pre</a></code>, <code><a href="section-scripting0.html#script0">script</a></code>, <code>select</code>,
  255.      <code>spacer</code>, <code><a href="section-document.html#style">style</a></code>, <code><a href="section-tabular.html#tbody">tbody</a></code>, <code>textarea</code>, <code><a href="section-tabular.html#tfoot0">tfoot</a></code>, <code><a href="section-tabular.html#thead0">thead</a></code>, <code><a href="section-document.html#title1">title</a></code>, <code><a href="section-tabular.html#tr">tr</a></code>,
  256.      <code><a href="section-lists0.html#ul">ul</a></code>, and <code>wbr</code>.
  257.  
  258.    </p></dd><dt><dfn id="scoping">Scoping</dfn>
  259.  
  260.    </dt><dd>
  261.     <p>The following HTML elements introduce new <a href="#have-an" title="has an element in scope">scopes</a> for various parts of the
  262.      parsing: <code>button</code>, <code><a href="section-tabular.html#caption0">caption</a></code>, <code><a href="section-the-root.html#html">html</a></code>, <code>marquee</code>, <code><a href="section-embedded.html#object">object</a></code>, <code><a href="section-tabular.html#table">table</a></code>, <code><a href="section-tabular.html#td">td</a></code> and
  263.      <code><a href="section-tabular.html#th">th</a></code>.
  264.  
  265.    </p></dd><dt><dfn id="formatting">Formatting</dfn>
  266.  
  267.    </dt><dd>
  268.     <p>The following HTML elements are those that end up in the <a href="#list-of4">list of active formatting elements</a>: <code><a href="section-phrase.html#a">a</a></code>, <code><a href="section-phrase.html#b">b</a></code>,
  269.      <code>big</code>, <code><a href="section-phrase.html#em">em</a></code>, <code><a href="section-presentational.html#font">font</a></code>, <code><a href="section-phrase.html#i">i</a></code>,
  270.      <code>nobr</code>, <code>s</code>, <code><a href="section-phrase.html#small">small</a></code>, <code>strike</code>, <code><a href="section-phrase.html#strong">strong</a></code>, <code>tt</code>, and <code>u</code>.
  271.  
  272.    </p></dd><dt><dfn id="phrasing">Phrasing</dfn>
  273.  
  274.    </dt><dd>
  275.     <p>All other elements found while parsing an HTML document.
  276.   </p></dd></dl>
  277.  
  278.   <p class="big-issue">Still need to add these new elements to the lists:
  279.    <code><a href="section-scripting0.html#event-source">event-source</a></code>, <code><a href="section-sections.html#section">section</a></code>, <code><a href="section-sections.html#nav">nav</a></code>,
  280.    <code><a href="section-sections.html#article">article</a></code>, <code><a href="section-sections.html#aside">aside</a></code>, <code><a href="section-sections.html#header">header</a></code>,
  281.    <code><a href="section-sections.html#footer">footer</a></code>, <code><a href="section-interactive.html#datagrid0">datagrid</a></code>, <code><a href="section-the-command.html#command0">command</a></code>
  282.  
  283.   </p><p>The <a href="#stack">stack of open elements</a> is said to <dfn id="have-an" title="has an element in scope">have an element in scope</dfn>
  284.    or <dfn id="have-an0" title="has an element in table scope">have an element
  285.    in <em>table scope</em></dfn> when the following algorithm terminates in a
  286.    match state:
  287.  
  288.   </p><ol>
  289.    <li>
  290.     <p>Initialise <var title="">node</var> to be the <a href="#current4">current node</a> (the bottommost node of the stack).
  291.  
  292.    </p></li><li>
  293.     <p>If <var title="">node</var> is the target node, terminate in a match
  294.      state.
  295.  
  296.    </p></li><li>
  297.     <p>Otherwise, if <var title="">node</var> is a <code><a href="section-tabular.html#table">table</a></code> element, terminate in a failure state.
  298.  
  299.    </p></li><li>
  300.     <p>Otherwise, if the algorithm is the &quot;has an element in scope&quot; variant
  301.      (rather than the &quot;has an element in table scope&quot; variant), and <var title="">node</var> is one of the following, terminate in a failure
  302.      state:</p>
  303.  
  304.     <ul class="brief">
  305.      <li><code><a href="section-tabular.html#caption0">caption</a></code>
  306.  
  307.      </li><li><code><a href="section-tabular.html#td">td</a></code>
  308.  
  309.      </li><li><code><a href="section-tabular.html#th">th</a></code>
  310.  
  311.      </li><li><code>button</code>
  312.  
  313.      </li><li><code>marquee</code>
  314.  
  315.      </li><li><code><a href="section-embedded.html#object">object</a></code>
  316.     </li></ul>
  317.  
  318.    </li><li>
  319.     <p>Otherwise, if <var title="">node</var> is an <code><a href="section-the-root.html#html">html</a></code> element, terminate in a failure state.
  320.      (This can only happen if the <var title="">node</var> is the topmost
  321.      node of the <a href="#stack">stack of open elements</a>, and prevents
  322.      the next step from being invoked if there are no more elements in the
  323.      stack.)
  324.  
  325.    </p></li><li>
  326.     <p>Otherwise, set <var title="">node</var> to the previous entry in the
  327.      <a href="#stack">stack of open elements</a> and return to step 2. (This
  328.      will never fail, since the loop will always terminate in the previous
  329.      step if the top of the stack is reached.)
  330.   </p></li></ol>
  331.  
  332.   <p>Nothing happens if at any time any of the elements in the <a href="#stack">stack of open elements</a> are moved to a new location in,
  333.    or removed from, the <code>Document</code> tree. In particular, the stack
  334.    is not changed in this situation. This can cause, amongst other strange
  335.    effects, content to be appended to nodes that are no longer in the DOM.
  336.  
  337.   </p><p class="note">In some cases (namely, when <a href="#adoptionAgency">closing
  338.    misnested formatting elements</a>), the stack is manipulated in a
  339.    random-access fashion.
  340.  
  341.   </p><h6 id="the-list"><span class="secno">8.2.4.3.2. </span>The list of active
  342.    formatting elements</h6>
  343.  
  344.   <p>Initially the <dfn id="list-of4">list of active formatting elements</dfn>
  345.    is empty. It is used to handle mis-nested <a href="#formatting" title="formatting">formatting element tags</a>.
  346.  
  347.   </p><p>The list contains elements in the <a href="#formatting">formatting</a>
  348.    category, and scope markers. The scope markers are inserted when entering
  349.    buttons, <code><a href="section-embedded.html#object">object</a></code> elements, marquees,
  350.    table cells, and table captions, and are used to prevent formatting from
  351.    &quot;leaking&quot; into tables, buttons, <code><a href="section-embedded.html#object">object</a></code>
  352.    elements, and marquees.
  353.  
  354.   </p><p>When the steps below require the UA to <dfn id="reconstruct">reconstruct
  355.    the active formatting elements</dfn>, the UA must perform the following
  356.    steps:
  357.  
  358.   </p><ol>
  359.    <li>If there are no entries in the <a href="#list-of4">list of active
  360.     formatting elements</a>, then there is nothing to reconstruct; stop this
  361.     algorithm.
  362.  
  363.    </li><li>If the last (most recently added) entry in the <a href="#list-of4">list of active formatting elements</a> is a marker, or
  364.     if it is an element that is in the <a href="#stack">stack of open
  365.     elements</a>, then there is nothing to reconstruct; stop this algorithm.
  366.  
  367.    </li><li>Let <var title="">entry</var> be the last (most recently added)
  368.     element in the <a href="#list-of4">list of active formatting
  369.     elements</a>.
  370.  
  371.    </li><li>If there are no entries before <var title="">entry</var> in the <a href="#list-of4">list of active formatting elements</a>, then jump to
  372.     step 8.
  373.  
  374.    </li><li>Let <var title="">entry</var> be the entry one earlier than <var title="">entry</var> in the <a href="#list-of4">list of active formatting
  375.     elements</a>.
  376.  
  377.    </li><li>If <var title="">entry</var> is neither a marker nor an element that
  378.     is also in the <a href="#stack">stack of open elements</a>, go to step 4.
  379.  
  380.    </li><li>Let <var title="">entry</var> be the element one later than <var title="">entry</var> in the <a href="#list-of4">list of active formatting
  381.     elements</a>.
  382.  
  383.    </li><li>Perform a shallow clone of the element <var title="">entry</var> to
  384.     obtain <var title="">clone</var>. <a href="#refsDOM3CORE">[DOM3CORE]</a>
  385.  
  386.    </li><li>Append <var title="">clone</var> to the <a href="#current4">current
  387.     node</a> and push it onto the <a href="#stack">stack of open elements</a>
  388.     so that it is the new <a href="#current4">current node</a>.
  389.  
  390.    </li><li>Replace the entry for <var title="">entry</var> in the list with an
  391.     entry for <var title="">clone</var>.
  392.  
  393.    </li><li>If the entry for <var title="">clone</var> in the <a href="#list-of4">list of active formatting elements</a> is not the last
  394.     entry in the list, return to step 7.
  395.   </li></ol>
  396.  
  397.   <p>This has the effect of reopening all the formatting elements that were
  398.    opened in the current body, cell, or caption (whichever is youngest) that
  399.    haven't been explicitly closed.
  400.  
  401.  </p><p class="note">The way this specification is written, the <a href="#list-of4">list of active formatting elements</a> always consists of
  402.   elements in chronological order with the least recently added element
  403.   first and the most recently added element last (except for while steps 8
  404.   to 11 of the above algorithm are being executed, of course).
  405.  
  406.  </p><p>When the steps below require the UA to <dfn id="clear0">clear the list of
  407.   active formatting elements up to the last marker</dfn>, the UA must
  408.   perform the following steps:
  409.  
  410.  </p><ol>
  411.   <li>Let <var title="">entry</var> be the last (most recently added) entry
  412.    in the <a href="#list-of4">list of active formatting elements</a>.
  413.  
  414.   </li><li>Remove <var title="">entry</var> from the <a href="#list-of4">list of
  415.    active formatting elements</a>.
  416.  
  417.   </li><li>If <var title="">entry</var> was a marker, then stop the algorithm at
  418.    this point. The list has been cleared up to the last marker.
  419.  
  420.   </li><li>Go to step 1.
  421.  </li></ol>
  422.  
  423.  <h6 id="creating"><span class="secno">8.2.4.3.3. </span>Creating and inserting
  424.   HTML elements</h6>
  425.  
  426.  <p>When the steps below require the UA to <dfn id="create" title="create an
  427.   element for the token">create an element for a token</dfn>, the UA must
  428.   create a node implementing the interface appropriate for the element type
  429.   corresponding to the tag name of the token (as given in the section of
  430.   this specification that defines that element, e.g. for an <code><a href="section-phrase.html#a">a</a></code> element it would be the <code><a href="section-phrase.html#htmlanchorelement">HTMLAnchorElement</a></code> interface), with
  431.   the tag name being the name of that element, with the node being in the <a href="section-namespaces.html#html-namespace0">HTML namespace</a>, and with the attributes on the
  432.   node being those given in the given token.
  433.  
  434.  </p><p>When the steps below require the UA to <dfn id="insert">insert an HTML
  435.   element</dfn> for a token, the UA must first <a href="#create">create an
  436.   element for the token</a>, and then append this node to the <a href="#current4">current node</a>, and push it onto the <a href="#stack">stack of open elements</a> so that it is the new <a href="#current4">current node</a>.
  437.  
  438.  </p><p>The steps below may also require that the UA insert an HTML element in a
  439.   particular place, in which case the UA must <a href="#create">create an
  440.   element for the token</a> and then insert or append the new node in the
  441.   location specified. (This happens in particular during the parsing of
  442.   tables with invalid content.)
  443.  
  444.  </p><p>The interface appropriate for an element that is not defined in this
  445.   specification is <code><a href="section-elements.html#htmlelement">HTMLElement</a></code>.
  446.  
  447.  </p><h6 id="closing"><span class="secno">8.2.4.3.4. </span>Closing elements that
  448.   have implied end tags</h6>
  449.  
  450.  <p>When the steps below require the UA to <dfn id="generate">generate implied
  451.   end tags</dfn>, then, if the <a href="#current4">current node</a> is a
  452.   <code><a href="section-lists0.html#dd">dd</a></code> element, a <code><a href="section-lists0.html#dt">dt</a></code> element, an <code><a href="section-lists0.html#li">li</a></code>
  453.   element, a <code><a href="section-prose.html#p">p</a></code> element, a <code><a href="section-tabular.html#td">td</a></code> element, a <code><a href="section-tabular.html#th">th</a></code>
  454.   element, or a <code><a href="section-tabular.html#tr">tr</a></code> element, the UA must act
  455.   as if an end tag with the respective tag name had been seen and then <a href="#generate">generate implied end tags</a> again.
  456.  
  457.  </p><p>The step that requires the UA to generate implied end tags but lists an
  458.   element to exclude from the process, then the UA must perform the above
  459.   steps as if that element was not in the above list.
  460.  
  461.  </p><h6 id="the-element"><span class="secno">8.2.4.3.5. </span>The element pointers</h6>
  462.  
  463.  <p>Initially the <dfn id="head-element"><code title="">head</code> element
  464.   pointer</dfn> and the <dfn id="form-element"><code title="">form</code>
  465.   element pointer</dfn> are both null.
  466.  
  467.  </p><p>Once a <code><a href="section-document.html#head">head</a></code> element has been parsed
  468.   (whether implicitly or explicitly) the <a href="#head-element"><code title="">head</code> element pointer</a> gets set to point to this node.
  469.  
  470.  </p><p>The <a href="#form-element"><code title="">form</code> element
  471.   pointer</a> points to the last <code>form</code> element that was opened
  472.   and whose end tag has not yet been seen. It is used to make form controls
  473.   associate with forms in the face of dramatically bad markup, for
  474.   historical reasons.
  475.  
  476.  </p><h6 id="the-insertion"><span class="secno">8.2.4.3.6. </span>The insertion mode</h6>
  477.  
  478.  <p>Initially the <dfn id="insertion0">insertion mode</dfn> is &quot;<a href="#before2" title="insertion mode: before head">before head</a>&quot;. It
  479.   can change to &quot;<a href="#in-head" title="insertion mode: in head">in
  480.   head</a>&quot;, &quot;<a href="#after1" title="insertion mode: after head">after
  481.   head</a>&quot;, &quot;<a href="#in-body" title="insertion mode: in body">in
  482.   body</a>&quot;, &quot;<a href="#in-table" title="insertion mode: in table">in
  483.   table</a>&quot;, &quot;<a href="#in-caption" title="insertion mode: in caption">in
  484.   caption</a>&quot;, &quot;<a href="#in-column" title="insertion mode: in column
  485.   group">in column group</a>&quot;, &quot;<a href="#in-table0" title="insertion mode:
  486.   in table body">in table body</a>&quot;, &quot;<a href="#in-row" title="insertion
  487.   mode: in row">in row</a>&quot;, &quot;<a href="#in-cell" title="insertion mode: in
  488.   cell">in cell</a>&quot;, &quot;<a href="#in-select" title="insertion mode: in
  489.   select">in select</a>&quot;, &quot;<a href="#after2" title="insertion mode: after
  490.   body">after body</a>&quot;, &quot;<a href="#in-frameset" title="insertion mode: in
  491.   frameset">in frameset</a>&quot;, and &quot;<a href="#after3" title="insertion mode:
  492.   after frameset">after frameset</a>&quot; during the course of the parsing, as
  493.   described below. It affects how certain tokens are processed.
  494.  
  495.  </p><p>If the tree construction stage is switched from <a href="#the-main0">the
  496.   main phase</a> to <a href="#the-trailing0">the trailing end phase</a> and
  497.   back again, the various pieces of state are not reset; the UA must act as
  498.   if the state was maintained.
  499.  
  500.  </p><p>When the steps below require the UA to <dfn id="reset">reset the insertion
  501.   mode appropriately</dfn>, it means the UA must follow these steps:
  502.  
  503.  </p><ol>
  504.   <li>Let <var title="">last</var> be false.
  505.  
  506.   </li><li>Let <var title="">node</var> be the last node in the <a href="#stack">stack of open elements</a>.
  507.  
  508.   </li><li>If <var title="">node</var> is the first node in the stack of open
  509.    elements, then set <var title="">last</var> to true. If the element whose
  510.    <code title="dom-innerHTML-HTML"><a href="section-dynamic.html#innerhtml0">innerHTML</a></code>
  511.    attribute is being set is neither a <code><a href="section-tabular.html#td">td</a></code>
  512.    element nor a <code><a href="section-tabular.html#th">th</a></code> element, then set <var title="">node</var> to the element whose <code title="dom-innerHTML-HTML"><a href="section-dynamic.html#innerhtml0">innerHTML</a></code>
  513.    attribute is being set. (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code>
  514.    case</a>)
  515.  
  516.   </li><li>If <var title="">node</var> is a <code>select</code> element, then
  517.    switch the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-select" title="insertion mode: in select">in select</a>&quot; and
  518.    abort these steps. (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code>
  519.    case</a>)
  520.  
  521.   </li><li>If <var title="">node</var> is a <code><a href="section-tabular.html#td">td</a></code> or
  522.    <code><a href="section-tabular.html#th">th</a></code> element, then switch the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-cell" title="insertion mode: in cell">in cell</a>&quot; and abort these steps.
  523.  
  524.   </li><li>If <var title="">node</var> is a <code><a href="section-tabular.html#tr">tr</a></code>
  525.    element, then switch the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-row" title="insertion mode: in row">in row</a>&quot; and abort these
  526.    steps.
  527.  
  528.   </li><li>If <var title="">node</var> is a <code><a href="section-tabular.html#tbody">tbody</a></code>, <code><a href="section-tabular.html#thead0">thead</a></code>,
  529.    or <code><a href="section-tabular.html#tfoot0">tfoot</a></code> element, then switch the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-table0" title="insertion mode: in table body">in table body</a>&quot; and abort these
  530.    steps.
  531.  
  532.   </li><li>If <var title="">node</var> is a <code><a href="section-tabular.html#caption0">caption</a></code> element, then switch the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-caption" title="insertion mode: in caption">in caption</a>&quot; and abort these steps.
  533.  
  534.   </li><li>If <var title="">node</var> is a <code><a href="section-tabular.html#colgroup">colgroup</a></code> element, then switch the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-column" title="insertion mode: in column group">in column group</a>&quot; and abort
  535.    these steps. (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>)
  536.  
  537.   </li><li>If <var title="">node</var> is a <code><a href="section-tabular.html#table">table</a></code> element, then switch the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-table" title="insertion mode: in table">in table</a>&quot; and abort these steps.
  538.  
  539.   </li><li>If <var title="">node</var> is a <code><a href="section-document.html#head">head</a></code>
  540.    element, then switch the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-body" title="insertion mode: in body">in body</a>&quot; (&quot;<a href="#in-body" title="insertion mode: in body">in body</a>&quot;! <em> not
  541.    &quot;<a href="#in-head" title="insertion mode: in head">in head</a>&quot;</em>!)
  542.    and abort these steps. (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code>
  543.    case</a>)
  544.  
  545.   </li><li>If <var title="">node</var> is a <code><a href="section-sections.html#body0">body</a></code> element, then switch the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-body" title="insertion mode: in body">in body</a>&quot; and abort these steps.
  546.  
  547.   </li><li>If <var title="">node</var> is a <code>frameset</code> element, then
  548.    switch the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-frameset" title="insertion mode: in frameset">in frameset</a>&quot;
  549.    and abort these steps. (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code>
  550.    case</a>)
  551.  
  552.   </li><li>If <var title="">node</var> is an <code><a href="section-the-root.html#html">html</a></code> element, then: if the <a href="#head-element"><code title="">head</code> element pointer</a> is
  553.    null, switch the <a href="#insertion0">insertion mode</a> to &quot;<a href="#before2" title="insertion mode: before head">before head</a>&quot;,
  554.    otherwise, switch the <a href="#insertion0">insertion mode</a> to &quot;<a href="#after1" title="insertion mode: after head">after head</a>&quot;. In
  555.    either case, abort these steps. (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>)</li>
  556.   <!-- XXX can the head element pointer ever be
  557.   non-null when we're going through these steps? -->
  558.  
  559.    <li>If <var title="">last</var> is true, then set the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-body" title="insertion mode: in body">in body</a>&quot; and abort these steps. (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>)
  560.  
  561.    </li><li>Let <var title="">node</var> now be the node before <var title="">node</var> in the <a href="#stack">stack of open elements</a>.
  562.  
  563.    </li><li>Return to step 3.
  564.   </li></ol>
  565.   <!--When you don't have to handle innerHTML, you can use this
  566. simplified explanation instead:
  567.  
  568.  <ol>
  569.  
  570.   <li><p>If the <span>stack of open elements</span> <span title="has
  571.   an element in table scope">has a <code>td</code> or <code>th</code>
  572.   element in table scope</span>, then switch the <span>insertion
  573.   mode</span> to "<span title="insertion mode: in cell">in
  574.   cell</span>".</p></li>
  575.  
  576.   <li><p>Otherwise, if the <span>stack of open elements</span> <span
  577.   title="has an element in table scope">has a <code>tr</code> element
  578.   in table scope</span>, then switch the <span>insertion mode</span>
  579.   to "<span title="insertion mode: in row">in row</span>".</p></li>
  580.  
  581.   <li><p>Otherwise, if the <span>stack of open elements</span> <span
  582.   title="has an element in table scope">has a <code>tbody</code>,
  583.   <code>tfoot</code>, or <code>thead</code> element in table
  584.   scope</span>, then switch the <span>insertion mode</span> to "<span
  585.   title="insertion mode: in table body">in table
  586.   body</span>".</p></li>
  587.  
  588.   <li><p>Otherwise, if the <span>stack of open elements</span> <span
  589.   title="has an element in table scope">has a <code>caption</code>
  590.   element in table scope</span>, then switch the <span>insertion
  591.   mode</span> to "<span title="insertion mode: in caption">in
  592.   caption</span>".</p></li>
  593.  
  594.   ( you can't reach this point with a colgroup element on the
  595.    stack )
  596.  
  597.    <li><p>Otherwise, if the <span>stack of open elements</span> <span
  598.    title="has an element in table scope">has a <code>table</code>
  599.    element in table scope</span>, then switch the <span>insertion
  600.    mode</span> to "<span title="insertion mode: in table">in
  601.   table</span>".</p></li>
  602.  
  603.    <li><p>Otherwise, switch the <span>insertion mode</span> to "<span
  604.   title="insertion mode: in body">in body</span>".</p></li>
  605.  
  606.   </ol>
  607. -->
  608.  
  609.   <h6 id="how-to0"><span class="secno">8.2.4.3.7. </span>How to handle tokens in
  610.    the main phase</h6>
  611.  
  612.   <p>Tokens in the main phase must be handled as follows:
  613.  
  614.   </p><dl class="switch">
  615.    <dt>A DOCTYPE token
  616.  
  617.    </dt><dd>
  618.     <p><a href="section-parsing.html#parse">Parse error</a>. Ignore the token.</p>
  619.  
  620.    </dd><dt>A start tag token with the tag name &quot;html&quot;
  621.  
  622.    </dt><dd>
  623.     <p>If this start tag token was not the first start tag token, then it is
  624.      a <a href="section-parsing.html#parse">parse error</a>.</p>
  625.  
  626.     <p>For each attribute on the token, check to see if the attribute is
  627.      already present on the top element of the <a href="#stack">stack of open
  628.      elements</a>. If it is not, add the attribute and its corresponding
  629.      value to that element.</p>
  630.  
  631.    </dd><dt>An end-of-file token
  632.  
  633.    </dt><dd>
  634.     <p><a href="#generate">Generate implied end tags.</a></p>
  635.  
  636.     <p>If there are more than two nodes on the <a href="#stack">stack of open
  637.      elements</a>, or if there are two nodes but the second node is not a
  638.      <code><a href="section-sections.html#body0">body</a></code> node, this is a <a href="section-parsing.html#parse">parse error</a>.</p>
  639.  
  640.     <p>Otherwise, if the parser was originally created in order to handle the
  641.      setting of an element's <code title="dom-innerHTML-HTML"><a href="section-dynamic.html#innerhtml0">innerHTML</a></code> attribute, and there's more than
  642.      one element in the <a href="#stack">stack of open elements</a>, and the
  643.      second node on the <a href="#stack">stack of open elements</a> is not a
  644.      <code><a href="section-sections.html#body0">body</a></code> node, then this is a <a href="section-parsing.html#parse">parse error</a>. (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>)</p>
  645.  
  646.     <p><a href="#stops">Stop parsing.</a></p>
  647.  
  648.     <p class="big-issue">This fails because it doesn't imply HEAD and BODY
  649.     tags. We should probably expand out the insertion modes and merge them
  650.     with phases and then put the three things here into each insertion mode
  651.     instead of trying to factor them out so carefully.</p>
  652.  
  653.   </dd><dt>Anything else
  654.  
  655.   </dt><dd>
  656.    <p>Depends on the <a href="#insertion0">insertion mode</a>:</p>
  657.  
  658.    <dl class="switch">
  659.     <dt>If the <a href="#insertion0">insertion mode</a> is &quot;<dfn id="before2" title="insertion mode: before head">before head</dfn>&quot;
  660.  
  661.     </dt><dd>
  662.      <p>Handle the token as follows:</p>
  663.  
  664.      <dl class="switch">
  665.       <dt>A character token that is one of one of U+0009 CHARACTER
  666.        TABULATION, U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C
  667.        FORM FEED (FF), U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
  668.  
  669.       </dt><dd>
  670.        <p><a href="#append" title="append a character">Append the
  671.         character</a> to the <a href="#current4">current node</a>.</p>
  672.  
  673.       </dd><dt>A comment token
  674.  
  675.       </dt><dd>
  676.        <p>Append a <code>Comment</code> node to the <a href="#current4">current node</a> with the <code title="">data</code> attribute set to the data given in the comment
  677.         token.</p>
  678.  
  679.       </dd><dt>A start tag token with the tag name &quot;head&quot;
  680.  
  681.       </dt><dd>
  682.        <p><a href="#create">Create an element for the token</a>.</p>
  683.  
  684.        <p>Set the <a href="#head-element"><code title="">head</code> element
  685.         pointer</a> to this new element node.</p>
  686.  
  687.        <p>Append the new element to the <a href="#current4">current node</a>
  688.         and push it onto the <a href="#stack">stack of open elements</a>.</p>
  689.  
  690.        <p>Change the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-head" title="insertion mode: in head">in head</a>&quot;.</p>
  691.  
  692.       </dd><dt>A start tag token whose tag name is one of: &quot;base&quot;, &quot;link&quot;,
  693.        &quot;meta&quot;, &quot;script&quot;, &quot;style&quot;, &quot;title&quot;
  694.  
  695.       </dt><dd>
  696.        <p>Act as if a start tag token with the tag name &quot;head&quot; and no
  697.         attributes had been seen, then reprocess the current token.</p>
  698.  
  699.        <p class="note">This will result in a <code><a href="section-document.html#head">head</a></code> element being generated, and with the
  700.         current token being reprocessed in the &quot;<a href="#in-head" title="insertion mode: in head">in head</a>&quot; <a href="#insertion0">insertion mode</a>.</p>
  701.  
  702.       </dd><dt>An end tag with the tag name &quot;html&quot;
  703.  
  704.       </dt><dd>
  705.        <p>Act as if a start tag token with the tag name &quot;head&quot; and no
  706.         attributes had been seen, then reprocess the current token.</p>
  707.  
  708.       </dd><dt>Any other end tag
  709.  
  710.       </dt><dd>
  711.        <p><a href="section-parsing.html#parse">Parse error</a>. Ignore the token.</p>
  712.  
  713.       </dd><dt>A character token that is <em>not</em> one of U+0009 CHARACTER
  714.        TABULATION, U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C
  715.        FORM FEED (FF), U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
  716.  
  717.       </dt><dt>Any other start tag token
  718.  
  719.       </dt><dd>
  720.        <p>Act as if a start tag token with the tag name &quot;head&quot; and no
  721.         attributes had been seen, then reprocess the current token.</p>
  722.  
  723.        <p class="note">This will result in an empty <code><a href="section-document.html#head">head</a></code> element being generated, with the
  724.         current token being reprocessed in the &quot;<a href="#after1" title="insertion mode: after head">after head</a>&quot; <a href="#insertion0">insertion mode</a>.</p>
  725.      </dd></dl>
  726.  
  727.     </dd><dt id="parsing-main-inhead">If the <a href="#insertion0">insertion
  728.      mode</a> is &quot;<dfn id="in-head" title="insertion mode: in head">in
  729.      head</dfn>&quot;
  730.  
  731.     </dt><dd>
  732.      <p>Handle the token as follows.</p>
  733.  
  734.      <p class="note">The rules for handling &quot;title&quot;, &quot;style&quot;, and &quot;script&quot;
  735.       start tags are similar, but not identical.</p>
  736.  
  737.      <p class="note">It is possible for the <a href="#tree-construction0">tree
  738.       construction</a> stage's <a href="#the-main0" title="the main
  739.       phase">main phase</a> to be in the &quot;<a href="#in-head" title="insertion mode: in head">in head</a>&quot; <a href="#insertion0">insertion mode</a> without the <a href="#current4">current node</a> being a <code><a href="section-document.html#head">head</a></code> element, e.g. if a <code><a href="section-document.html#head">head</a></code> end tag is immediately followed by a
  740.        <code><a href="section-document.html#meta0">meta</a></code> start tag.</p>
  741.  
  742.       <dl class="switch">
  743.        <dt>A character token that is one of one of U+0009 CHARACTER
  744.         TABULATION, U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C
  745.         FORM FEED (FF), U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
  746.  
  747.        </dt><dd>
  748.         <p><a href="#append" title="append a character">Append the
  749.          character</a> to the <a href="#current4">current node</a>.</p>
  750.  
  751.        </dd><dt>A comment token
  752.  
  753.        </dt><dd>
  754.         <p>Append a <code>Comment</code> node to the <a href="#current4">current node</a> with the <code title="">data</code> attribute set to the data given in the comment
  755.          token.</p>
  756.  
  757.        </dd><dt>A start tag with the tag name &quot;title&quot;
  758.  
  759.        </dt><dd>
  760.         <p><a href="#create">Create an element for the token</a>.</p>
  761.  
  762.         <p>Append the new element to the node pointed to by the <a href="#head-element"><code title="">head</code> element pointer</a>,
  763.          or, if that is null (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code>
  764.          case</a>), to the <a href="#current4">current node</a>.</p>
  765.  
  766.         <p>Switch the tokeniser's <a href="section-tokenisation.html#content2">content model flag</a>
  767.         to the RCDATA state.</p>
  768.  
  769.        <p>Then, collect all the character tokens that the tokeniser returns
  770.         until it returns a token that is not a character token.</p>
  771.  
  772.        <p>If this process resulted in a collection of character tokens,
  773.         append a single <code>Text</code> node to the <code><a href="section-document.html#title1">title</a></code> element node whose contents is the
  774.         concatenation of all those tokens' characters.</p>
  775.  
  776.         <p>The tokeniser's <a href="section-tokenisation.html#content2">content model flag</a> will
  777.         have switched back to the PCDATA state.</p>
  778.  
  779.        <p>If the next token is an end tag token with the tag name &quot;title&quot;,
  780.         ignore it. Otherwise, this is a <a href="section-parsing.html#parse">parse error</a>.</p>
  781.  
  782.       </dd><dt>A start tag with the tag name &quot;style&quot;
  783.  
  784.       </dt><dd>
  785.        <p><a href="#create">Create an element for the token</a>.</p>
  786.  
  787.        <p>Append the new element to the <a href="#current4">current
  788.         node</a>, unless the <a href="#insertion0">insertion mode</a> is &quot;<a href="#in-head" title="insertion mode: in head">in head</a>&quot; and the
  789.         <a href="#head-element"><code title="">head</code> element
  790.         pointer</a> is not null, in which case append it to the node pointed
  791.         to by the <a href="#head-element"><code title="">head</code> element
  792.         pointer</a>. <!--
  793.        <head></head><style><body> should put the style block in the
  794.        head, and does so by switching back to in head, but the head
  795.        isn't the current node at that point (comments should go
  796.         between the head and the body) -->.</p>
  797.  
  798.         <p>Switch the tokeniser's <a href="section-tokenisation.html#content2">content model flag</a>
  799.         to the CDATA state.</p>
  800.  
  801.        <p>Then, collect all the character tokens that the tokeniser returns
  802.         until it returns a token that is not a character token, or until it
  803.         stops tokenising.</p>
  804.  
  805.        <p>If this process resulted in a collection of character tokens,
  806.         append a single <code>Text</code> node to the <code><a href="section-document.html#style">style</a></code> element node whose contents is the
  807.         concatenation of all those tokens' characters.</p>
  808.  
  809.         <p>The tokeniser's <a href="section-tokenisation.html#content2">content model flag</a> will
  810.         have switched back to the PCDATA state.</p>
  811.  
  812.        <p>If the next token is an end tag token with the tag name &quot;style&quot;,
  813.         ignore it. Otherwise, this is a <a href="section-parsing.html#parse">parse error</a>.</p>
  814.  
  815.       </dd><dt id="scriptTag">A start tag with the tag name &quot;script&quot;
  816.  
  817.       </dt><dd>
  818.        <p><a href="#create">Create an element for the token</a>.</p>
  819.  
  820.        <p>Mark the element as being <a href="section-scripting0.html#parser-inserted">&quot;parser-inserted&quot;</a>. This ensures that, if
  821.         the script is external, any <code title="dom-document-write-HTML"><a href="section-dynamic.html#document.write0">document.write()</a></code> calls in the
  822.         script will execute in-line, instead of blowing the document away,
  823.         as would happen in most other cases.</p>
  824.  
  825.        <p>Switch the tokeniser's <a href="section-tokenisation.html#content2">content model flag</a>
  826.          to the CDATA state.</p>
  827.  
  828.         <p>Then, collect all the character tokens that the tokeniser returns
  829.          until it returns a token that is not a character token, or until it
  830.          stops tokenising.</p>
  831.  
  832.         <p>If this process resulted in a collection of character tokens,
  833.          append a single <code>Text</code> node to the <code><a href="section-scripting0.html#script0">script</a></code> element node whose contents is the
  834.          concatenation of all those tokens' characters.</p>
  835.  
  836.        <p>The tokeniser's <a href="section-tokenisation.html#content2">content model flag</a> will
  837.          have switched back to the PCDATA state.</p>
  838.  
  839.         <p>If the next token is not an end tag token with the tag name
  840.          &quot;script&quot;, then this is a <a href="section-parsing.html#parse">parse error</a>; mark the
  841.          <code><a href="section-scripting0.html#script0">script</a></code> element as <a href="section-scripting0.html#already">&quot;already executed&quot;</a>. Otherwise, the token is the
  842.          <code><a href="section-scripting0.html#script0">script</a></code> element's end tag, so
  843.         ignore it.</p>
  844.  
  845.        <p>If the parser was originally created in order to handle the
  846.         setting of a node's <code title="dom-innerHTML-HTML"><a href="section-dynamic.html#innerhtml0">innerHTML</a></code> attribute, then mark the
  847.          <code><a href="section-scripting0.html#script0">script</a></code> element as <a href="section-scripting0.html#already">&quot;already executed&quot;</a>, and skip the rest of the
  848.          processing described for this token (including the part below where
  849.          &quot;<a href="section-scripting0.html#the-script" title="the script that will execute as soon
  850.         as the parser resumes">scripts that will execute as soon as the
  851.          parser resumes</a>&quot; are executed). (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>)</p>
  852.  
  853.         <p class="note">Marking the <code><a href="section-scripting0.html#script0">script</a></code>
  854.          element as &quot;already executed&quot; prevents it from executing when it is
  855.          inserted into the document a few paragraphs below. Scripts missing
  856.          their end tags and scripts that were inserted using <code title="dom-innerHTML-HTML"><a href="section-dynamic.html#innerhtml0">innerHTML</a></code>
  857.          aren't executed.</p>
  858.  
  859.        <p>Let the <var title="">old insertion point</var> have the same
  860.         value as the current <a href="section-parsing.html#insertion">insertion point</a>. Let
  861.         the <a href="section-parsing.html#insertion">insertion point</a> be just before the <a href="section-parsing.html#next-input">next input character</a>.</p>
  862.  
  863.        <p>Append the new element to the <a href="#current4">current
  864.         node</a>, unless the <a href="#insertion0">insertion mode</a> is &quot;<a href="#in-head" title="insertion mode: in head">in head</a>&quot; and the
  865.         <a href="#head-element"><code title="">head</code> element
  866.         pointer</a> is not null, in which case append it to the node pointed
  867.         to by the <a href="#head-element"><code title="">head</code> element
  868.         pointer</a>. <!--
  869.        <head></head><script><body> should put the script in the head,
  870.        and does so by switching back to in head, but the head isn't
  871.         the current node at that point (comments should go between the
  872.         head and the body) -->
  873.          <a href="section-scripting0.html#running0" title="running a script">Special processing
  874.          occurs when a <code>script</code> element is inserted into a
  875.          document</a> that might cause some script to execute, which might
  876.          cause <a href="section-dynamic.html#document.write0" title="dom-document-write-HTML">new
  877.          characters to be inserted into the tokeniser</a>.</p>
  878.  
  879.         <p>Let the <a href="section-parsing.html#insertion">insertion point</a> have the value of
  880.          the <var title="">old insertion point</var>. (In other words,
  881.          restore the <a href="section-parsing.html#insertion">insertion point</a> to the value it
  882.          had before the previous paragraph. This value might be the
  883.          &quot;undefined&quot; value.)</p>
  884.  
  885.         <p id="scriptTagParserResumes">At this stage, if there is <a href="section-scripting0.html#the-script" title="the script that will execute as soon as
  886.         the parser resumes">a script that will execute as soon as the parser
  887.          resumes</a>, then:</p>
  888.  
  889.         <dl class="switch">
  890.          <dt>If the tree construction stage is <a href="section-parsing.html#nestedParsing">being
  891.           called reentrantly</a>, say from a call to <code title="dom-document-write-HTML"><a href="section-dynamic.html#document.write0">document.write()</a></code>:
  892.  
  893.          </dt><dd>
  894.           <p>Abort the processing of any nested invokations of the tokeniser,
  895.            yielding control back to the caller. (Tokenisation will resume
  896.            when the caller returns to the &quot;outer&quot; tree construction stage.)
  897.  
  898.          </p></dd><dt>Otherwise:
  899.  
  900.          </dt><dd>
  901.           <p>Follow these steps:</p>
  902.  
  903.           <ol>
  904.            <li>
  905.             <p>Let <var title="">the script</var> be <a href="section-scripting0.html#the-script">the script that will execute as soon as the
  906.              parser resumes</a>. There is no longer <a href="section-scripting0.html#the-script" title="the script that will execute as soon as the parser
  907.             resumes">a script that will execute as soon as the parser
  908.              resumes</a>.
  909.  
  910.            </p></li><li>
  911.             <p><a href="section-terminology.html#pause">Pause</a> until the script has
  912.              <span>completed loading</span><!-- XXX xref -->.
  913.  
  914.            </p></li><li>
  915.             <p>Let the <a href="section-parsing.html#insertion">insertion point</a> be just
  916.              before the <a href="section-parsing.html#next-input">next input character</a>.
  917.  
  918.            </p></li><li>
  919.             <p><a href="section-scripting0.html#executing0" title="executing a script block">Execute
  920.              the script</a>.
  921.  
  922.            </p></li><li>
  923.             <p>Let the <a href="section-parsing.html#insertion">insertion point</a> be undefined
  924.              again.
  925.  
  926.            </p></li><li>
  927.             <p>If there is once again <a href="section-scripting0.html#the-script" title="the script
  928.             that will execute as soon as the parser resumes">a script that
  929.              will execute as soon as the parser resumes</a>, then repeat
  930.              these steps from step 1.
  931.           </p></li></ol>
  932.         </dd></dl>
  933.  
  934.        </dd><dt>A start tag with the tag name &quot;base&quot;, &quot;link&quot;, or &quot;meta&quot;
  935.  
  936.        </dt><dd>
  937.         <p><a href="#create">Create an element for the token</a>.</p>
  938.  
  939.         <p>Append the new element to the node pointed to by the <a href="#head-element"><code title="">head</code> element pointer</a>,
  940.          or, if that is null (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code>
  941.          case</a>), to the <a href="#current4">current node</a>.</p>
  942.  
  943.        </dd><dt>An end tag with the tag name &quot;head&quot;
  944.  
  945.        </dt><dd>
  946.         <p>If the <a href="#current4">current node</a> is a <code><a href="section-document.html#head">head</a></code> element, pop the <a href="#current4">current node</a> off the <a href="#stack">stack of
  947.          open elements</a>. Otherwise, this is a <a href="section-parsing.html#parse">parse
  948.          error</a>.</p>
  949.         <!-- might happen if you see two </head>s
  950.         and something in between the two sends you from "after head"
  951.         back to "in head" -->
  952.        
  953.         <p>Change the <a href="#insertion0">insertion mode</a> to &quot;<a href="#after1" title="insertion mode: after head">after head</a>&quot;.</p>
  954.  
  955.        </dd><dt>An end tag with the tag name &quot;html&quot;
  956.  
  957.        </dt><dd>
  958.         <p>Act as described in the &quot;anything else&quot; entry below.</p>
  959.  
  960.        </dd><dt>A start tag with the tag name &quot;head&quot;
  961.  
  962.        </dt><dt>Any other end tag
  963.  
  964.        </dt><dd>
  965.         <p><a href="section-parsing.html#parse">Parse error</a>. Ignore the token.</p>
  966.  
  967.        </dd><dt>Anything else
  968.  
  969.        </dt><dd>
  970.         <p>If the <a href="#current4">current node</a> is a <code><a href="section-document.html#head">head</a></code> element, act as if an end tag token
  971.          with the tag name &quot;head&quot; had been seen.</p>
  972.  
  973.         <p>Otherwise, change the <a href="#insertion0">insertion mode</a> to
  974.          &quot;<a href="#after1" title="insertion mode: after head">after
  975.          head</a>&quot;.</p>
  976.  
  977.         <p>Then, reprocess the current token.</p>
  978.  
  979.         <p class="big-issue">In certain UAs, <a href="https://bugzilla.mozilla.org/attachment.cgi?id=180157&amp;action=view">some
  980.          elements</a> don't trigger the &quot;in body&quot; mode straight away, but
  981.         instead get put into the head. Do we want to copy that?</p>
  982.      </dd></dl>
  983.  
  984.     </dd><dt>If the <a href="#insertion0">insertion mode</a> is &quot;<dfn id="after1" title="insertion mode: after head">after head</dfn>&quot;
  985.  
  986.     </dt><dd>
  987.      <p>Handle the token as follows:</p>
  988.  
  989.      <dl class="switch">
  990.       <dt>A character token that is one of one of U+0009 CHARACTER
  991.        TABULATION, U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C
  992.        FORM FEED (FF), U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
  993.  
  994.       </dt><dd>
  995.        <p><a href="#append" title="append a character">Append the
  996.         character</a> to the <a href="#current4">current node</a>.</p>
  997.  
  998.       </dd><dt>A comment token
  999.  
  1000.       </dt><dd>
  1001.        <p>Append a <code>Comment</code> node to the <a href="#current4">current node</a> with the <code title="">data</code> attribute set to the data given in the comment
  1002.         token.</p>
  1003.  
  1004.       </dd><dt>A start tag token with the tag name &quot;body&quot;
  1005.  
  1006.       </dt><dd>
  1007.        <p><a href="#insert" title="insert an HTML element">Insert a
  1008.         <code>body</code> element</a> for the token.</p>
  1009.  
  1010.        <p>Change the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-body" title="insertion mode: in body">in body</a>&quot;.</p>
  1011.  
  1012.       </dd><dt>A start tag token with the tag name &quot;frameset&quot;
  1013.  
  1014.       </dt><dd>
  1015.        <p><a href="#insert" title="insert an HTML element">Insert a
  1016.         <code>frameset</code> element</a> for the token.</p>
  1017.  
  1018.        <p>Change the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-frameset" title="insertion mode: in frameset">in
  1019.         frameset</a>&quot;.</p>
  1020.  
  1021.       </dd><dt>A start tag token whose tag name is one of: &quot;base&quot;, &quot;link&quot;,
  1022.        &quot;meta&quot;, &quot;script&quot;, &quot;style&quot;, &quot;title&quot;
  1023.  
  1024.       </dt><dd>
  1025.        <p><a href="section-parsing.html#parse">Parse error</a>. Switch the <a href="#insertion0">insertion mode</a> back to &quot;<a href="#in-head" title="insertion mode: in head">in head</a>&quot; and reprocess the
  1026.         token.</p>
  1027.  
  1028.       </dd><dt>Anything else
  1029.  
  1030.       </dt><dd>
  1031.        <p>Act as if a start tag token with the tag name &quot;body&quot; and no
  1032.         attributes had been seen, and then reprocess the current token.</p>
  1033.      </dd></dl>
  1034.  
  1035.     </dd><dt id="parsing-main-inbody">If the <a href="#insertion0">insertion
  1036.      mode</a> is &quot;<dfn id="in-body" title="insertion mode: in body">in
  1037.      body</dfn>&quot;
  1038.  
  1039.     </dt><dd>
  1040.      <p>Handle the token as follows:</p>
  1041.  
  1042.      <dl class="switch">
  1043.       <dt>A character token
  1044.  
  1045.       </dt><dd>
  1046.        <p><a href="#reconstruct">Reconstruct the active formatting
  1047.         elements</a>, if any.</p>
  1048.  
  1049.        <p><a href="#append" title="append a character">Append the token's
  1050.          character</a> to the <a href="#current4">current node</a>.</p>
  1051.  
  1052.        </dd><dt>A comment token
  1053.  
  1054.        </dt><dd>
  1055.         <p>Append a <code>Comment</code> node to the <a href="#current4">current node</a> with the <code title="">data</code> attribute set to the data given in the comment
  1056.          token.</p>
  1057.  
  1058.        </dd><dt>A start tag token whose tag name is one of: &quot;script&quot;, &quot;style&quot;
  1059.  
  1060.        </dt><dd>
  1061.         <p>Process the token as if the <a href="#insertion0">insertion
  1062.          mode</a> had been &quot;<a href="#in-head" title="insertion mode: in
  1063.         head">in head</a>&quot;.</p>
  1064.  
  1065.        </dd><dt>A start tag token whose tag name is one of: &quot;base&quot;, &quot;link&quot;,
  1066.         &quot;meta&quot;, &quot;title&quot;
  1067.  
  1068.        </dt><dd>
  1069.         <p><a href="section-parsing.html#parse">Parse error</a>. Process the token as if the <a href="#insertion0">insertion mode</a> had been &quot;<a href="#in-head" title="insertion mode: in head">in head</a>&quot;.</p>
  1070.  
  1071.        </dd><dt>A start tag token with the tag name &quot;body&quot;
  1072.  
  1073.        </dt><dd>
  1074.         <p><a href="section-parsing.html#parse">Parse error</a>.</p>
  1075.  
  1076.         <p>If the second element on the <a href="#stack">stack of open
  1077.          elements</a> is not a <code><a href="section-sections.html#body0">body</a></code>
  1078.          element, or, if the <a href="#stack">stack of open elements</a> has
  1079.          only one node on it, then ignore the token. (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>)</p>
  1080.  
  1081.         <p>Otherwise, for each attribute on the token, check to see if the
  1082.          attribute is already present on the <code><a href="section-sections.html#body0">body</a></code> element (the second element) on the <a href="#stack">stack of open elements</a>. If it is not, add the
  1083.          attribute and its corresponding value to that element.</p>
  1084.  
  1085.        </dd><dt>An end tag with the tag name &quot;body&quot;
  1086.  
  1087.        </dt><dd>
  1088.         <p>If the second element in the <a href="#stack">stack of open
  1089.          elements</a> is not a <code><a href="section-sections.html#body0">body</a></code>
  1090.          element, this is a <a href="section-parsing.html#parse">parse error</a>. Ignore the
  1091.          token. (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>)</p>
  1092.  
  1093.         <p>Otherwise:</p>
  1094.  
  1095.         <p class="big-issue">this needs to handle closing of implied elements,
  1096.          but without closing them</p>
  1097.  
  1098.         <p>If the <a href="#current4">current node</a> is not the <code><a href="section-sections.html#body0">body</a></code> element, then this is a <a href="section-parsing.html#parse">parse error</a>.</p>
  1099.  
  1100.         <p>Change the <a href="#insertion0">insertion mode</a> to &quot;<a href="#after2" title="insertion mode: after body">after body</a>&quot;.</p>
  1101.  
  1102.        </dd><dt>An end tag with the tag name &quot;html&quot;
  1103.  
  1104.        </dt><dd>
  1105.         <p>Act as if an end tag with tag name &quot;body&quot; had been seen, then, if
  1106.          that token wasn't ignored, reprocess the current token.</p>
  1107.  
  1108.        <p class="note">The fake end tag token here can only be ignored in the
  1109.         <a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>.</p>
  1110.  
  1111.       </dd><dt>A start tag whose tag name is one of: &quot;address&quot;, &quot;blockquote&quot;,
  1112.        &quot;center&quot;, &quot;dir&quot;, &quot;div&quot;, &quot;dl&quot;, &quot;fieldset&quot;, &quot;listing&quot;, &quot;menu&quot;, &quot;ol&quot;,
  1113.        &quot;p&quot;, &quot;ul&quot;
  1114.  
  1115.       </dt><dd>
  1116.        <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an" title="has an element in scope">has a <code>p</code>
  1117.         element in scope</a>, then act as if an end tag with the tag name
  1118.         <code><a href="section-prose.html#p">p</a></code> had been seen.</p>
  1119.  
  1120.        <p><a href="#insert" title="insert an html element">Insert an HTML
  1121.         element</a> for the token.</p>
  1122.  
  1123.       </dd><dt>A start tag whose tag name is &quot;pre&quot;
  1124.  
  1125.       </dt><dd>
  1126.        <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an" title="has an element in scope">has a <code>p</code>
  1127.         element in scope</a>, then act as if an end tag with the tag name
  1128.         <code><a href="section-prose.html#p">p</a></code> had been seen.</p>
  1129.  
  1130.        <p><a href="#insert" title="insert an html element">Insert an HTML
  1131.         element</a> for the token.</p>
  1132.  
  1133.        <p>If the next token is a U+000A LINE FEED (LF) character token, then
  1134.         ignore that token and move on to the next one. (Newlines at the
  1135.         start of <code><a href="section-preformatted.html#pre">pre</a></code> blocks are ignored as
  1136.         an authoring convenience.)</p>
  1137.  
  1138.       </dd><dt>A start tag whose tag name is &quot;form&quot;
  1139.  
  1140.       </dt><dd>
  1141.        <p>If the <a href="#form-element"><code title="form">form</code>
  1142.         element pointer</a> is not null, ignore the token with a <a href="section-parsing.html#parse">parse error</a>.</p>
  1143.  
  1144.        <p>Otherwise:</p>
  1145.  
  1146.        <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an" title="has an element in scope">has a <code>p</code>
  1147.         element in scope</a>, then act as if an end tag with the tag name
  1148.         <code><a href="section-prose.html#p">p</a></code> had been seen.</p>
  1149.  
  1150.        <p><a href="#insert" title="insert an html Element">Insert an HTML
  1151.         element</a> for the token, and set the <code title="form">form</code>
  1152.         element pointer to point to the element created.</p>
  1153.  
  1154.       </dd><dt>A start tag whose tag name is &quot;li&quot;
  1155.  
  1156.       </dt><dd>
  1157.        <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an" title="has an element in scope">has a <code>p</code>
  1158.         element in scope</a>, then act as if an end tag with the tag name
  1159.         <code><a href="section-prose.html#p">p</a></code> had been seen.</p>
  1160.  
  1161.        <p>Run the following algorithm:</p>
  1162.  
  1163.        <ol>
  1164.         <li>
  1165.          <p>Initialise <var title="">node</var> to be the <a href="#current4">current node</a> (the bottommost node of the
  1166.           stack).
  1167.  
  1168.         </p></li><li>
  1169.          <p>If <var title="">node</var> is an <code><a href="section-lists0.html#li">li</a></code> element, then pop all the nodes from the
  1170.           <a href="#current4">current node</a> up to <var title="">node</var>, including <var title="">node</var>, then stop
  1171.           this algorithm. If more than one node is popped, then this is a <a href="section-parsing.html#parse">parse error</a>.
  1172.  
  1173.         </p></li><li>
  1174.          <p>If <var title="">node</var> is not in the <a href="#formatting">formatting</a> category, and is not in the <a href="#phrasing">phrasing</a> category, and is not an <code><a href="section-sections.html#address">address</a></code> or <code><a href="section-miscellaneous.html#div">div</a></code> element, then stop this algorithm.
  1175.         </p></li>
  1176.         <!-- an element <foo> is in this
  1177.         list if the following markup:
  1178.  
  1179.             <!DOCTYPE html><body><ol><li><foo><li>
  1180.  
  1181.         ...results in the second <li> not being (in any way) a
  1182.         descendant of the first <li>, or if <foo> is a formatting
  1183.         element that gets reopened later. -->
  1184.  
  1185.         <li>
  1186.          <p>Otherwise, set <var title="">node</var> to the previous entry in
  1187.           the <a href="#stack">stack of open elements</a> and return to step
  1188.           2.
  1189.        </p></li></ol>
  1190.  
  1191.        <p>Finally, <a href="#insert" title="insert an html element">insert
  1192.         an <code>li</code> element</a>.</p>
  1193.  
  1194.       </dd><dt>A start tag whose tag name is &quot;dd&quot; or &quot;dt&quot;
  1195.  
  1196.       </dt><dd>
  1197.        <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an" title="has an element in scope">has a <code>p</code>
  1198.         element in scope</a>, then act as if an end tag with the tag name
  1199.         <code><a href="section-prose.html#p">p</a></code> had been seen.</p>
  1200.  
  1201.        <p>Run the following algorithm:</p>
  1202.  
  1203.        <ol>
  1204.         <li>
  1205.          <p>Initialise <var title="">node</var> to be the <a href="#current4">current node</a> (the bottommost node of the
  1206.           stack).
  1207.  
  1208.         </p></li><li>
  1209.          <p>If <var title="">node</var> is a <code><a href="section-lists0.html#dd">dd</a></code> or <code><a href="section-lists0.html#dt">dt</a></code>
  1210.           element, then pop all the nodes from the <a href="#current4">current node</a> up to <var title="">node</var>,
  1211.           including <var title="">node</var>, then stop this algorithm. If
  1212.           more than one node is popped, then this is a <a href="section-parsing.html#parse">parse error</a>.
  1213.  
  1214.         </p></li><li>
  1215.          <p>If <var title="">node</var> is not in the <a href="#formatting">formatting</a> category, and is not in the <a href="#phrasing">phrasing</a> category, and is not an <code><a href="section-sections.html#address">address</a></code> or <code><a href="section-miscellaneous.html#div">div</a></code> element, then stop this algorithm.
  1216.         </p></li>
  1217.         <!-- an element <foo> is in this
  1218.         list if the following markup:
  1219.  
  1220.             <!DOCTYPE html><body><ol><dt><foo><dt>
  1221.  
  1222.         ...results in the second <li> not being (in any way) a
  1223.         descendant of the first <li>, or if <foo> is a formatting
  1224.         element that gets reopened later. -->
  1225.  
  1226.         <li>
  1227.          <p>Otherwise, set <var title="">node</var> to the previous entry in
  1228.           the <a href="#stack">stack of open elements</a> and return to step
  1229.           2.
  1230.        </p></li></ol>
  1231.  
  1232.        <p>Finally, <a href="#insert" title="insert an html element">insert
  1233.         an HTML element</a> with the same tag name as the token's.</p>
  1234.  
  1235.        </dd><dt>A start tag token whose tag name is &quot;plaintext&quot;
  1236.  
  1237.        </dt><dd>
  1238.         <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an" title="has an element in scope">has a <code>p</code>
  1239.          element in scope</a>, then act as if an end tag with the tag name
  1240.          <code><a href="section-prose.html#p">p</a></code> had been seen.</p>
  1241.  
  1242.         <p><a href="#insert" title="insert an html element">Insert an HTML
  1243.          element</a> for the token.</p>
  1244.  
  1245.         <p>Switch the <a href="section-tokenisation.html#content2">content model flag</a> to the
  1246.          PLAINTEXT state.</p>
  1247.  
  1248.         <p class="note">Once a start tag with the tag name &quot;plaintext&quot; has been
  1249.          seen, that will be the last token ever seen other than character
  1250.          tokens (and the end-of-file token), because there is no way to
  1251.          switch the <a href="section-tokenisation.html#content2">content model flag</a> out of the
  1252.          PLAINTEXT state.</p>
  1253.  
  1254.        </dd><dt>An end tag whose tag name is one of: &quot;address&quot;, &quot;blockquote&quot;,
  1255.         &quot;center&quot;, &quot;dir&quot;, &quot;div&quot;, &quot;dl&quot;, &quot;fieldset&quot;, &quot;listing&quot;, &quot;menu&quot;, &quot;ol&quot;,
  1256.         &quot;pre&quot;, &quot;ul&quot;
  1257.  
  1258.        </dt><dd>
  1259.         <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an">has an element in scope</a> with the same tag name
  1260.          as that of the token, then <a href="#generate">generate implied end
  1261.          tags</a>.</p>
  1262.  
  1263.         <p>Now, if the <a href="#current4">current node</a> is not an element
  1264.          with the same tag name as that of the token, then this is a <a href="section-parsing.html#parse">parse error</a>.</p>
  1265.  
  1266.         <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an">has an element in scope</a> with the same tag name
  1267.          as that of the token, then pop elements from this stack until an
  1268.          element with that tag name has been popped from the stack.</p>
  1269.         <!-- XXX quirk (except for in certain cases?):
  1270.         <p>Otherwise, act as if a start tag with the tag name given in
  1271.         the token had been seen, then reprocess the current token.</p>
  1272.         -->
  1273.        
  1274.  
  1275.        </dd><dt>An end tag whose tag name is &quot;form&quot;
  1276.  
  1277.        </dt><dd>
  1278.         <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an">has an element in scope</a> with the same tag name
  1279.          as that of the token, then <a href="#generate">generate implied end
  1280.          tags</a>.</p>
  1281.  
  1282.         <p>Now, if the <a href="#current4">current node</a> is not an element
  1283.          with the same tag name as that of the token, then this is a <a href="section-parsing.html#parse">parse error</a>.</p>
  1284.  
  1285.         <p>Otherwise, if the <a href="#current4">current node</a> is an
  1286.          element with the same tag name as that of the token pop that element
  1287.          from the stack.</p>
  1288.  
  1289.         <p>In any case, set the <a href="#form-element"><code title="">form</code> element pointer</a> to null.</p>
  1290.  
  1291.        </dd><dt>An end tag whose tag name is &quot;p&quot;
  1292.  
  1293.        </dt><dd>
  1294.         <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an" title="has an element in scope">has a <code>p</code>
  1295.          element in scope</a>, then <a href="#generate">generate implied end
  1296.          tags</a>, except for <code><a href="section-prose.html#p">p</a></code> elements.</p>
  1297.  
  1298.         <p>If the <a href="#current4">current node</a> is not a <code><a href="section-prose.html#p">p</a></code> element, then this is a <a href="section-parsing.html#parse">parse error</a>.</p>
  1299.  
  1300.         <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an" title="has an element in scope">has a <code>p</code>
  1301.          element in scope</a>, then pop elements from this stack until the
  1302.          stack no longer <a href="#have-an" title="has an element in
  1303.         scope">has a <code>p</code> element in scope</a>.</p>
  1304.         <!-- XXX quirk:
  1305.         <p>Otherwise, act as if a start tag with the tag name
  1306.         <code>p</code> had been seen, then reprocess the current
  1307.         token.</p>
  1308.         -->
  1309.        
  1310.  
  1311.        </dd><dt>An end tag whose tag name is &quot;dd&quot;, &quot;dt&quot;, or &quot;li&quot;
  1312.  
  1313.        </dt><dd>
  1314.         <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an">has an element in scope</a> whose tag name matches
  1315.          the tag name of the token, then <a href="#generate">generate implied
  1316.          end tags</a>, except for elements with the same tag name as the
  1317.          token.</p>
  1318.  
  1319.         <p>If the <a href="#current4">current node</a> is not an element with
  1320.          the same tag name as the token, then this is a <a href="section-parsing.html#parse">parse error</a>.</p>
  1321.  
  1322.         <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an">has an element in scope</a> whose tag name matches
  1323.          the tag name of the token, then pop elements from this stack until
  1324.          an element with that tag name has been popped from the stack.</p>
  1325.  
  1326.        </dd><dt>A start tag whose tag name is one of: &quot;h1&quot;, &quot;h2&quot;, &quot;h3&quot;, &quot;h4&quot;,
  1327.         &quot;h5&quot;, &quot;h6&quot;
  1328.  
  1329.        </dt><dd>
  1330.         <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an" title="has an element in scope">has a <code>p</code>
  1331.          element in scope</a>, then act as if an end tag with the tag name
  1332.          <code><a href="section-prose.html#p">p</a></code> had been seen.</p>
  1333.  
  1334.         <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an" title="has an element in scope">has in scope</a> an
  1335.          element whose tag name is one of &quot;h1&quot;, &quot;h2&quot;, &quot;h3&quot;, &quot;h4&quot;, &quot;h5&quot;, or
  1336.          &quot;h6&quot;, then this is a <a href="section-parsing.html#parse">parse error</a>; pop elements
  1337.          from the stack until an element with one of those tag names has been
  1338.          popped from the stack.</p>
  1339.  
  1340.         <p><a href="#insert" title="insert an html element">Insert an HTML
  1341.          element</a> for the token.</p>
  1342.  
  1343.        </dd><dt>An end tag whose tag name is one of: &quot;h1&quot;, &quot;h2&quot;, &quot;h3&quot;, &quot;h4&quot;, &quot;h5&quot;,
  1344.         &quot;h6&quot;
  1345.  
  1346.        </dt><dd>
  1347.         <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an" title="has an element in scope">has in scope</a> an
  1348.          element whose tag name is one of &quot;h1&quot;, &quot;h2&quot;, &quot;h3&quot;, &quot;h4&quot;, &quot;h5&quot;, or
  1349.          &quot;h6&quot;, then <a href="#generate">generate implied end tags</a>.</p>
  1350.  
  1351.         <p>Now, if the <a href="#current4">current node</a> is not an element
  1352.          with the same tag name as that of the token, then this is a <a href="section-parsing.html#parse">parse error</a>.</p>
  1353.  
  1354.         <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an" title="has an element in scope">has in scope</a> an
  1355.          element whose tag name is one of &quot;h1&quot;, &quot;h2&quot;, &quot;h3&quot;, &quot;h4&quot;, &quot;h5&quot;, or
  1356.          &quot;h6&quot;, then pop elements from the stack until an element with one of
  1357.          those tag names has been popped from the stack.</p>
  1358.         <!-- XXX quirk:
  1359.         <p>Otherwise, act as if a start tag with the tag name given in
  1360.         the token had been seen, then reprocess the current token.</p>
  1361.         -->
  1362.         </dd>
  1363.        <!-- ADOPTION AGENCY ELEMENTS
  1364.             Mozilla-only: bdo blink del ins sub sup q
  1365.             Safari-only: code dfn kbd nobr samp var wbr
  1366.             Both: a b big em font i s small strike strong tt u -->
  1367.  
  1368.        <dt>A start tag whose tag name is &quot;a&quot;
  1369.  
  1370.        </dt><dd>
  1371.         <p>If the <a href="#list-of4">list of active formatting elements</a>
  1372.          contains an element whose tag name is &quot;a&quot; between the end of the
  1373.          list and the last marker on the list (or the start of the list if
  1374.          there is no marker on the list), then this is a <a href="section-parsing.html#parse">parse error</a>; act as if an end tag with the tag
  1375.          name &quot;a&quot; had been seen, then remove that element from the <a href="#list-of4">list of active formatting elements</a> and the <a href="#stack">stack of open elements</a> if the end tag didn't
  1376.         already remove it (it might not have if the element is not <a href="#have-an0" title="has an element in table scope">in table
  1377.         scope</a>).</p>
  1378.  
  1379.        <p class="example">In the non-conforming stream
  1380.         <code>&lt;a href=&quot;a&quot;&gt;a&lt;table&gt;&lt;a href=&quot;b&quot;&gt;b&lt;/table&gt;x</code>,
  1381.         the first <code><a href="section-phrase.html#a">a</a></code> element would be closed
  1382.         upon seeing the second one, and the &quot;x&quot; character would be inside a
  1383.         link to &quot;b&quot;, not to &quot;a&quot;. This is despite the fact that the outer
  1384.         <code><a href="section-phrase.html#a">a</a></code> element is not in table scope
  1385.         (meaning that a regular <code>&lt;/a&gt;</code> end tag at the start of
  1386.         the table wouldn't close the outer <code><a href="section-phrase.html#a">a</a></code>
  1387.          element).</p>
  1388.  
  1389.         <p><a href="#reconstruct">Reconstruct the active formatting
  1390.          elements</a>, if any.</p>
  1391.  
  1392.         <p><a href="#insert" title="insert an html element">Insert an HTML
  1393.          element</a> for the token. Add that element to the <a href="#list-of4">list of active formatting elements</a>.</p>
  1394.  
  1395.        </dd><dt>A start tag whose tag name is one of: &quot;b&quot;, &quot;big&quot;, &quot;em&quot;, &quot;font&quot;,
  1396.         &quot;i&quot;, &quot;nobr&quot;, &quot;s&quot;, &quot;small&quot;, &quot;strike&quot;, &quot;strong&quot;, &quot;tt&quot;, &quot;u&quot;
  1397.  
  1398.        </dt><dd>
  1399.         <p><a href="#reconstruct">Reconstruct the active formatting
  1400.          elements</a>, if any.</p>
  1401.  
  1402.         <p><a href="#insert" title="insert an html element">Insert an HTML
  1403.          element</a> for the token. Add that element to the <a href="#list-of4">list of active formatting elements</a>.</p>
  1404.  
  1405.        </dd><dt id="adoptionAgency">An end tag whose tag name is one of: &quot;a&quot;, &quot;b&quot;,
  1406.         &quot;big&quot;, &quot;em&quot;, &quot;font&quot;, &quot;i&quot;, &quot;nobr&quot;, &quot;s&quot;, &quot;small&quot;, &quot;strike&quot;, &quot;strong&quot;,
  1407.         &quot;tt&quot;, &quot;u&quot;
  1408.  
  1409.        </dt><dd>
  1410.         <p>Follow these steps:</p>
  1411.  
  1412.         <ol>
  1413.          <li>
  1414.           <p>Let the <var title="">formatting element</var> be the last
  1415.            element in the <a href="#list-of4">list of active formatting
  1416.            elements</a> that:</p>
  1417.  
  1418.           <ul>
  1419.            <li>is between the end of the list and the last scope marker in
  1420.             the list, if any, or the start of the list otherwise, and
  1421.  
  1422.            </li><li>has the same tag name as the token.
  1423.           </li></ul>
  1424.  
  1425.           <p>If there is no such node, or, if that node is also in the <a href="#stack">stack of open elements</a> but the element is not <a href="#have-an" title="has an element in scope">in scope</a>, then
  1426.            this is a <a href="section-parsing.html#parse">parse error</a>. Abort these steps. The
  1427.            token is ignored.</p>
  1428.  
  1429.           <p>Otherwise, if there is such a node, but that node is not in the
  1430.            <a href="#stack">stack of open elements</a>, then this is a <a href="section-parsing.html#parse">parse error</a>; remove the element from the list,
  1431.            and abort these steps.</p>
  1432.  
  1433.           <p>Otherwise, there is a <var title="">formatting element</var> and
  1434.            that element is in <a href="#stack" title="stack of open
  1435.           elements">the stack</a> and is <a href="#have-an" title="has an
  1436.           element in scope">in scope</a>. If the element is not the <a href="#current4">current node</a>, this is a <a href="section-parsing.html#parse">parse error</a>. In any case, proceed with the
  1437.            algorithm as written in the following steps.</p>
  1438.  
  1439.          </li><li>
  1440.           <p>Let the <var title="">furthest block</var> be the topmost node
  1441.            in the <a href="#stack">stack of open elements</a> that is lower
  1442.            in the stack than the <var title="">formatting element</var>, and
  1443.            is not an element in the <a href="#phrasing">phrasing</a> or <a href="#formatting">formatting</a> categories. There might not be
  1444.            one.
  1445.  
  1446.          </p></li><li>
  1447.           <p>If there is no <var title="">furthest block</var>, then the UA
  1448.            must skip the subsequent steps and instead just pop all the nodes
  1449.            from the bottom of the <a href="#stack">stack of open
  1450.            elements</a>, from the <a href="#current4">current node</a> up to
  1451.            the <var title="">formatting element</var>, and remove the <var title="">formatting element</var> from the <a href="#list-of4">list of active formatting elements</a>.
  1452.  
  1453.          </p></li><li>
  1454.           <p>Let the <var title="">common ancestor</var> be the element
  1455.            immediately above the <var title="">formatting element</var> in
  1456.            the <a href="#stack">stack of open elements</a>.
  1457.  
  1458.          </p></li><li>
  1459.           <p>If the <var title="">furthest block</var> has a parent node,
  1460.            then remove the <var title="">furthest block</var> from its parent
  1461.            node.
  1462.  
  1463.          </p></li><li>
  1464.           <p>Let a bookmark note the position of the <var title="">formatting
  1465.            element</var> in the <a href="#list-of4">list of active formatting
  1466.            elements</a> relative to the elements on either side of it in the
  1467.            list.
  1468.  
  1469.          </p></li><li>
  1470.           <p>Let <var title="">node</var> and <var title="">last node</var>
  1471.            be the <var title="">furthest block</var>. Follow these steps:</p>
  1472.  
  1473.           <ol>
  1474.            <li>Let <var title="">node</var> be the element immediately prior
  1475.             to <var title="">node</var> in the <a href="#stack">stack of open
  1476.             elements</a>.
  1477.  
  1478.            </li><li>If <var title="">node</var> is not in the <a href="#list-of4">list of active formatting elements</a>, then
  1479.             remove <var title="">node</var> from the <a href="#stack">stack
  1480.             of open elements</a> and then go back to step 1.
  1481.  
  1482.            </li><li>Otherwise, if <var title="">node</var> is the <var title="">formatting element</var>, then go to the next step in
  1483.             the overall algorithm.
  1484.  
  1485.            </li><li>Otherwise, if <var title="">last node</var> is the <var title="">furthest block</var>, then move the aforementioned
  1486.             bookmark to be immediately after the <var title="">node</var> in
  1487.             the <a href="#list-of4">list of active formatting elements</a>.
  1488.  
  1489.            </li><li>If <var title="">node</var> has any children, perform a
  1490.             shallow clone of <var title="">node</var>, replace the entry for
  1491.             <var title="">node</var> in the <a href="#list-of4">list of
  1492.             active formatting elements</a> with an entry for the clone,
  1493.             replace the entry for <var title="">node</var> in the <a href="#stack">stack of open elements</a> with an entry for the
  1494.             clone, and let <var title="">node</var> be the clone.
  1495.  
  1496.            </li><li>Insert <var title="">last node</var> into <var title="">node</var>, first removing it from its previous parent
  1497.             node if any.
  1498.  
  1499.            </li><li>Let <var title="">last node</var> be <var title="">node</var>.
  1500.  
  1501.            </li><li>Return to step 1 of this inner set of steps.
  1502.           </li></ol>
  1503.  
  1504.          </li><li>
  1505.           <p>Insert whatever <var title="">last node</var> ended up being in
  1506.            the previous step into the <var title="">common ancestor</var>
  1507.            node, first removing it from its previous parent node if any.
  1508.  
  1509.          </p></li><li>
  1510.           <p>Perform a shallow clone of the <var title="">formatting
  1511.            element</var>.
  1512.  
  1513.          </p></li><li>
  1514.           <p>Take all of the child nodes of the <var title="">furthest
  1515.            block</var> and append them to the clone created in the last step.
  1516.  
  1517.          </p></li><li>
  1518.           <p>Append that clone to the <var title="">furthest block</var>.
  1519.  
  1520.          </p></li><li>
  1521.           <p>Remove the <var title="">formatting element</var> from the <a href="#list-of4">list of active formatting elements</a>, and
  1522.            insert the clone into the <a href="#list-of4">list of active
  1523.            formatting elements</a> at the position of the aforementioned
  1524.            bookmark.
  1525.  
  1526.          </p></li><li>
  1527.           <p>Remove the <var title="">formatting element</var> from the <a href="#stack">stack of open elements</a>, and insert the clone
  1528.            into the <a href="#stack">stack of open elements</a> immediately
  1529.            after (i.e. in a more deeply nested position than) the position of
  1530.            the <var title="">furthest block</var> in that stack.
  1531.  
  1532.          </p></li><li>
  1533.           <p>Jump back to step 1 in this series of steps.
  1534.         </p></li></ol>
  1535.  
  1536.         <p class="note">The way these steps are defined, only elements in the
  1537.          <a href="#formatting">formatting</a> category ever get cloned by
  1538.          this algorithm.</p>
  1539.         <!--XXX
  1540.         <div class="example">
  1541.          <p class="big-issue">Need an example.</p>
  1542.         </div>
  1543. -->
  1544.        
  1545.         <p class="note">Because of the way this algorithm causes elements to
  1546.          change parents, it has been dubbed the &quot;adoption agency algorithm&quot;
  1547.          (in contrast with other possibly algorithms for dealing with
  1548.          misnested content, which included the &quot;incest algorithm&quot;, the
  1549.          &quot;secret affair algorithm&quot;, and the &quot;Heisenberg algorithm&quot;).</p>
  1550.  
  1551.        </dd><dt>A start tag token whose tag name is &quot;button&quot;
  1552.  
  1553.        </dt><dd>
  1554.         <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an" title="has an element in scope">has a
  1555.          <code>button</code> element in scope</a>, then this is a <a href="section-parsing.html#parse">parse error</a>; act as if an end tag with the tag
  1556.          name &quot;button&quot; had been seen, then reprocess the token.</p>
  1557.  
  1558.         <p>Otherwise:</p>
  1559.  
  1560.         <p><a href="#reconstruct">Reconstruct the active formatting
  1561.          elements</a>, if any.</p>
  1562.  
  1563.         <p><a href="#insert">Insert an HTML element</a> for the token.</p>
  1564.  
  1565.         <p>Insert a marker at the end of the <a href="#list-of4">list of
  1566.          active formatting elements</a>.</p>
  1567.  
  1568.        </dd><dt>A start tag token whose tag name is one of: &quot;marquee&quot;, &quot;object&quot;
  1569.  
  1570.        </dt><dd>
  1571.         <p><a href="#reconstruct">Reconstruct the active formatting
  1572.          elements</a>, if any.</p>
  1573.  
  1574.         <p><a href="#insert">Insert an HTML element</a> for the token.</p>
  1575.  
  1576.         <p>Insert a marker at the end of the <a href="#list-of4">list of
  1577.          active formatting elements</a>.</p>
  1578.  
  1579.        </dd><dt>An end tag token whose tag name is one of: &quot;button&quot;, &quot;marquee&quot;,
  1580.         &quot;object&quot;
  1581.  
  1582.        </dt><dd>
  1583.         <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an" title="has an element in scope">has in scope</a> an
  1584.          element whose tag name is the same as the tag name of the token,
  1585.          then <a href="#generate">generate implied end tags</a>.</p>
  1586.  
  1587.         <p>Now, if the <a href="#current4">current node</a> is not an element
  1588.          with the same tag name as the token, then this is a <a href="section-parsing.html#parse">parse error</a>.</p>
  1589.  
  1590.         <p>Now, if the <a href="#stack">stack of open elements</a> <a href="#have-an">has an element in scope</a> whose tag name matches
  1591.          the tag name of the token, then pop elements from the stack until
  1592.          that element has been popped from the stack, and <a href="#clear0">clear the list of active formatting elements up to
  1593.          the last marker</a>.</p>
  1594.  
  1595.        </dd><dt>A start tag token whose tag name is &quot;xmp&quot;
  1596.  
  1597.        </dt><dd>
  1598.         <p><a href="#reconstruct">Reconstruct the active formatting
  1599.          elements</a>, if any.</p>
  1600.  
  1601.         <p><a href="#insert">Insert an HTML element</a> for the token.</p>
  1602.  
  1603.         <p>Switch the <a href="section-tokenisation.html#content2">content model flag</a> to the CDATA
  1604.          state.</p>
  1605.  
  1606.        </dd><dt>A start tag whose tag name is &quot;table&quot;
  1607.  
  1608.        </dt><dd>
  1609.         <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an" title="has an element in scope">has a <code>p</code>
  1610.          element in scope</a>, then act as if an end tag with the tag name
  1611.          <code><a href="section-prose.html#p">p</a></code> had been seen.</p>
  1612.         <!-- XXX quirks: don't do this -->
  1613.        <p><a href="#insert">Insert an HTML element</a> for the token.</p>
  1614.  
  1615.        <p>Change the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-table" title="insertion mode: in table">in table</a>&quot;.</p>
  1616.  
  1617.       </dd><dt>A start tag whose tag name is one of: &quot;area&quot;, &quot;basefont&quot;,
  1618.        &quot;bgsound&quot;, &quot;br&quot;, &quot;embed&quot;, &quot;img&quot;, &quot;param&quot;, &quot;spacer&quot;, &quot;wbr&quot;
  1619.  
  1620.       </dt><dd>
  1621.        <p><a href="#reconstruct">Reconstruct the active formatting
  1622.         elements</a>, if any.</p>
  1623.  
  1624.        <p><a href="#insert" title="insert an html element">Insert an HTML
  1625.         element</a> for the token. Immediately pop the <a href="#current4">current node</a> off the <a href="#stack">stack of
  1626.         open elements</a>.</p>
  1627.  
  1628.       </dd><dt>A start tag whose tag name is &quot;hr&quot;
  1629.  
  1630.       </dt><dd>
  1631.        <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an" title="has an element in scope">has a <code>p</code>
  1632.         element in scope</a>, then act as if an end tag with the tag name
  1633.         <code><a href="section-prose.html#p">p</a></code> had been seen.</p>
  1634.        <!-- XXX quirks: don't do this -->
  1635.         <p><a href="#insert" title="insert an html element">Insert an HTML
  1636.          element</a> for the token. Immediately pop the <a href="#current4">current node</a> off the <a href="#stack">stack of
  1637.          open elements</a>.</p>
  1638.  
  1639.        </dd><dt>A start tag whose tag name is &quot;image&quot;
  1640.  
  1641.        </dt><dd>
  1642.         <p><a href="section-parsing.html#parse">Parse error</a>. Change the token's tag name to
  1643.         &quot;img&quot; and reprocess it. (Don't ask.)</p>
  1644.         <!-- As of
  1645.         2005-12, studies showed that around 0.2% of pages used the
  1646.         <image> element. -->
  1647.        
  1648.  
  1649.        </dd><dt>A start tag whose tag name is &quot;input&quot;
  1650.  
  1651.        </dt><dd>
  1652.         <p><a href="#reconstruct">Reconstruct the active formatting
  1653.          elements</a>, if any.</p>
  1654.  
  1655.         <p><a href="#insert" title="insert an html element">Insert an
  1656.          <code>input</code> element</a> for the token.</p>
  1657.  
  1658.         <p>If the <a href="#form-element"><code title="">form</code> element
  1659.          pointer</a> is not null, then <span>associate</span><!--XXX
  1660.         xref! -->
  1661.          the <code>input</code> element with the <code>form</code> element
  1662.          pointed to by the <a href="#form-element"><code title="">form</code>
  1663.          element pointer</a>.</p>
  1664.  
  1665.         <p>Pop that <code>input</code> element off the <a href="#stack">stack
  1666.          of open elements</a>.</p>
  1667.  
  1668.        </dd><dt id="isindex">A start tag whose tag name is &quot;isindex&quot;
  1669.  
  1670.        </dt><dd>
  1671.         <p><a href="section-parsing.html#parse">Parse error</a>.</p>
  1672.  
  1673.         <p>If the <a href="#form-element"><code title="">form</code> element
  1674.          pointer</a> is not null, then ignore the token.</p>
  1675.  
  1676.         <p>Otherwise:</p>
  1677.  
  1678.         <p>Act as if a start tag token with the tag name &quot;form&quot; had been
  1679.          seen.</p>
  1680.  
  1681.         <p>Act as if a start tag token with the tag name &quot;hr&quot; had been seen.</p>
  1682.  
  1683.         <p>Act as if a start tag token with the tag name &quot;p&quot; had been seen.</p>
  1684.  
  1685.         <p>Act as if a start tag token with the tag name &quot;label&quot; had been
  1686.          seen.</p>
  1687.  
  1688.         <p>Act as if a stream of character tokens had been seen (see below
  1689.          for what they should say).</p>
  1690.  
  1691.         <p>Act as if a start tag token with the tag name &quot;input&quot; had been
  1692.          seen, with all the attributes from the &quot;isindex&quot; token, except with
  1693.          the &quot;name&quot; attribute set to the value &quot;isindex&quot; (ignoring any
  1694.          explicit &quot;name&quot; attribute).</p>
  1695.  
  1696.         <p>Act as if a stream of character tokens had been seen (see below
  1697.          for what they should say).</p>
  1698.  
  1699.         <p>Act as if an end tag token with the tag name &quot;label&quot; had been
  1700.          seen.</p>
  1701.  
  1702.         <p>Act as if an end tag token with the tag name &quot;p&quot; had been seen.</p>
  1703.  
  1704.         <p>Act as if a start tag token with the tag name &quot;hr&quot; had been seen.</p>
  1705.  
  1706.         <p>Act as if an end tag token with the tag name &quot;form&quot; had been seen.</p>
  1707.  
  1708.         <p>The two streams of character tokens together should, together with
  1709.          the <code>input</code> element, express the equivalent of &quot;This is a
  1710.          searchable index. Insert your search keywords here: (input field)&quot;
  1711.          in the user's preferred language.</p>
  1712.  
  1713.        <p class="big-issue"> Then need to specify that if the form submission
  1714.         causes just a single form control, whose name is &quot;isindex&quot;, to be
  1715.         submitted, then we submit just the value part, not the &quot;isindex=&quot;
  1716.         part.</p>
  1717.       </dd>
  1718.       <!-- XXX keygen support; don't forget form element pointer!
  1719.  
  1720.        <dt>A start tag whose tag name is "keygen"</dt>
  1721.        <dd>
  1722.         ...
  1723.        </dd>
  1724. -->
  1725.  
  1726.        <dt>A start tag whose tag name is &quot;textarea&quot;
  1727.  
  1728.        </dt><dd>
  1729.         <p><a href="#create">Create an element for the token</a>.</p>
  1730.  
  1731.         <p>If the <a href="#form-element"><code title="">form</code> element
  1732.          pointer</a> is not null, then <span>associate</span><!--XXX
  1733.         xref! -->
  1734.          the <code>textarea</code> element with the <code>form</code> element
  1735.          pointed to by the <a href="#form-element"><code title="">form</code>
  1736.          element pointer</a>.</p>
  1737.  
  1738.         <p>Append the new element to the <a href="#current4">current
  1739.          node</a>.</p>
  1740.  
  1741.         <p>Switch the tokeniser's <a href="section-tokenisation.html#content2">content model flag</a>
  1742.         to the RCDATA state.</p>
  1743.  
  1744.        <p>If the next token is a U+000A LINE FEED (LF) character token, then
  1745.         ignore that token and move on to the next one. (Newlines at the
  1746.         start of <code>textarea</code> elements are ignored as an authoring
  1747.         convenience.)</p>
  1748.  
  1749.        <p>Then, collect all the character tokens that the tokeniser returns
  1750.         until it returns a token that is not a character token, or until it
  1751.         stops tokenising.</p>
  1752.  
  1753.        <p>If this process resulted in a collection of character tokens,
  1754.         append a single <code>Text</code> node, whose contents is the
  1755.         concatenation of all those tokens' characters, to the new element
  1756.          node.</p>
  1757.  
  1758.         <p>The tokeniser's <a href="section-tokenisation.html#content2">content model flag</a> will
  1759.         have switched back to the PCDATA state.</p>
  1760.  
  1761.        <p>If the next token is an end tag token with the tag name
  1762.         &quot;textarea&quot;, ignore it. Otherwise, this is a <a href="section-parsing.html#parse">parse
  1763.         error</a>.</p>
  1764.  
  1765.       </dd><dt>A start tag whose tag name is one of: &quot;iframe&quot;, &quot;noembed&quot;,
  1766.        &quot;noframes&quot;
  1767.  
  1768.       </dt><dt>A start tag whose tag name is &quot;noscript&quot;, if <a href="section-scripting.html#scripting2">scripting is enabled</a>:
  1769.  
  1770.       </dt><dd>
  1771.        <p><a href="#create">Create an element for the token</a>.</p>
  1772.  
  1773.        <p>For &quot;iframe&quot; tags, the node must be an <code><a href="section-embedded.html#htmliframeelement">HTMLIFrameElement</a></code> object, for
  1774.         the other tags it must be an <code><a href="section-elements.html#htmlelement">HTMLElement</a></code> object.</p>
  1775.  
  1776.        <p>Append the new element to the <a href="#current4">current
  1777.         node</a>.</p>
  1778.  
  1779.        <p>Switch the tokeniser's <a href="section-tokenisation.html#content2">content model flag</a>
  1780.          to the CDATA state.</p>
  1781.  
  1782.         <p>Then, collect all the character tokens that the tokeniser returns
  1783.          until it returns a token that is not a character token, or until it
  1784.          stops tokenising.</p>
  1785.  
  1786.         <p>If this process resulted in a collection of character tokens,
  1787.          append a single <code>Text</code> node, whose contents is the
  1788.          concatenation of all those tokens' characters, to the new element
  1789.         node.</p>
  1790.  
  1791.        <p>The tokeniser's <a href="section-tokenisation.html#content2">content model flag</a> will
  1792.          have switched back to the PCDATA state.</p>
  1793.  
  1794.         <p>If the next token is an end tag token with the same tag name as
  1795.          the start tag token, ignore it. Otherwise, this is a <a href="section-parsing.html#parse">parse error</a>.</p>
  1796.  
  1797.        </dd><dt>A start tag whose tag name is &quot;select&quot;
  1798.  
  1799.        </dt><dd>
  1800.         <p><a href="#reconstruct">Reconstruct the active formatting
  1801.          elements</a>, if any.</p>
  1802.  
  1803.         <p><a href="#insert">Insert an HTML element</a> for the token.</p>
  1804.  
  1805.         <p>Change the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-select" title="insertion mode: in select">in select</a>&quot;.</p>
  1806.        </dd>
  1807.        <!-- XXX quirks:
  1808.        <dt>An end tag whose tag name is "br"</dt>
  1809.        <dd>
  1810.         <p>Act as if a start tag token with the tag name "br" had been
  1811.         seen. Ignore the end tag token.</p>
  1812.        </dd>
  1813. -->
  1814.  
  1815.        <dt>A start or end tag whose tag name is one of: &quot;caption&quot;, &quot;col&quot;,
  1816.         &quot;colgroup&quot;, &quot;frame&quot;, &quot;frameset&quot;, &quot;head&quot;, &quot;option&quot;, &quot;optgroup&quot;,
  1817.         &quot;tbody&quot;, &quot;td&quot;, &quot;tfoot&quot;, &quot;th&quot;, &quot;thead&quot;, &quot;tr&quot;
  1818.  
  1819.        </dt><dt>An end tag whose tag name is one of: &quot;area&quot;, &quot;basefont&quot;,
  1820.         &quot;bgsound&quot;, <!--XXX quirks: remove br-->&quot;br&quot;, &quot;embed&quot;, &quot;hr&quot;, &quot;iframe&quot;,
  1821.         &quot;image&quot;, &quot;img&quot;, &quot;input&quot;, &quot;isindex&quot;, &quot;noembed&quot;, &quot;noframes&quot;, &quot;param&quot;,
  1822.         &quot;select&quot;, &quot;spacer&quot;, &quot;table&quot;, &quot;textarea&quot;, &quot;wbr&quot;</dt>
  1823.        <!-- add keygen if we add the start tag -->
  1824.  
  1825.        <dt>An end tag whose tag name is &quot;noscript&quot;, if <a href="section-scripting.html#scripting2">scripting is enabled</a>:
  1826.  
  1827.        </dt><dd>
  1828.         <p><a href="section-parsing.html#parse">Parse error</a>. Ignore the token.</p>
  1829.  
  1830.        </dd><dt>A start or end tag whose tag name is one of: &quot;event-source&quot;,
  1831.         &quot;section&quot;, &quot;nav&quot;, &quot;article&quot;, &quot;aside&quot;, &quot;header&quot;, &quot;footer&quot;, &quot;datagrid&quot;,
  1832.         &quot;command&quot;
  1833.  
  1834.        </dt><dd> <!-- XXXX -->
  1835.         <p class="big-issue">Work in progress!</p>
  1836.  
  1837.        </dd><dt>A start tag token not covered by the previous entries
  1838.  
  1839.        </dt><dd>
  1840.         <p><a href="#reconstruct">Reconstruct the active formatting
  1841.          elements</a>, if any.</p>
  1842.  
  1843.         <p><a href="#insert">Insert an HTML element</a> for the token.</p>
  1844.  
  1845.         <p class="note">This element will be a <a href="#phrasing">phrasing</a>
  1846.          element.</p>
  1847.         <!--
  1848. Put the following into the MathML namespace if parsed:
  1849.    math, mrow, mfrac, msqrt, mroot, mstyle, merror, mpadded,
  1850.    mphantom, mfenced, menclose, msub, msup, msubsup, munder,
  1851.    mover, munderover, mmultiscripts, mtable, mlabeledtr, mtr,
  1852.    mtd, maction
  1853. -->
  1854.        
  1855.  
  1856.        </dd><dt>An end tag token not covered by the previous entries
  1857.  
  1858.        </dt><dd>
  1859.         <p>Run the following algorithm:</p>
  1860.  
  1861.         <ol>
  1862.          <li>
  1863.           <p>Initialise <var title="">node</var> to be the <a href="#current4">current node</a> (the bottommost node of the
  1864.            stack).
  1865.  
  1866.          </p></li><li>
  1867.           <p>If <var title="">node</var> has the same tag name as the end tag
  1868.            token, then:</p>
  1869.  
  1870.           <ol>
  1871.            <li>
  1872.             <p><a href="#generate">Generate implied end tags</a>.
  1873.  
  1874.            </p></li><li>
  1875.             <p>If the tag name of the end tag token does not match the tag
  1876.              name of the <a href="#current4">current node</a>, this is a <a href="section-parsing.html#parse">parse error</a>.
  1877.  
  1878.            </p></li><li>
  1879.             <p>Pop all the nodes from the <a href="#current4">current
  1880.              node</a> up to <var title="">node</var>, including <var title="">node</var>, then stop this algorithm.
  1881.           </p></li></ol>
  1882.  
  1883.          </li><li>
  1884.           <p>Otherwise, if <var title="">node</var> is in neither the <a href="#formatting">formatting</a> category nor the <a href="#phrasing">phrasing</a> category, then this is a <a href="section-parsing.html#parse">parse error</a>. Stop this algorithm. The end tag
  1885.            token is ignored.
  1886.  
  1887.          </p></li><li>
  1888.           <p>Set <var title="">node</var> to the previous entry in the <a href="#stack">stack of open elements</a>.
  1889.  
  1890.          </p></li><li>
  1891.           <p>Return to step 2.
  1892.         </p></li></ol>
  1893.       </dd></dl>
  1894.  
  1895.      </dd><dt id="parsing-main-intable">If the <a href="#insertion0">insertion
  1896.       mode</a> is &quot;<dfn id="in-table" title="insertion mode: in table">in
  1897.       table</dfn>&quot;
  1898.  
  1899.      </dt><dd>
  1900.       <dl class="switch">
  1901.        <dt>A character token that is one of one of U+0009 CHARACTER
  1902.         TABULATION, U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C
  1903.         FORM FEED (FF), U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
  1904.  
  1905.        </dt><dd>
  1906.         <p><a href="#append" title="append a character">Append the
  1907.          character</a> to the <a href="#current4">current node</a>.</p>
  1908.  
  1909.        </dd><dt>A comment token
  1910.  
  1911.        </dt><dd>
  1912.         <p>Append a <code>Comment</code> node to the <a href="#current4">current node</a> with the <code title="">data</code> attribute set to the data given in the comment
  1913.          token.</p>
  1914.  
  1915.        </dd><dt>A start tag whose tag name is &quot;caption&quot;
  1916.  
  1917.        </dt><dd>
  1918.         <p><a href="#clear1">Clear the stack back to a table context</a>.
  1919.          (See below.)</p>
  1920.  
  1921.         <p>Insert a marker at the end of the <a href="#list-of4">list of
  1922.          active formatting elements</a>.</p>
  1923.  
  1924.         <p><a href="#insert">Insert an HTML element</a> for the token, then
  1925.          switch the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-caption" title="insertion mode: in caption">in
  1926.          caption</a>&quot;.</p>
  1927.  
  1928.        </dd><dt>A start tag whose tag name is &quot;colgroup&quot;
  1929.  
  1930.        </dt><dd>
  1931.         <p><a href="#clear1">Clear the stack back to a table context</a>.
  1932.          (See below.)</p>
  1933.  
  1934.         <p><a href="#insert">Insert an HTML element</a> for the token, then
  1935.          switch the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-column" title="insertion mode: in column group">in column
  1936.          group</a>&quot;.</p>
  1937.  
  1938.        </dd><dt>A start tag whose tag name is &quot;col&quot;
  1939.  
  1940.        </dt><dd>
  1941.         <p>Act as if a start tag token with the tag name &quot;colgroup&quot; had been
  1942.          seen, then reprocess the current token.</p>
  1943.  
  1944.        </dd><dt>A start tag whose tag name is one of: &quot;tbody&quot;, &quot;tfoot&quot;, &quot;thead&quot;
  1945.  
  1946.        </dt><dd>
  1947.         <p><a href="#clear1">Clear the stack back to a table context</a>.
  1948.          (See below.)</p>
  1949.  
  1950.         <p><a href="#insert">Insert an HTML element</a> for the token, then
  1951.          switch the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-table0" title="insertion mode: in table body">in table
  1952.          body</a>&quot;.</p>
  1953.  
  1954.        </dd><dt>A start tag whose tag name is one of: &quot;td&quot;, &quot;th&quot;, &quot;tr&quot;
  1955.  
  1956.        </dt><dd>
  1957.         <p>Act as if a start tag token with the tag name &quot;tbody&quot; had been
  1958.          seen, then reprocess the current token.</p>
  1959.  
  1960.        </dd><dt>A start tag whose tag name is &quot;table&quot;
  1961.  
  1962.        </dt><dd>
  1963.         <p><a href="section-parsing.html#parse">Parse error</a>. Act as if an end tag token with
  1964.          the tag name &quot;table&quot; had been seen, then, if that token wasn't
  1965.         ignored, reprocess the current token.</p>
  1966.  
  1967.        <p class="note">The fake end tag token here can only be ignored in the
  1968.         <a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>.</p>
  1969.  
  1970.       </dd><dt>An end tag whose tag name is &quot;table&quot;
  1971.  
  1972.       </dt><dd>
  1973.        <p>If the <a href="#stack">stack of open elements</a> does not <a href="#have-an0" title="has an element in table scope">have an
  1974.         element in table scope</a> with the same tag name as the token, this
  1975.         is a <a href="section-parsing.html#parse">parse error</a>. Ignore the token. (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>)</p>
  1976.  
  1977.        <p>Otherwise:</p>
  1978.  
  1979.        <p><a href="#generate">Generate implied end tags</a>.</p>
  1980.  
  1981.        <p>Now, if the <a href="#current4">current node</a> is not a <code><a href="section-tabular.html#table">table</a></code> element, then this is a <a href="section-parsing.html#parse">parse error</a>.</p>
  1982.  
  1983.        <p>Pop elements from this stack until a <code><a href="section-tabular.html#table">table</a></code> element has been popped from the
  1984.         stack.</p>
  1985.  
  1986.        <p><a href="#reset">Reset the insertion mode appropriately</a>.</p>
  1987.  
  1988.       </dd><dt>An end tag whose tag name is one of: &quot;body&quot;, &quot;caption&quot;, &quot;col&quot;,
  1989.        &quot;colgroup&quot;, &quot;html&quot;, &quot;tbody&quot;, &quot;td&quot;, &quot;tfoot&quot;, &quot;th&quot;, &quot;thead&quot;, &quot;tr&quot;
  1990.  
  1991.       </dt><dd>
  1992.        <p><a href="section-parsing.html#parse">Parse error</a>. Ignore the token.</p>
  1993.  
  1994.       </dd><dt>Anything else
  1995.  
  1996.       </dt><dd>
  1997.        <p><a href="section-parsing.html#parse">Parse error</a>. Process the token as if the <a href="#insertion0">insertion mode</a> was &quot;<a href="#in-body" title="insertion mode: in body">in body</a>&quot;, with the following
  1998.         exception:</p>
  1999.  
  2000.        <p>If the <a href="#current4">current node</a> is a <code><a href="section-tabular.html#table">table</a></code>, <code><a href="section-tabular.html#tbody">tbody</a></code>, <code><a href="section-tabular.html#tfoot0">tfoot</a></code>, <code><a href="section-tabular.html#thead0">thead</a></code>, or <code><a href="section-tabular.html#tr">tr</a></code> element, then, whenever a node would be
  2001.         inserted into the <a href="#current4">current node</a>, it must
  2002.         instead be inserted into the <em><a href="#foster">foster parent
  2003.         element</a></em>.</p>
  2004.  
  2005.        <p>The <dfn id="foster">foster parent element</dfn> is the parent
  2006.         element of the last <code><a href="section-tabular.html#table">table</a></code> element
  2007.         in the <a href="#stack">stack of open elements</a>, if there is a
  2008.         <code><a href="section-tabular.html#table">table</a></code> element and it has such a
  2009.         parent element. If there is no <code><a href="section-tabular.html#table">table</a></code> element in the <a href="#stack">stack
  2010.         of open elements</a> (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code>
  2011.         case</a>), then the <em><a href="#foster">foster parent
  2012.         element</a></em> is the first element in the <a href="#stack">stack
  2013.         of open elements</a> (the <code><a href="section-the-root.html#html">html</a></code>
  2014.         element). Otherwise, if there is a <code><a href="section-tabular.html#table">table</a></code> element in the <a href="#stack">stack
  2015.         of open elements</a>, but the last <code><a href="section-tabular.html#table">table</a></code> element in the <a href="#stack">stack
  2016.         of open elements</a> has no parent, or its parent node is not an
  2017.         element, then the <em><a href="#foster">foster parent
  2018.         element</a></em> is the element before the last <code><a href="section-tabular.html#table">table</a></code> element in the <a href="#stack">stack
  2019.         of open elements</a>.</p>
  2020.  
  2021.        <p>If the <em><a href="#foster">foster parent element</a></em> is the
  2022.         parent element of the last <code><a href="section-tabular.html#table">table</a></code>
  2023.         element in the <a href="#stack">stack of open elements</a>, then the
  2024.         new node must be inserted immediately <em>before</em> the last
  2025.         <code><a href="section-tabular.html#table">table</a></code> element in the <a href="#stack">stack of open elements</a> in the <a href="#foster">foster parent element</a>; otherwise, the new node
  2026.         must be <em>appended</em> to the <a href="#foster">foster parent
  2027.         element</a>.</p>
  2028.      </dd></dl>
  2029.  
  2030.      <p>When the steps above require the UA to <dfn id="clear1">clear the
  2031.       stack back to a table context</dfn>, it means that the UA must, while
  2032.       the <a href="#current4">current node</a> is not a <code><a href="section-tabular.html#table">table</a></code> element or an <code><a href="section-the-root.html#html">html</a></code> element, pop elements from the <a href="#stack">stack of open elements</a>. If this causes any elements
  2033.       to be popped from the stack, then this is a <a href="section-parsing.html#parse">parse
  2034.       error</a>.</p>
  2035.  
  2036.      <p class="note">The <a href="#current4">current node</a> being an
  2037.       <code><a href="section-the-root.html#html">html</a></code> element after this process is an
  2038.       <a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>.</p>
  2039.  
  2040.     </dd><dt id="parsing-main-incaption">If the <a href="#insertion0">insertion
  2041.      mode</a> is &quot;<dfn id="in-caption" title="insertion mode: in caption">in
  2042.      caption</dfn>&quot;
  2043.  
  2044.     </dt><dd>
  2045.      <dl class="switch">
  2046.       <dt>An end tag whose tag name is &quot;caption&quot;
  2047.  
  2048.       </dt><dd>
  2049.        <p>If the <a href="#stack">stack of open elements</a> does not <a href="#have-an0" title="has an element in table scope">have an
  2050.         element in table scope</a> with the same tag name as the token, this
  2051.         is a <a href="section-parsing.html#parse">parse error</a>. Ignore the token. (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>)</p>
  2052.  
  2053.        <p>Otherwise:</p>
  2054.  
  2055.        <p><a href="#generate">Generate implied end tags</a>.</p>
  2056.  
  2057.        <p>Now, if the <a href="#current4">current node</a> is not a <code><a href="section-tabular.html#caption0">caption</a></code> element, then this is a <a href="section-parsing.html#parse">parse error</a>.</p>
  2058.  
  2059.        <p>Pop elements from this stack until a <code><a href="section-tabular.html#caption0">caption</a></code> element has been popped from the
  2060.         stack.</p>
  2061.  
  2062.        <p><a href="#clear0">Clear the list of active formatting elements up
  2063.         to the last marker</a>.</p>
  2064.  
  2065.        <p>Switch the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-table" title="insertion mode: in table">in table</a>&quot;.</p>
  2066.  
  2067.       </dd><dt>A start tag whose tag name is one of: &quot;caption&quot;, &quot;col&quot;,
  2068.        &quot;colgroup&quot;, &quot;tbody&quot;, &quot;td&quot;, &quot;tfoot&quot;, &quot;th&quot;, &quot;thead&quot;, &quot;tr&quot;
  2069.  
  2070.       </dt><dt>An end tag whose tag name is &quot;table&quot;
  2071.  
  2072.       </dt><dd>
  2073.        <p><a href="section-parsing.html#parse">Parse error</a>. Act as if an end tag with the
  2074.         tag name &quot;caption&quot; had been seen, then, if that token wasn't
  2075.          ignored, reprocess the current token.</p>
  2076.  
  2077.         <p class="note">The fake end tag token here can only be ignored in the
  2078.          <a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>.</p>
  2079.  
  2080.        </dd><dt>An end tag whose tag name is one of: &quot;body&quot;, &quot;col&quot;, &quot;colgroup&quot;,
  2081.         &quot;html&quot;, &quot;tbody&quot;, &quot;td&quot;, &quot;tfoot&quot;, &quot;th&quot;, &quot;thead&quot;, &quot;tr&quot;
  2082.  
  2083.        </dt><dd>
  2084.         <p><a href="section-parsing.html#parse">Parse error</a>. Ignore the token.</p>
  2085.  
  2086.        </dd><dt>Anything else
  2087.  
  2088.        </dt><dd>
  2089.         <p>Process the token as if the <a href="#insertion0">insertion
  2090.          mode</a> was &quot;<a href="#in-body" title="insertion mode: in body">in
  2091.          body</a>&quot;.</p>
  2092.       </dd></dl>
  2093.  
  2094.      </dd><dt id="parsing-main-incolgroup">If the <a href="#insertion0">insertion
  2095.       mode</a> is &quot;<dfn id="in-column" title="insertion mode: in column
  2096.      group">in column group</dfn>&quot;
  2097.  
  2098.      </dt><dd>
  2099.       <dl class="switch">
  2100.        <dt>A character token that is one of one of U+0009 CHARACTER
  2101.         TABULATION, U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C
  2102.         FORM FEED (FF), U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
  2103.  
  2104.        </dt><dd>
  2105.         <p><a href="#append" title="append a character">Append the
  2106.          character</a> to the <a href="#current4">current node</a>.</p>
  2107.  
  2108.        </dd><dt>A comment token
  2109.  
  2110.        </dt><dd>
  2111.         <p>Append a <code>Comment</code> node to the <a href="#current4">current node</a> with the <code title="">data</code> attribute set to the data given in the comment
  2112.          token.</p>
  2113.  
  2114.        </dd><dt>A start tag whose tag name is &quot;col&quot;
  2115.  
  2116.        </dt><dd>
  2117.         <p><a href="#insert" title="insert an HTML element">Insert a
  2118.          <code>col</code> element</a> for the token. Immediately pop the <a href="#current4">current node</a> off the <a href="#stack">stack of
  2119.          open elements</a>.</p>
  2120.  
  2121.        </dd><dt>An end tag whose tag name is &quot;colgroup&quot;
  2122.  
  2123.        </dt><dd>
  2124.         <p>If the <a href="#current4">current node</a> is the root <code><a href="section-the-root.html#html">html</a></code> element, then this is a <a href="section-parsing.html#parse">parse error</a>, ignore the token. (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>)</p>
  2125.  
  2126.         <p>Otherwise, pop the <a href="#current4">current node</a> (which
  2127.          will be a <code><a href="section-tabular.html#colgroup">colgroup</a></code> element)
  2128.          from the <a href="#stack">stack of open elements</a>. Switch the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-table" title="insertion mode: in table">in table</a>&quot;.</p>
  2129.  
  2130.        </dd><dt>An end tag whose tag name is &quot;col&quot;
  2131.  
  2132.        </dt><dd>
  2133.         <p><a href="section-parsing.html#parse">Parse error</a>. Ignore the token.</p>
  2134.  
  2135.        </dd><dt>Anything else
  2136.  
  2137.        </dt><dd>
  2138.         <p>Act as if an end tag with the tag name &quot;colgroup&quot; had been seen,
  2139.          and then, if that token wasn't ignored, reprocess the current token.</p>
  2140.  
  2141.        <p class="note">The fake end tag token here can only be ignored in the
  2142.         <a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>.</p>
  2143.      </dd></dl>
  2144.  
  2145.     </dd><dt id="parsing-main-intbody">If the <a href="#insertion0">insertion
  2146.      mode</a> is &quot;<dfn id="in-table0" title="insertion mode: in table body">in
  2147.      table body</dfn>&quot;
  2148.  
  2149.     </dt><dd>
  2150.      <dl class="switch">
  2151.       <dt>A start tag whose tag name is &quot;tr&quot;
  2152.  
  2153.       </dt><dd>
  2154.        <p><a href="#clear2">Clear the stack back to a table body
  2155.         context</a>. (See below.)</p>
  2156.  
  2157.        <p><a href="#insert" title="insert an HTML element">Insert a
  2158.         <code>tr</code> element</a> for the token, then switch the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-row" title="insertion mode: in row">in row</a>&quot;.</p>
  2159.  
  2160.       </dd><dt>A start tag whose tag name is one of: &quot;th&quot;, &quot;td&quot;
  2161.  
  2162.       </dt><dd>
  2163.        <p><a href="section-parsing.html#parse">Parse error</a>. Act as if a start tag with the
  2164.         tag name &quot;tr&quot; had been seen, then reprocess the current token.</p>
  2165.  
  2166.       </dd><dt>An end tag whose tag name is one of: &quot;tbody&quot;, &quot;tfoot&quot;, &quot;thead&quot;
  2167.  
  2168.       </dt><dd>
  2169.        <p>If the <a href="#stack">stack of open elements</a> does not <a href="#have-an0" title="has an element in table scope">have an
  2170.         element in table scope</a> with the same tag name as the token, this
  2171.         is a <a href="section-parsing.html#parse">parse error</a>. Ignore the token.</p>
  2172.  
  2173.        <p>Otherwise:</p>
  2174.  
  2175.        <p><a href="#clear2">Clear the stack back to a table body
  2176.         context</a>. (See below.)</p>
  2177.  
  2178.        <p>Pop the <a href="#current4">current node</a> from the <a href="#stack">stack of open elements</a>. Switch the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-table" title="insertion mode: in table">in table</a>&quot;.</p>
  2179.  
  2180.       </dd><dt>A start tag whose tag name is one of: &quot;caption&quot;, &quot;col&quot;,
  2181.        &quot;colgroup&quot;, &quot;tbody&quot;, &quot;tfoot&quot;, &quot;thead&quot;
  2182.  
  2183.       </dt><dt>An end tag whose tag name is &quot;table&quot;
  2184.  
  2185.       </dt><dd>
  2186.        <p>If the <a href="#stack">stack of open elements</a> does not <a href="#have-an0" title="has an element in table scope">have a
  2187.         <code>tbody</code>, <code>thead</code>, or <code>tfoot</code>
  2188.         element in table scope</a>, this is a <a href="section-parsing.html#parse">parse
  2189.         error</a>. Ignore the token. (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>)</p>
  2190.  
  2191.        <p>Otherwise:</p>
  2192.  
  2193.        <p><a href="#clear2">Clear the stack back to a table body
  2194.         context</a>. (See below.)</p>
  2195.  
  2196.        <p>Act as if an end tag with the same tag name as the <a href="#current4">current node</a> (&quot;tbody&quot;, &quot;tfoot&quot;, or &quot;thead&quot;) had
  2197.         been seen, then reprocess the current token.</p>
  2198.  
  2199.       </dd><dt>An end tag whose tag name is one of: &quot;body&quot;, &quot;caption&quot;, &quot;col&quot;,
  2200.        &quot;colgroup&quot;, &quot;html&quot;, &quot;td&quot;, &quot;th&quot;, &quot;tr&quot;
  2201.  
  2202.       </dt><dd>
  2203.        <p><a href="section-parsing.html#parse">Parse error</a>. Ignore the token.</p>
  2204.  
  2205.       </dd><dt>Anything else
  2206.  
  2207.       </dt><dd>
  2208.        <p>Process the token as if the <a href="#insertion0">insertion
  2209.         mode</a> was &quot;<a href="#in-table" title="insertion mode: in
  2210.         table">in table</a>&quot;.</p>
  2211.      </dd></dl>
  2212.  
  2213.      <p>When the steps above require the UA to <dfn id="clear2">clear the
  2214.       stack back to a table body context</dfn>, it means that the UA must,
  2215.       while the <a href="#current4">current node</a> is not a <code><a href="section-tabular.html#tbody">tbody</a></code>, <code><a href="section-tabular.html#tfoot0">tfoot</a></code>, <code><a href="section-tabular.html#thead0">thead</a></code>, or <code><a href="section-the-root.html#html">html</a></code> element, pop elements from the <a href="#stack">stack of open elements</a>. If this causes any elements
  2216.       to be popped from the stack, then this is a <a href="section-parsing.html#parse">parse
  2217.       error</a>.</p>
  2218.  
  2219.      <p class="note">The <a href="#current4">current node</a> being an
  2220.       <code><a href="section-the-root.html#html">html</a></code> element after this process is an
  2221.       <a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>.</p>
  2222.  
  2223.     </dd><dt id="parsing-main-intr">If the <a href="#insertion0">insertion mode</a>
  2224.      is &quot;<dfn id="in-row" title="insertion mode: in row">in row</dfn>&quot;
  2225.  
  2226.     </dt><dd>
  2227.      <dl class="switch">
  2228.       <dt>A start tag whose tag name is one of: &quot;th&quot;, &quot;td&quot;
  2229.  
  2230.       </dt><dd>
  2231.        <p><a href="#clear3">Clear the stack back to a table row context</a>.
  2232.         (See below.)</p>
  2233.  
  2234.        <p><a href="#insert" title="insert an HTML element">Insert an HTML
  2235.         element</a> for the token, then switch the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-cell" title="insertion mode: in cell">in cell</a>&quot;.</p>
  2236.  
  2237.        <p>Insert a marker at the end of the <a href="#list-of4">list of
  2238.         active formatting elements</a>.</p>
  2239.  
  2240.       </dd><dt>An end tag whose tag name is &quot;tr&quot;
  2241.  
  2242.       </dt><dd>
  2243.        <p>If the <a href="#stack">stack of open elements</a> does not <a href="#have-an0" title="has an element in table scope">have an
  2244.         element in table scope</a> with the same tag name as the token, this
  2245.         is a <a href="section-parsing.html#parse">parse error</a>. Ignore the token. (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>)</p>
  2246.  
  2247.        <p>Otherwise:</p>
  2248.  
  2249.        <p><a href="#clear3">Clear the stack back to a table row context</a>.
  2250.         (See below.)</p>
  2251.  
  2252.        <p>Pop the <a href="#current4">current node</a> (which will be a
  2253.         <code><a href="section-tabular.html#tr">tr</a></code> element) from the <a href="#stack">stack of open elements</a>. Switch the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-table0" title="insertion mode: in table body">in table body</a>&quot;.</p>
  2254.  
  2255.       </dd><dt>A start tag whose tag name is one of: &quot;caption&quot;, &quot;col&quot;,
  2256.        &quot;colgroup&quot;, &quot;tbody&quot;, &quot;tfoot&quot;, &quot;thead&quot;, &quot;tr&quot;
  2257.  
  2258.       </dt><dt>An end tag whose tag name is &quot;table&quot;
  2259.  
  2260.       </dt><dd>
  2261.        <p>Act as if an end tag with the tag name &quot;tr&quot; had been seen, then,
  2262.         if that token wasn't ignored, reprocess the current token.</p>
  2263.  
  2264.         <p class="note">The fake end tag token here can only be ignored in the
  2265.          <a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>.</p>
  2266.  
  2267.        </dd><dt>An end tag whose tag name is one of: &quot;tbody&quot;, &quot;tfoot&quot;, &quot;thead&quot;
  2268.  
  2269.        </dt><dd>
  2270.         <p>If the <a href="#stack">stack of open elements</a> does not <a href="#have-an0" title="has an element in table scope">have an
  2271.          element in table scope</a> with the same tag name as the token, this
  2272.          is a <a href="section-parsing.html#parse">parse error</a>. Ignore the token.</p>
  2273.  
  2274.         <p>Otherwise, act as if an end tag with the tag name &quot;tr&quot; had been
  2275.          seen, then reprocess the current token.</p>
  2276.  
  2277.        </dd><dt>An end tag whose tag name is one of: &quot;body&quot;, &quot;caption&quot;, &quot;col&quot;,
  2278.         &quot;colgroup&quot;, &quot;html&quot;, &quot;td&quot;, &quot;th&quot;
  2279.  
  2280.        </dt><dd>
  2281.         <p><a href="section-parsing.html#parse">Parse error</a>. Ignore the token.</p>
  2282.  
  2283.        </dd><dt>Anything else
  2284.  
  2285.        </dt><dd>
  2286.         <p>Process the token as if the <a href="#insertion0">insertion
  2287.          mode</a> was &quot;<a href="#in-table" title="insertion mode: in
  2288.         table">in table</a>&quot;.</p>
  2289.       </dd></dl>
  2290.  
  2291.       <p>When the steps above require the UA to <dfn id="clear3">clear the
  2292.        stack back to a table row context</dfn>, it means that the UA must,
  2293.        while the <a href="#current4">current node</a> is not a <code><a href="section-tabular.html#tr">tr</a></code> element or an <code><a href="section-the-root.html#html">html</a></code> element, pop elements from the <a href="#stack">stack of open elements</a>. If this causes any elements
  2294.        to be popped from the stack, then this is a <a href="section-parsing.html#parse">parse
  2295.        error</a>.</p>
  2296.  
  2297.       <p class="note">The <a href="#current4">current node</a> being an
  2298.        <code><a href="section-the-root.html#html">html</a></code> element after this process is an
  2299.        <a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>.</p>
  2300.  
  2301.      </dd><dt id="parsing-main-intd">If the <a href="#insertion0">insertion mode</a>
  2302.       is &quot;<dfn id="in-cell" title="insertion mode: in cell">in cell</dfn>&quot;
  2303.  
  2304.      </dt><dd>
  2305.       <dl class="switch">
  2306.        <dt>An end tag whose tag name is one of: &quot;td&quot;, &quot;th&quot;
  2307.  
  2308.        </dt><dd>
  2309.         <p>If the <a href="#stack">stack of open elements</a> does not <a href="#have-an0" title="has an element in table scope">have an
  2310.          element in table scope</a> with the same tag name as that of the
  2311.          token, then this is a <a href="section-parsing.html#parse">parse error</a> and the token
  2312.          must be ignored.</p>
  2313.  
  2314.         <p>Otherwise:</p>
  2315.  
  2316.         <p><a href="#generate">Generate implied end tags</a>, except for
  2317.          elements with the same tag name as the token.</p>
  2318.  
  2319.         <p>Now, if the <a href="#current4">current node</a> is not an element
  2320.          with the same tag name as the token, then this is a <a href="section-parsing.html#parse">parse error</a>.</p>
  2321.  
  2322.         <p>Pop elements from this stack until an element with the same tag
  2323.          name as the token has been popped from the stack.</p>
  2324.  
  2325.         <p><a href="#clear0">Clear the list of active formatting elements up
  2326.          to the last marker</a>.</p>
  2327.  
  2328.         <p>Switch the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-row" title="insertion mode: in row">in row</a>&quot;. (The <a href="#current4">current node</a> will be a <code><a href="section-tabular.html#tr">tr</a></code> element at this point.)</p>
  2329.  
  2330.        </dd><dt>A start tag whose tag name is one of: &quot;caption&quot;, &quot;col&quot;,
  2331.         &quot;colgroup&quot;, &quot;tbody&quot;, &quot;td&quot;, &quot;tfoot&quot;, &quot;th&quot;, &quot;thead&quot;, &quot;tr&quot;
  2332.  
  2333.        </dt><dd>
  2334.         <p>If the <a href="#stack">stack of open elements</a> does
  2335.          <em>not</em> <a href="#have-an0" title="has an element in table
  2336.         scope">have a <code>td</code> or <code>th</code> element in table
  2337.          scope</a>, then this is a <a href="section-parsing.html#parse">parse error</a>; ignore
  2338.          the token. (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>)</p>
  2339.  
  2340.         <p>Otherwise, <a href="#close2">close the cell</a> (see below) and
  2341.          reprocess the current token.</p>
  2342.  
  2343.        </dd><dt>An end tag whose tag name is one of: &quot;body&quot;, &quot;caption&quot;, &quot;col&quot;,
  2344.         &quot;colgroup&quot;, &quot;html&quot;
  2345.  
  2346.        </dt><dd>
  2347.         <p><a href="section-parsing.html#parse">Parse error</a>. Ignore the token.</p>
  2348.  
  2349.        </dd><dt>An end tag whose tag name is one of: &quot;table&quot;, &quot;tbody&quot;, &quot;tfoot&quot;,
  2350.         &quot;thead&quot;, &quot;tr&quot;
  2351.  
  2352.        </dt><dd>
  2353.         <p>If the <a href="#stack">stack of open elements</a> does not <a href="#have-an0" title="has an element in table scope">have an
  2354.          element in table scope</a> with the same tag name as that of the
  2355.          token (which can only happen for &quot;tbody&quot;, &quot;tfoot&quot; and &quot;thead&quot;, or,
  2356.          in the <a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>), then
  2357.          this is a <a href="section-parsing.html#parse">parse error</a> and the token must be
  2358.          ignored.</p>
  2359.  
  2360.         <p>Otherwise, <a href="#close2">close the cell</a> (see below) and
  2361.          reprocess the current token.</p>
  2362.  
  2363.        </dd><dt>Anything else
  2364.  
  2365.        </dt><dd>
  2366.         <p>Process the token as if the <a href="#insertion0">insertion
  2367.          mode</a> was &quot;<a href="#in-body" title="insertion mode: in body">in
  2368.          body</a>&quot;.</p>
  2369.       </dd></dl>
  2370.  
  2371.       <p>Where the steps above say to <dfn id="close2">close the cell</dfn>,
  2372.        they mean to follow the following algorithm:</p>
  2373.  
  2374.       <ol>
  2375.        <li>
  2376.         <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an0" title="has an element in table scope">has a
  2377.          <code>td</code> element in table scope</a>, then act as if an end
  2378.          tag token with the tag name &quot;td&quot; had been seen.
  2379.  
  2380.        </p></li><li>
  2381.         <p>Otherwise, the <a href="#stack">stack of open elements</a> will <a href="#have-an0" title="has an element in table scope">have a
  2382.          <code>th</code> element in table scope</a>; act as if an end tag
  2383.          token with the tag name &quot;th&quot; had been seen.
  2384.       </p></li></ol>
  2385.  
  2386.       <p class="note">The <a href="#stack">stack of open elements</a> cannot
  2387.        have both a <code><a href="section-tabular.html#td">td</a></code> and a <code><a href="section-tabular.html#th">th</a></code> element <a href="#have-an0" title="has an
  2388.       element in table scope">in table scope</a> at the same time, nor can
  2389.        it have neither when the <a href="#insertion0">insertion mode</a> is
  2390.        &quot;<a href="#in-cell" title="insertion mode: in cell">in cell</a>&quot;.</p>
  2391.  
  2392.      </dd><dt id="parsing-main-inselect">If the <a href="#insertion0">insertion
  2393.       mode</a> is &quot;<dfn id="in-select" title="insertion mode: in select">in
  2394.       select</dfn>&quot;
  2395.  
  2396.      </dt><dd>
  2397.       <p>Handle the token as follows:</p>
  2398.  
  2399.       <dl class="switch">
  2400.        <dt>A character token
  2401.  
  2402.        </dt><dd>
  2403.         <p><a href="#append" title="append a character">Append the token's
  2404.         character</a> to the <a href="#current4">current node</a>.</p>
  2405.  
  2406.       </dd><dt>A comment token
  2407.  
  2408.       </dt><dd>
  2409.        <p>Append a <code>Comment</code> node to the <a href="#current4">current node</a> with the <code title="">data</code> attribute set to the data given in the comment
  2410.         token.</p>
  2411.  
  2412.       </dd><dt>A start tag token whose tag name is &quot;option&quot;
  2413.  
  2414.       </dt><dd>
  2415.        <p>If the <a href="#current4">current node</a> is an
  2416.         <code>option</code> element, act as if an end tag with the tag name
  2417.         &quot;option&quot; had been seen.</p>
  2418.  
  2419.        <p><a href="#insert">Insert an HTML element</a> for the token.</p>
  2420.  
  2421.       </dd><dt>A start tag token whose tag name is &quot;optgroup&quot;
  2422.  
  2423.       </dt><dd>
  2424.        <p>If the <a href="#current4">current node</a> is an
  2425.         <code>option</code> element, act as if an end tag with the tag name
  2426.         &quot;option&quot; had been seen.</p>
  2427.  
  2428.        <p>If the <a href="#current4">current node</a> is an
  2429.         <code>optgroup</code> element, act as if an end tag with the tag
  2430.         name &quot;optgroup&quot; had been seen.</p>
  2431.  
  2432.        <p><a href="#insert">Insert an HTML element</a> for the token.</p>
  2433.  
  2434.       </dd><dt>An end tag token whose tag name is &quot;optgroup&quot;
  2435.  
  2436.       </dt><dd>
  2437.        <p>First, if the <a href="#current4">current node</a> is an
  2438.         <code>option</code> element, and the node immediately before it in
  2439.         the <a href="#stack">stack of open elements</a> is an
  2440.         <code>optgroup</code> element, then act as if an end tag with the
  2441.         tag name &quot;option&quot; had been seen.</p>
  2442.  
  2443.        <p>If the <a href="#current4">current node</a> is an
  2444.         <code>optgroup</code> element, then pop that node from the <a href="#stack">stack of open elements</a>. Otherwise, this is a <a href="section-parsing.html#parse">parse error</a>, ignore the token.</p>
  2445.  
  2446.       </dd><dt>An end tag token whose tag name is &quot;option&quot;
  2447.  
  2448.       </dt><dd>
  2449.        <p>If the <a href="#current4">current node</a> is an
  2450.         <code>option</code> element, then pop that node from the <a href="#stack">stack of open elements</a>. Otherwise, this is a <a href="section-parsing.html#parse">parse error</a>, ignore the token.</p>
  2451.  
  2452.       </dd><dt>An end tag whose tag name is &quot;select&quot;
  2453.  
  2454.       </dt><dd>
  2455.        <p>If the <a href="#stack">stack of open elements</a> does not <a href="#have-an0" title="has an element in table scope">have an
  2456.         element in table scope</a> with the same tag name as the token, this
  2457.         is a <a href="section-parsing.html#parse">parse error</a>. Ignore the token. (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>)</p>
  2458.  
  2459.        <p>Otherwise:</p>
  2460.  
  2461.        <p>Pop elements from the <a href="#stack">stack of open elements</a>
  2462.         until a <code>select</code> element has been popped from the stack.</p>
  2463.  
  2464.        <p><a href="#reset">Reset the insertion mode appropriately</a>.</p>
  2465.  
  2466.       </dd><dt>A start tag whose tag name is &quot;select&quot;
  2467.  
  2468.       </dt><dd>
  2469.        <p><a href="section-parsing.html#parse">Parse error</a>. Act as if the token had been an
  2470.         end tag with the tag name &quot;select&quot; instead.</p>
  2471.  
  2472.       </dd><dt>An end tag whose tag name is one of: &quot;caption&quot;, &quot;table&quot;, &quot;tbody&quot;,
  2473.        &quot;tfoot&quot;, &quot;thead&quot;, &quot;tr&quot;, &quot;td&quot;, &quot;th&quot;
  2474.  
  2475.       </dt><dd>
  2476.        <p><a href="section-parsing.html#parse">Parse error</a>.</p>
  2477.  
  2478.        <p>If the <a href="#stack">stack of open elements</a> <a href="#have-an0">has an element in table scope</a> with the same tag
  2479.         name as that of the token, then act as if an end tag with the tag
  2480.         name &quot;select&quot; had been seen, and reprocess the token. Otherwise,
  2481.         ignore the token.</p>
  2482.  
  2483.       </dd><dt>Anything else
  2484.  
  2485.       </dt><dd>
  2486.        <p><a href="section-parsing.html#parse">Parse error</a>. Ignore the token.</p>
  2487.      </dd></dl>
  2488.  
  2489.     </dd><dt id="parsing-main-afterbody">If the <a href="#insertion0">insertion
  2490.      mode</a> is &quot;<dfn id="after2" title="insertion mode: after body">after
  2491.      body</dfn>&quot;
  2492.  
  2493.     </dt><dd>
  2494.      <p>Handle the token as follows:</p>
  2495.  
  2496.      <dl class="switch">
  2497.       <dt>A character token that is one of one of U+0009 CHARACTER
  2498.        TABULATION, U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C
  2499.        FORM FEED (FF), U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
  2500.  
  2501.       </dt><dd>
  2502.        <p>Process the token as it would be processed if the <a href="#insertion0">insertion mode</a> was &quot;<a href="#in-body" title="insertion mode: in body">in body</a>&quot;.</p>
  2503.  
  2504.       </dd><dt>A comment token
  2505.  
  2506.       </dt><dd>
  2507.        <p>Append a <code>Comment</code> node to the first element in the <a href="#stack">stack of open elements</a> (the <code><a href="section-the-root.html#html">html</a></code> element), with the <code title="">data</code> attribute set to the data given in the comment
  2508.         token.</p>
  2509.  
  2510.       </dd><dt>An end tag with the tag name &quot;html&quot;
  2511.  
  2512.       </dt><dd>
  2513.        <p>If the parser was originally created in order to handle the
  2514.         setting of <em>an element</em>'s <code title="dom-innerHTML-HTML"><a href="section-dynamic.html#innerhtml0">innerHTML</a></code> attribute, this is a <a href="section-parsing.html#parse">parse error</a>; ignore the token. (The element will
  2515.          be an <code><a href="section-the-root.html#html">html</a></code> element in this case.)
  2516.          (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>)</p>
  2517.  
  2518.         <p>Otherwise, switch to <a href="#the-trailing0">the trailing end
  2519.          phase</a>.</p>
  2520.  
  2521.        </dd><dt>Anything else
  2522.  
  2523.        </dt><dd>
  2524.         <p><a href="section-parsing.html#parse">Parse error</a>. Set the <a href="#insertion0">insertion mode</a> to &quot;<a href="#in-body" title="insertion mode: in body">in body</a>&quot; and reprocess the
  2525.          token.</p>
  2526.       </dd></dl>
  2527.  
  2528.      </dd><dt id="parsing-main-inframeset">If the <a href="#insertion0">insertion
  2529.       mode</a> is &quot;<dfn id="in-frameset" title="insertion mode: in frameset">in
  2530.       frameset</dfn>&quot;
  2531.  
  2532.      </dt><dd>
  2533.       <p>Handle the token as follows:</p>
  2534.  
  2535.       <dl class="switch">
  2536.        <dt>A character token that is one of one of U+0009 CHARACTER
  2537.         TABULATION, U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C
  2538.         FORM FEED (FF), U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
  2539.  
  2540.        </dt><dd>
  2541.         <p><a href="#append" title="append a character">Append the
  2542.          character</a> to the <a href="#current4">current node</a>.</p>
  2543.  
  2544.        </dd><dt>A comment token
  2545.  
  2546.        </dt><dd>
  2547.         <p>Append a <code>Comment</code> node to the <a href="#current4">current node</a> with the <code title="">data</code> attribute set to the data given in the comment
  2548.          token.</p>
  2549.  
  2550.        </dd><dt>A start tag with the tag name &quot;frameset&quot;
  2551.  
  2552.        </dt><dd>
  2553.         <p><a href="#insert" title="Insert an HTML element">Insert a
  2554.          <code>frameset</code> element</a> for the token.</p>
  2555.  
  2556.        </dd><dt>An end tag with the tag name &quot;frameset&quot;
  2557.  
  2558.        </dt><dd>
  2559.         <p>If the <a href="#current4">current node</a> is the root <code><a href="section-the-root.html#html">html</a></code> element, then this is a <a href="section-parsing.html#parse">parse error</a>; ignore the token. (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>)</p>
  2560.  
  2561.         <p>Otherwise, pop the <a href="#current4">current node</a> from the
  2562.          <a href="#stack">stack of open elements</a>.</p>
  2563.  
  2564.         <p>If the parser was <em>not</em> originally created in order to
  2565.          handle the setting of an element's <code title="dom-innerHTML-HTML"><a href="section-dynamic.html#innerhtml0">innerHTML</a></code> attribute (<a href="section-dynamic.html#innerhtml1"><code>innerHTML</code> case</a>), and the <a href="#current4">current node</a> is no longer a
  2566.         <code>frameset</code> element, then change the <a href="#insertion0">insertion mode</a> to &quot;<a href="#after3" title="insertion mode: after frameset">after frameset</a>&quot;.</p>
  2567.  
  2568.       </dd><dt>A start tag with the tag name &quot;frame&quot;
  2569.  
  2570.       </dt><dd>
  2571.        <p><a href="#insert">Insert an HTML element</a> for the token.
  2572.         Immediately pop the <a href="#current4">current node</a> off the <a href="#stack">stack of open elements</a>.</p>
  2573.  
  2574.       </dd><dt>A start tag with the tag name &quot;noframes&quot;
  2575.  
  2576.       </dt><dd>
  2577.        <p>Process the token as if the <a href="#insertion0">insertion
  2578.         mode</a> had been &quot;<a href="#in-body" title="insertion mode: in
  2579.         body">in body</a>&quot;.</p>
  2580.  
  2581.       </dd><dt>Anything else
  2582.  
  2583.       </dt><dd>
  2584.        <p><a href="section-parsing.html#parse">Parse error</a>. Ignore the token.</p>
  2585.      </dd></dl>
  2586.  
  2587.     </dd><dt id="parsing-main-afterframeset">If the <a href="#insertion0">insertion
  2588.      mode</a> is &quot;<dfn id="after3" title="insertion mode: after
  2589.      frameset">after frameset</dfn>&quot;
  2590.  
  2591.     </dt><dd>
  2592.      <p>Handle the token as follows:</p>
  2593.  
  2594.      <dl class="switch">
  2595.       <dt>A character token that is one of one of U+0009 CHARACTER
  2596.        TABULATION, U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C
  2597.        FORM FEED (FF), U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
  2598.  
  2599.       </dt><dd>
  2600.        <p><a href="#append" title="append a character">Append the
  2601.         character</a> to the <a href="#current4">current node</a>.</p>
  2602.  
  2603.       </dd><dt>A comment token
  2604.  
  2605.       </dt><dd>
  2606.        <p>Append a <code>Comment</code> node to the <a href="#current4">current node</a> with the <code title="">data</code> attribute set to the data given in the comment
  2607.         token.</p>
  2608.  
  2609.       </dd><dt>An end tag with the tag name &quot;html&quot;
  2610.  
  2611.       </dt><dd>
  2612.        <p>Switch to <a href="#the-trailing0">the trailing end phase</a>.</p>
  2613.  
  2614.       </dd><dt>A start tag with the tag name &quot;noframes&quot;
  2615.  
  2616.       </dt><dd>
  2617.        <p>Process the token as if the <a href="#insertion0">insertion
  2618.         mode</a> had been &quot;<a href="#in-body" title="insertion mode: in
  2619.         body">in body</a>&quot;.</p>
  2620.  
  2621.       </dd><dt>Anything else
  2622.  
  2623.       </dt><dd>
  2624.        <p><a href="section-parsing.html#parse">Parse error</a>. Ignore the token.</p>
  2625.      </dd></dl>
  2626.    </dd></dl>
  2627.  </dd></dl>
  2628.  
  2629.  <p class="big-issue">This doesn't handle UAs that don't support frames, or
  2630.   that do support frames but want to show the NOFRAMES content. Supporting
  2631.   the former is easy; supporting the latter is harder.
  2632.  
  2633.  </p><h5 id="the-trailing"><span class="secno">8.2.4.4. </span><dfn id="the-trailing0">The trailing end phase</dfn></h5>
  2634.  
  2635.  <p>After <a href="#the-main0">the main phase</a>, as each token is emitted
  2636.   from the <a href="section-tokenisation.html#tokenisation0">tokenisation</a> stage, it must be
  2637.   processed as described in this section.
  2638.  
  2639.  </p><dl class="switch">
  2640.   <dt>A DOCTYPE token
  2641.  
  2642.   </dt><dd>
  2643.    <p><a href="section-parsing.html#parse">Parse error</a>. Ignore the token.</p>
  2644.  
  2645.   </dd><dt>A comment token
  2646.  
  2647.   </dt><dd>
  2648.    <p>Append a <code>Comment</code> node to the <code>Document</code> object
  2649.     with the <code title="">data</code> attribute set to the data given in
  2650.     the comment token.</p>
  2651.  
  2652.   </dd><dt>A character token that is one of one of U+0009 CHARACTER TABULATION,
  2653.    U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
  2654.    U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
  2655.  
  2656.   </dt><dd>
  2657.    <p>Process the token as it would be processed in <a href="#the-main0">the
  2658.     main phase</a>.</p>
  2659.  
  2660.   </dd><dt>A character token that is <em>not</em> one of U+0009 CHARACTER
  2661.    TABULATION, U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM
  2662.    FEED (FF), U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
  2663.  
  2664.   </dt><dt>A start tag token
  2665.  
  2666.   </dt><dt>An end tag token
  2667.  
  2668.   </dt><dd>
  2669.    <p><a href="section-parsing.html#parse">Parse error</a>. Switch back to <a href="#the-main0">the main phase</a> and reprocess the token.</p>
  2670.  
  2671.   </dd><dt>An end-of-file token
  2672.  
  2673.   </dt><dd>
  2674.    <p><a href="#stops">Stop parsing</a>.</p>
  2675.  </dd></dl>
  2676.  
  2677.  <h4 id="the-end"><span class="secno">8.2.5. </span>The End</h4>
  2678.  
  2679.  <p>Once the user agent <dfn id="stops" title="stop parsing">stops
  2680.   parsing</dfn> the document, the user agent must follow the steps in this
  2681.   section.
  2682.  
  2683.  </p><p>First, <!--the user agent must <span title="fire a DOMContentLoaded
  2684.  event">fire a <code
  2685.  title="event-DOMContentLoaded">DOMContentLoaded</code> event</span>
  2686.  at <span>the <code>body</code> element</span>.</p>
  2687.  
  2688.  <p>Then, -->the
  2689.   rules for <a href="section-scripting0.html#when-a">when a script completes loading</a> start
  2690.   applying (script execution is no longer managed by the parser).
  2691.  
  2692.  </p><p>If any of the scripts in the <a href="section-scripting0.html#list-of1">list of scripts that
  2693.   will execute as soon as possible</a> have <span>completed
  2694.   loading</span><!-- XXX xref -->, or if the <a href="section-scripting0.html#list-of0">list of
  2695.   scripts that will execute asynchronously</a> is not empty and the first
  2696.   script in that list has <span>completed loading</span><!-- XXX xref
  2697.  -->,
  2698.   then the user agent must act as if those scripts just completed loading,
  2699.   following the rules given for that in the <code><a href="section-scripting0.html#script0">script</a></code> element definition.
  2700.  
  2701.  </p><p>Then, if the <a href="section-scripting0.html#list-of">list of scripts that will execute when
  2702.   the document has finished parsing</a> is not empty, and the first item in
  2703.   this list has already <span>completed loading</span><!--XXX
  2704.  xref -->,
  2705.   then the user agent must act as if that script just finished loading.
  2706.  
  2707.  </p><p>By this point, there will be no scripts that have loaded but have not
  2708.   yet been executed.
  2709.  
  2710.  </p><p>The user agent must then <a href="section-scripting.html#firing2">fire a simple event</a>
  2711.   called <code title="event-DOMContentLoaded">DOMContentLoaded</code> at the
  2712.   <code>Document</code>.
  2713.  
  2714.  </p><p>Once everything that <dfn id="delays" title="delay the load event">delays
  2715.   the load event</dfn> has completed, the user agent must <a href="section-scripting.html#firing4" title="fire a load event">fire a <code title="event-load">load</code>
  2716.   event</a> at <a href="section-dom-tree.html#the-body0">the <code>body</code> element</a>.</p>
  2717.  <!-- XXX make sure things "delay the load event" -->
  2718.  <!--XXX need to handle
  2719. http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#2354
  2720. 2354           // Don't open transient styles if it makes the stack deep, bug 58917.
  2721. -->
  2722.   <!--XXX
  2723. http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/nsHTMLTokenizer.cpp#749
  2724. -->
  2725.   <!--
  2726. see also  CTextToken::ConsumeCharacterData()  for CDATA parsing?
  2727.  
  2728. 1212                      1  Here's a tricky case from bug 22596:  <h5><li><h5>
  2729. 1213                         How do we know that the 2nd <h5> should close the <LI> rather than nest inside the <LI>?
  2730. 1214                         (Afterall, the <h5> is a legal child of the <LI>).
  2731. 1215              
  2732. 1216                         The way you know is that there is no root between the two, so the <h5> binds more
  2733. 1217                         tightly to the 1st <h5> than to the <LI>.
  2734. 1218                      2.  Also, bug 6148 shows this case: <SPAN><DIV><SPAN>
  2735. 1219                         From this case we learned not to execute this logic if the parent is a block.
  2736. 1220                    
  2737. 1221                      3. Fix for 26583
  2738. 1222                         Ex. <A href=foo.html><B>foo<A href-bar.html>bar</A></B></A>  <- A legal HTML
  2739. 1223                         In the above example clicking on "foo" or "bar" should link to
  2740. 1224                         foo.html or bar.html respectively. That is, the inner <A> should be informed
  2741. 1225                         about the presence of an open <A> above <B>..so that the inner <A> can close out
  2742. 1226                         the outer <A>. The following code does it for us.
  2743. 1227                      
  2744. 1228                      4. Fix for 27865 [ similer to 22596 ]. Ex: <DL><DD><LI>one<DD><LI>two
  2745. - http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#1211
  2746.  
  2747. 815             // Here's a problem.  If theTag is legal in here, we don't move it
  2748. 816             // out.  So if we're moving stuff out of here, the parent of theTag
  2749. 817             // gets closed at this point.  But some things are legal
  2750. 818             // _everywhere_ and hence would effectively close out misplaced
  2751. 819             // content in tables.  This is undesirable, so treat them as
  2752. 820             // illegal here so they'll be shipped out with their parents and
  2753. 821             // siblings.  See bug 40855 for an explanation (that bug was for
  2754. 822             // comments, but the same issues arise with whitespace, newlines,
  2755. 823             // noscript, etc).  Script is special, though.  Shipping it out
  2756. 824             // breaks document.write stuff.  See bug 243064.
  2757. - http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#825
  2758.  
  2759.  
  2760. 1326     /**************************************************************************************
  2761. 1327      *
  2762. 1328      * Now a little code to deal with bug #49687 (crash when layout stack gets too deep)
  2763. 1329      * I've also opened this up to any container (not just inlines): re bug 55095
  2764. 1330      * Improved to handle bug 55980 (infinite loop caused when DEPTH is exceeded and
  2765. 1331      * </P> is encountered by itself (<P>) is continuously produced.
  2766. 1332      *
  2767. 1333      **************************************************************************************/
  2768.  
  2769. 1912               // Oh boy!! we found a "stray" tag. Nav4.x and IE introduce line break in
  2770. 1913               // such cases. So, let's simulate that effect for compatibility.
  2771. 1914               // Ex. <html><body>Hello</P>There</body></html>
  2772. http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#1912
  2773.  
  2774. http://lxr.mozilla.org/seamonkey/search?string=nested
  2775. /parser/htmlparser/src/CNavDTD.cpp, line 791 - * 2. <CENTER><DL><DT><A><CENTER> allow nested <CENTER>
  2776. /parser/htmlparser/src/CNavDTD.cpp, line 792 - * 3. <TABLE><TR><TD><TABLE>... allow nested <TABLE>
  2777. /parser/htmlparser/src/CNavDTD.cpp, line 2562 - // Discard nested forms - bug 72639
  2778. /parser/htmlparser/src/nsElementTable.cpp, line 1453 - * 2. <CENTER><DL><DT><A><CENTER> allow nested <CENTER>
  2779. /parser/htmlparser/src/nsElementTable.cpp, line 1454 - * 3. <TABLE><TR><TD><TABLE>... allow nested <TABLE>
  2780. /parser/htmlparser/src/nsElementTable.cpp, line 1901 - // Ex: <H1><LI><H1><LI>. Inner LI has the potential of getting nested
  2781. -->
  2782.  
  2783.  <script src="http://status.whatwg.org/annotate-web-apps.js" type="text/javascript"></script></body></html>