[html5] r7999 - [giow] (3) Another very risky change! Please review! This attempts to refactor t [...]

whatwg at whatwg.org whatwg at whatwg.org
Tue Jun 25 13:55:22 PDT 2013


Author: ianh
Date: 2013-06-25 13:55:18 -0700 (Tue, 25 Jun 2013)
New Revision: 7999

Modified:
   complete.html
   index
   source
Log:
[giow] (3) Another very risky change! Please review! This attempts to refactor the parser logic so that the ownerDocument is explicitly set at each place a node is created by the parser. This actually fixes an ambiguity, which was what should happen when a script has transplated a node that is still on the stack of open elements into a Document without a browsing context, if the node created has some magic (e.g. <img src>, <script>).
Affected topics: HTML Syntax and Parsing

Modified: complete.html
===================================================================
--- complete.html	2013-06-25 05:37:58 UTC (rev 7998)
+++ complete.html	2013-06-25 20:55:18 UTC (rev 7999)
@@ -86301,7 +86301,7 @@
   active formatting elements</dfn>, the UA must perform the following
   steps:</p>
 
-  <ol><li>If there are no entries in the <a href=#list-of-active-formatting-elements>list of active formatting
+  <ol><!--CLEANUP--><!--<p>s--><li>If there are no entries in the <a href=#list-of-active-formatting-elements>list of active formatting
    elements</a>, then there is nothing to reconstruct; stop this
    algorithm.</li>
 
@@ -86314,35 +86314,30 @@
    element in the <a href=#list-of-active-formatting-elements>list of active formatting
    elements</a>.</li>
 
-   <li>If there are no entries before <var title="">entry</var> in the
-   <a href=#list-of-active-formatting-elements>list of active formatting elements</a>, then jump to step
-   8.</li>
+   <li><i>Rewind</i>: If there are no entries before <var title="">entry</var> in the
+   <a href=#list-of-active-formatting-elements>list of active formatting elements</a>, then jump to the step
+   labeled <i>create</i>.</li>
 
    <li>Let <var title="">entry</var> be the entry one earlier than
    <var title="">entry</var> in the <a href=#list-of-active-formatting-elements>list of active formatting
    elements</a>.</li>
 
    <li>If <var title="">entry</var> is neither a marker nor an element
-   that is also in the <a href=#stack-of-open-elements>stack of open elements</a>, go to step
-   4.</li>
+   that is also in the <a href=#stack-of-open-elements>stack of open elements</a>, go to the step labeled
+   <i>rewind</i>.</li>
 
-   <li>Let <var title="">entry</var> be the element one later than
+   <li><i>Advance</i>: Let <var title="">entry</var> be the element one later than
    <var title="">entry</var> in the <a href=#list-of-active-formatting-elements>list of active formatting
    elements</a>.</li>
 
-   <li><a href=#create-an-element-for-the-token>Create an element for the token</a> for which the
-   element <var title="">entry</var> was created, to obtain <var title="">new element</var>.</li>
+   <li><i>Create</i>: <a href=#insert-an-html-element>Insert an HTML element</a> for the token for which the element <var title="">entry</var> was created, to obtain <var title="">new element</var>.</li>
 
-   <li>Insert <var title="">new element</var> <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate
-   place">in the appropriate place</a> and push it onto the <a href=#stack-of-open-elements>stack of open elements</a>
-   so that it is the new <a href=#current-node>current node</a>.</li>
-
    <li>Replace the entry for <var title="">entry</var> in the list
    with an entry for <var title="">new element</var>.</li>
 
    <li>If the entry for <var title="">new element</var> in the
    <a href=#list-of-active-formatting-elements>list of active formatting elements</a> is not the last
-   entry in the list, return to step 7.</li>
+   entry in the list, return to the step labeled <i>advance</i>.</li>
 
   </ol><p>This has the effect of reopening all the formatting elements that
   were opened in the current body, cell, or caption (whichever is
@@ -88642,50 +88637,133 @@
 
   <h5 id=creating-and-inserting-nodes><span class=secno>12.2.5.1 </span>Creating and inserting nodes</h5>
 
-  <p>When the steps below require the UA to <dfn id=create-an-element-for-the-token title="create an element for the token">create an
-  element for a token</dfn> in a particular namespace, the UA must create a node implementing the
-  interface appropriate for the element type corresponding to the tag name of the token in the given
-  namespace (as given in the specification that defines that element, e.g. for an <code><a href=#the-a-element>a</a></code>
-  element in the <a href=#html-namespace-0>HTML namespace</a>, this specification defines it to be the
-  <code><a href=#htmlanchorelement>HTMLAnchorElement</a></code> interface), with the tag name being the name of that element, with
-  the node being in the given namespace, and with the attributes on the node being those given in
-  the given token.</p>
+  <p>The <dfn id=appropriate-place-for-inserting-a-node>appropriate place for inserting a node</dfn>, optionally using a particular
+  <i>override target</i>, is the position in an element returned by running the following steps:</p>
 
-  <p>The interface appropriate for an element in the <a href=#html-namespace-0>HTML namespace</a> that is not defined
-  in this specification (or <a href=#other-applicable-specifications>other applicable specifications</a>) is
-  <code><a href=#htmlunknownelement>HTMLUnknownElement</a></code>. Elements in other namespaces whose interface is not defined by
-  that namespace's specification must use the interface <code><a href=#element>Element</a></code>.</p>
+  <ol><li>
 
-  <p>When a <a href=#category-reset title=category-reset>resettable element</a> is created in this manner, its
-  <a href=#concept-form-reset-control title=concept-form-reset-control>reset algorithm</a> must be invoked once the
-  attributes are set. (This initializes the element's <a href=#concept-fe-value title=concept-fe-value>value</a>
-  and <a href=#concept-fe-checked title=concept-fe-checked>checkedness</a> based on the element's attributes.)</p>
+    <p>If there was an <i>override target</i> specified, then let <var title="">target</var> be the
+    <i>override target</i>.</p>
 
-  <hr><!-- The names of these algorithms are kinda confusing; e.g. see the confusion in
+    <p>Otherwise, let <var title="">target</var> be the <a href=#current-node>current node</a>.</p>
+
+   </li>
+
+   <li>
+
+    <p>Determine the <var title="">adjusted insertion location</var> using the first matching steps
+    from the following list:</p>
+
+    <dl class=switch><dt>If <dfn id=foster-parent title="foster parent">foster parenting</dfn> is enabled and <var title="">target</var> is a <code><a href=#the-table-element>table</a></code>, <code><a href=#the-tbody-element>tbody</a></code>, <code><a href=#the-tfoot-element>tfoot</a></code>,
+     <code><a href=#the-thead-element>thead</a></code>, or <code><a href=#the-tr-element>tr</a></code> element</dt>
+
+     <dd>
+
+      <p class=note>Foster parenting happens when content is misnested in tables.</p>
+
+      <p>The <dfn id=foster-parent-element>foster parent element</dfn> is the parent element of the last <code><a href=#the-table-element>table</a></code>
+      element in the <a href=#stack-of-open-elements>stack of open elements</a>, if there is a <code><a href=#the-table-element>table</a></code> element and
+      it has such a parent element.</p>
+
+      <p class=note>It might have no parent or some other kind parent if a script manipulated the
+      DOM after the element was inserted by the parser.</p>
+
+      <p>If there is no <code><a href=#the-table-element>table</a></code> element in the <a href=#stack-of-open-elements>stack of open elements</a>
+      (<a href=#fragment-case>fragment case</a>), then the <i><a href=#foster-parent-element>foster parent element</a></i> is the first element in the
+      <a href=#stack-of-open-elements>stack of open elements</a> (the <code><a href=#the-html-element>html</a></code> element). Otherwise, if there is a
+      <code><a href=#the-table-element>table</a></code> element in the <a href=#stack-of-open-elements>stack of open elements</a>, but the last
+      <code><a href=#the-table-element>table</a></code> element in the <a href=#stack-of-open-elements>stack of open elements</a> has no parent, or its
+      parent node is not an element, then the <i><a href=#foster-parent-element>foster parent element</a></i> is the element before the
+      last <code><a href=#the-table-element>table</a></code> element in the <a href=#stack-of-open-elements>stack of open elements</a>.</p>
+
+      <p>If the <i><a href=#foster-parent-element>foster parent element</a></i> is the parent element of the last <code><a href=#the-table-element>table</a></code>
+      element in the <a href=#stack-of-open-elements>stack of open elements</a>, then the <var title="">adjusted insertion
+      location</var> is inside the <i><a href=#foster-parent-element>foster parent element</a></i>, immediately <em>before</em> the
+      last <code><a href=#the-table-element>table</a></code> element in the <a href=#stack-of-open-elements>stack of open elements</a>; otherwise, the
+      <var title="">adjusted insertion location</var> is inside the <i><a href=#foster-parent-element>foster parent element</a></i>,
+      after its last child (if any).</p>
+
+     </dd>
+
+     <dt>Otherwise</dt>
+
+     <dd>
+
+      <p>The <var title="">adjusted insertion location</var> is inside <var title="">target</var>,
+      after its last child (if any).</p>
+
+     </dd>
+
+    </dl></li>
+
+   <li>
+
+    <p>Return the <var title="">adjusted insertion location</var>.</p>
+
+   </li>
+
+  </ol><hr><p>When the steps below require the UA to <dfn id=create-an-element-for-the-token title="create an element for the token">create an
+  element for a token</dfn> in a particular <var title="">given namespace</var> and with a
+  particular <var title="">intended parent</var>, the UA must run the following steps:</p>
+
+  <ol><li>
+
+    <p>Create a node implementing the interface appropriate for the element type corresponding to
+    the tag name of the token in <var title="">given namespace</var> (as given in the specification
+    that defines that element, e.g. for an <code><a href=#the-a-element>a</a></code> element in the <a href=#html-namespace-0>HTML
+    namespace</a>, this specification defines it to be the <code><a href=#htmlanchorelement>HTMLAnchorElement</a></code>
+    interface), with the tag name being the name of that element, with the node being in the given
+    namespace, and with the attributes on the node being those given in the given token.</p>
+
+    <p>The interface appropriate for an element in the <a href=#html-namespace-0>HTML namespace</a> that is not defined
+    in this specification (or <a href=#other-applicable-specifications>other applicable specifications</a>) is
+    <code><a href=#htmlunknownelement>HTMLUnknownElement</a></code>. Elements in other namespaces whose interface is not defined by
+    that namespace's specification must use the interface <code><a href=#element>Element</a></code>.</p>
+
+    <p>The <code title=dom-Node-ownerDocument><a href=#dom-node-ownerdocument>ownerDocument</a></code> of the newly created element
+    must be the same as that of the <var title="">intended parent</var>.</p>
+
+   </li>
+
+   <li>
+
+    <p>If the newly created element is a <a href=#category-reset title=category-reset>resettable element</a>,
+    invoke its <a href=#concept-form-reset-control title=concept-form-reset-control>reset algorithm</a>. (This initializes
+    the element's <a href=#concept-fe-value title=concept-fe-value>value</a> and <a href=#concept-fe-checked title=concept-fe-checked>checkedness</a> based on the element's attributes.)</p>
+
+   </li>
+
+   <li><p>Return the newly created element.</li>
+
+  </ol><hr><!-- The names of these algorithms are kinda confusing; e.g. see the confusion in
          https://www.w3.org/Bugs/Public/show_bug.cgi?id=18367
-       Not sure what we could call them instead, though... --><p>When the steps below require the UA to <dfn id=insert-an-html-element>insert an HTML element</dfn> for a token,
-  optionally in a specific place, the UA must run the following steps:</p>
+       Not sure what we could call them instead, though... --><p>When the steps below require the UA to <dfn id=insert-an-html-element>insert an HTML element</dfn> for a token, the UA
+  must run the following steps:</p>
 
-  <ol><li><p><a href=#create-an-element-for-the-token>Create an element for the token</a> in the <a href=#html-namespace-0>HTML namespace</a>.</li>
+  <ol><li><p>Let the <var title="">adjusted insertion location</var> be the <a href=#appropriate-place-for-inserting-a-node>appropriate
+   place for inserting a node</a>.</li>
 
+   <li><p><a href=#create-an-element-for-the-token>Create an element for the token</a> in the <a href=#html-namespace-0>HTML namespace</a>, with the
+   intended parent being the element in which the <var title="">adjusted insertion location</var>
+   finds itself.</li>
+
+   <!-- this could just as easily be in the "create..." algorithm I guess -->
    <li><p>If the element is a <a href=#form-associated-element>form-associated element</a>, and the <a href=#form-element-pointer><code title="">form</code> element pointer</a> is not null, and the newly created element doesn't
    have a <code title=attr-fae-form><a href=#attr-fae-form>form</a></code> attribute, <a href=#concept-form-association title=concept-form-association>associate</a> the newly created element with the
    <code><a href=#the-form-element>form</a></code> element pointed to by the <a href=#form-element-pointer><code title="">form</code> element
    pointer</a>, and suppress the running of the <a href=#reset-the-form-owner>reset the form owner</a> algorithm in
    the next step.</li>
 
-   <li><p>If no specific place has been specified, <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate
-   place">insert the node in the appropriate place</a>; otherwise, if a specific place has been
-   specified, insert or append the node as specified.</li>
+   <li><p>Insert the newly created element at the <var title="">adjusted insertion
+   location</var>.</li>
 
    <li><p>Push the element onto the <a href=#stack-of-open-elements>stack of open elements</a> so that it is the new
    <a href=#current-node>current node</a>.</li>
 
-  </ol><p class=note>A specific place is specified in in particular during the parsing of tables with
-  invalid content.</p>
+   <li><p>Return the newly created element.</li>
 
-  <hr><p>When the steps below require the UA to <dfn id=insert-a-foreign-element>insert a foreign element</dfn> for a token, the UA
-  must first <a href=#create-an-element-for-the-token>create an element for the token</a> in the given namespace, and then append
+  </ol><hr><p>When the steps below require the UA to <dfn id=insert-a-foreign-element>insert a foreign element</dfn> for a token, the UA
+  must first <a href=#create-an-element-for-the-token>create an element for the token</a> in the given namespace, with the <a href=#current-node>current node</a> as the intended parent, and then append
   this node to the <a href=#current-node>current node</a>, and push it onto the <a href=#stack-of-open-elements>stack of open
   elements</a> so that it is the new <a href=#current-node>current node</a>. If the newly created element has
   an <code title="">xmlns</code> attribute in the <a href=#xmlns-namespace>XMLNS namespace</a> whose value is not
@@ -88694,8 +88772,8 @@
   namespace</a> whose value is not the <a href=#xlink-namespace>XLink Namespace</a>, that is a <a href=#parse-error>parse
   error</a>.</p>
 
-  <p class=note>The <a href=#insert-a-foreign-element>insert a foreign element</a> algorithm isn't affected by the <a href=#foster-parent title="foster parent">foster parenting</a> logic (it doesn't use the <a href=#insert-a-node-in-the-appropriate-place>insert a node in the
-  appropriate place</a> algorithm); the <a href=#current-node>current node</a>, when the <a href=#insert-a-foreign-element>insert a
+  <p class=note>The <a href=#insert-a-foreign-element>insert a foreign element</a> algorithm isn't affected by the <a href=#foster-parent title="foster parent">foster parenting</a> logic (it doesn't use the <a href=#appropriate-place-for-inserting-a-node>appropriate place for
+  inserting a node</a> algorithm); the <a href=#current-node>current node</a>, when the <a href=#insert-a-foreign-element>insert a
   foreign element</a> algorithm is invoked, is always itself a non-HTML element.</p>
 
   <p>When the steps below require the user agent to <dfn id=adjust-mathml-attributes>adjust MathML attributes</dfn> for a token,
@@ -88792,98 +88870,30 @@
     <tr><td> <code title="">xml:space</code> <td> <code title="">xml</code> <td> <code title="">space</code> <td> <a href=#xml-namespace>XML namespace</a>
     <tr><td> <code title="">xmlns</code> <td> (none) <td> <code title="">xmlns</code> <td> <a href=#xmlns-namespace>XMLNS namespace</a>
     <tr><td> <code title="">xmlns:xlink</code> <td> <code title="">xmlns</code> <td> <code title="">xlink</code> <td> <a href=#xmlns-namespace>XMLNS namespace</a>
-  </table><hr><p>When the steps below require the user agent to <dfn id=insert-a-character>insert a character</dfn> for a token, the
-  user agent must insert it <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the appropriate
-  place</a>.</p>
+  </table><hr><p>When the steps below require the user agent to <dfn id=insert-a-character>insert a character</dfn> while processing a
+  token, the user agent must run the following steps:</p>
 
-  <hr><p>When the user agent is required to <dfn id=insert-a-node-in-the-appropriate-place>insert a node in the appropriate place</dfn>,
-  optionally using a particular <i>override target</i>, the user agent must follow the following
-  steps:</p>
+  <ol><li><p>Let <var title="">data</var> be the characters passed to the algorithm, or, if no
+   characters were explicitly specified, the character of the character token being
+   processed.</li>
 
-  <ol><li>
+   <li><p>Let the <var title="">adjusted insertion location</var> be the <a href=#appropriate-place-for-inserting-a-node>appropriate
+   place for inserting a node</a>.</li>
 
-    <p>If there was an <i>override target</i> specified, then let <var title="">target</var> be the
-    <i>override target</i>.</p>
-
-    <p>Otherwise, let <var title="">target</var> be the <a href=#current-node>current node</a>.</p>
-
-   </li>
-
    <li>
 
-    <p>Determine the <var title="">adjusted insertion location</var> using the first matching steps
-    from the following list:</p>
+    <p>If there is a <code><a href=#text>Text</a></code> node immediately before the <var title="">adjusted insertion
+    location</var>, then append <var title="">data</var> to that <code><a href=#text>Text</a></code> node's data.</p>
 
-    <dl class=switch><dt>If <dfn id=foster-parent title="foster parent">foster parenting</dfn> is enabled and <var title="">target</var> is a <code><a href=#the-table-element>table</a></code>, <code><a href=#the-tbody-element>tbody</a></code>, <code><a href=#the-tfoot-element>tfoot</a></code>,
-     <code><a href=#the-thead-element>thead</a></code>, or <code><a href=#the-tr-element>tr</a></code> element</dt>
+    <p>Otherwise, create a new <code><a href=#text>Text</a></code> node whose data is <var title="">data</var> and
+    whose <code title=dom-Node-ownerDocument><a href=#dom-node-ownerdocument>ownerDocument</a></code> is the same as that of the
+    element in which the <var title="">adjusted insertion location</var> finds itself, and insert
+    the newly created node at the <var title="">adjusted insertion location</var>.</p>
 
-     <dd>
+   </li>
 
-      <p class=note>Foster parenting happens when content is misnested in tables.</p>
+  </ol><div class=example>
 
-      <p>The <dfn id=foster-parent-element>foster parent element</dfn> is the parent element of the last <code><a href=#the-table-element>table</a></code>
-      element in the <a href=#stack-of-open-elements>stack of open elements</a>, if there is a <code><a href=#the-table-element>table</a></code> element and
-      it has such a parent element.</p>
-
-      <p class=note>It might have no parent or some other kind parent if a script manipulated the
-      DOM after the element was inserted by the parser.</p>
-
-      <p>If there is no <code><a href=#the-table-element>table</a></code> element in the <a href=#stack-of-open-elements>stack of open elements</a>
-      (<a href=#fragment-case>fragment case</a>), then the <i><a href=#foster-parent-element>foster parent element</a></i> is the first element in the
-      <a href=#stack-of-open-elements>stack of open elements</a> (the <code><a href=#the-html-element>html</a></code> element). Otherwise, if there is a
-      <code><a href=#the-table-element>table</a></code> element in the <a href=#stack-of-open-elements>stack of open elements</a>, but the last
-      <code><a href=#the-table-element>table</a></code> element in the <a href=#stack-of-open-elements>stack of open elements</a> has no parent, or its
-      parent node is not an element, then the <i><a href=#foster-parent-element>foster parent element</a></i> is the element before the
-      last <code><a href=#the-table-element>table</a></code> element in the <a href=#stack-of-open-elements>stack of open elements</a>.</p>
-
-      <p>If the <i><a href=#foster-parent-element>foster parent element</a></i> is the parent element of the last <code><a href=#the-table-element>table</a></code>
-      element in the <a href=#stack-of-open-elements>stack of open elements</a>, then the <var title="">adjusted insertion
-      location</var> is inside the <i><a href=#foster-parent-element>foster parent element</a></i>, immediately <em>before</em> the
-      last <code><a href=#the-table-element>table</a></code> element in the <a href=#stack-of-open-elements>stack of open elements</a>; otherwise, the
-      <var title="">adjusted insertion location</var> is inside the <i><a href=#foster-parent-element>foster parent element</a></i>,
-      after its last child (if any).</p>
-
-     </dd>
-
-     <dt>Otherwise</dt>
-
-     <dd>
-
-      <p>The <var title="">adjusted insertion location</var> is inside <var title="">target</var>,
-      after its last child (if any).</p>
-
-     </dd>
-
-    </dl></li>
-
-   <li>
-
-    <p>Run the first matching steps from the following list to actually perform the insertion:</p>
-
-    <dl class=switch><dt>If the node being inserted is a character</dt>
-
-     <dd>
-
-      <p>If there is a <code><a href=#text>Text</a></code> node immediately before the <var title="">adjusted
-      insertion location</var>, then append the character to that <code><a href=#text>Text</a></code> node.</p>
-
-      <p>Otherwise, create a new <code><a href=#text>Text</a></code> node whose data is just that character, and
-      insert it at the <var title="">adjusted insertion location</var>.</p>
-
-     </dd>
-
-     <dt>Otherwise</dt>
-
-     <dd>
-
-      <p>Insert the node at the <var title="">adjusted insertion location</var>.</p>
-
-     </dd>
-
-    </dl></li>
-
-  </ol><hr><div class=example>
-
    <p>Here are some sample inputs to the parser and the corresponding number of <code><a href=#text>Text</a></code>
    nodes that they result in, assuming a user agent that executes scripts.</p>
 
@@ -88912,7 +88922,26 @@
       <td>One <code><a href=#text>Text</a></code> node before the table, containing "A BC" (A-space-B-C), and one <code><a href=#text>Text</a></code> node inside the table (as a child of a <code><a href=#the-tbody-element>tbody</a></code>) with a single space character. (Space characters separated from non-space characters by non-character tokens are not affected by <a href=#foster-parent title="foster parent">foster parenting</a>, even if those other tokens then get ignored.)
    </table></div>
 
-  <p id=mutation-during-parsing>DOM mutation events must not fire for changes caused by the UA
+  <hr><p>When the steps below require the user agent to <dfn id=insert-a-comment>insert a comment</dfn> while processing a
+  comment token, optionally with an explicitly insertion position <var title="">position</var>, the
+  user agent must run the following steps:</p>
+
+  <ol><li><p>Let <var title="">data</var> be the data given in the comment token being
+   processed.</li>
+
+   <li><p>If <var title="">position</var> was specified, then let the <var title="">adjusted
+   insertion location</var> be <var title="">position</var>. Otherwise, let <var title="">adjusted
+   insertion location</var> be the <a href=#appropriate-place-for-inserting-a-node>appropriate place for inserting a node</a>.</li>
+
+   <li><p>Create a <code><a href=#comment-0>Comment</a></code> node whose <code title="">data</code> attribute is set to
+   <var title="">data</var> and whose <code title=dom-Node-ownerDocument><a href=#dom-node-ownerdocument>ownerDocument</a></code> is
+   the same as that of the node in which the <var title="">adjusted insertion location</var> finds
+   itself.</p>
+
+   <li><p>Insert the newly created node at the <var title="">adjusted insertion
+   location</var>.</li>
+
+  </ol><hr><p id=mutation-during-parsing>DOM mutation events must not fire for changes caused by the UA
   parsing the document. This includes the parsing of any content inserted using <code title=dom-document-write><a href=#dom-document-write>document.write()</a></code> and <code title=dom-document-writeln><a href=#dom-document-writeln>document.writeln()</a></code> calls. <a href=#refsDOMEVENTS>[DOMEVENTS]</a></p>
 
   <p>However, mutation observers <em>do</em> fire, as required by the DOM specification.</p>
@@ -88971,9 +89000,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node to the <code><a href=#document>Document</a></code>
-    object with the <code title="">data</code> attribute set to the
-    data given in the comment token.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a> as the last child of the <code><a href=#document>Document</a></code> object.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -89163,9 +89190,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node to the <code><a href=#document>Document</a></code>
-    object with the <code title="">data</code> attribute set to the
-    data given in the comment token.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a> as the last child of the <code><a href=#document>Document</a></code> object.</p>
    </dd>
 
    <dt>A character token that is one of U+0009 CHARACTER
@@ -89179,7 +89204,7 @@
    <dd>
 
     <p><a href=#create-an-element-for-the-token>Create an element for the token</a> in the <a href=#html-namespace-0>HTML
-    namespace</a>. Append it to the <code><a href=#document>Document</a></code>
+    namespace</a>, with the <code><a href=#document>Document</a></code> as the intended parent. Append it to the <code><a href=#document>Document</a></code>
     object. Put this element in the <a href=#stack-of-open-elements>stack of open
     elements</a>.</p>
 
@@ -89214,7 +89239,7 @@
    <dt>Anything else</dt>
    <dd>
 
-    <p>Create an <code><a href=#the-html-element>html</a></code> element. Append it to the
+    <p>Create an <code><a href=#the-html-element>html</a></code> element whose <code title=dom-Node-ownerDocument><a href=#dom-node-ownerdocument>ownerDocument</a></code> is the <code><a href=#document>Document</a></code> object. Append it to the
     <code><a href=#document>Document</a></code> object. Put this element in the <a href=#stack-of-open-elements>stack
     of open elements</a>.</p>
 
@@ -89247,9 +89272,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the
-    appropriate place</a>.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -89312,9 +89335,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the
-    appropriate place</a>.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -89391,9 +89412,13 @@
 
     <p>Run these steps:</p>
 
-    <ol><li><p><a href=#create-an-element-for-the-token>Create an element for the token</a> in the
-     <a href=#html-namespace-0>HTML namespace</a>.</li>
+    <ol><li><p>Let the <var title="">adjusted insertion location</var> be the <a href=#appropriate-place-for-inserting-a-node>appropriate
+     place for inserting a node</a>.</li>
 
+     <li><p><a href=#create-an-element-for-the-token>Create an element for the token</a> in the <a href=#html-namespace-0>HTML namespace</a>, with the
+     intended parent being the element in which the <var title="">adjusted insertion location</var>
+     finds itself.</li>
+
      <li>
 
       <p>Mark the element as being <a href=#parser-inserted>"parser-inserted"</a> and
@@ -89413,9 +89438,12 @@
      <code><a href=#the-script-element>script</a></code> element as <a href=#already-started>"already
      started"</a>. (<a href=#fragment-case>fragment case</a>)</li>
 
-     <li><p><a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">Insert the node in the appropriate
-     place</a>, and then push it onto the <a href=#stack-of-open-elements>stack of open elements</a>.</li>
+     <li><p>Insert the newly created element at the <var title="">adjusted insertion
+     location</var>.</li>
 
+     <li><p>Push the element onto the <a href=#stack-of-open-elements>stack of open elements</a> so that it is the new
+     <a href=#current-node>current node</a>.</li>
+
      <li><p>Switch the tokenizer to the <a href=#script-data-state>script data
      state</a>.</li>
 
@@ -89531,9 +89559,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the
-    appropriate place</a>.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -89653,9 +89679,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the
-    appropriate place</a>.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -90338,7 +90362,7 @@
        in the overall algorithm.</li>
 
        <li><a href=#create-an-element-for-the-token>Create an element for the token</a> for which the
-       element <var title="">node</var> was created, replace the entry
+       element <var title="">node</var> was created, with <var title="">common ancestor</var> as the intended parent; replace the entry
        for <var title="">node</var> in the <a href=#list-of-active-formatting-elements>list of active
        formatting elements</a> with an entry for the new element,
        replace the entry for <var title="">node</var> in the
@@ -90359,10 +90383,12 @@
 
       </ol></li>
 
-     <li><p>Insert whatever <var title="">last node</var> ended up being in the previous step <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the appropriate place</a>, but using <var title="">common ancestor</var> as the <i>override target</i>.</li>
+     <li><p>Insert whatever <var title="">last node</var> ended up being in the previous step at the <a href=#appropriate-place-for-inserting-a-node>appropriate
+     place for inserting a node</a>, but using <var title="">common ancestor</var> as the <i>override target</i>.</li>
 
      <li><p><a href=#create-an-element-for-the-token>Create an element for the token</a> for which the
-     <var title="">formatting element</var> was created.</li>
+     <var title="">formatting element</var> was created, with <var title="">furthest
+     block</var> as the intended parent.</li>
 
      <li><p>Take all of the child nodes of the <var title="">furthest
      block</var> and append them to the element created in the last
@@ -91016,9 +91042,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the
-    appropriate place</a>.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -91322,9 +91346,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the
-    appropriate place</a>.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -91682,9 +91704,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the
-    appropriate place</a>.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -91860,10 +91880,9 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node to the first element in
+    <p><a href=#insert-a-comment>Insert a comment</a> as the last child of the first element in
     the <a href=#stack-of-open-elements>stack of open elements</a> (the <code><a href=#the-html-element>html</a></code>
-    element), with the <code title="">data</code> attribute set to
-    the data given in the comment token.</p>
+    element).</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -91916,9 +91935,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the
-    appropriate place</a>.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -92008,9 +92025,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the
-    appropriate place</a>.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -92052,9 +92067,7 @@
 
   <dl class=switch><dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node to the <code><a href=#document>Document</a></code>
-    object with the <code title="">data</code> attribute set to the
-    data given in the comment token.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a> as the last child of the <code><a href=#document>Document</a></code> object.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -92085,9 +92098,7 @@
 
   <dl class=switch><dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node to the <code><a href=#document>Document</a></code>
-    object with the <code title="">data</code> attribute set to the
-    data given in the comment token.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a> as the last child of the <code><a href=#document>Document</a></code> object.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -92148,9 +92159,7 @@
    <dt>A comment token</dt>
    <dd>
 
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the
-    appropriate place</a>.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a>.</p>
 
    </dd>
 

Modified: index
===================================================================
--- index	2013-06-25 05:37:58 UTC (rev 7998)
+++ index	2013-06-25 20:55:18 UTC (rev 7999)
@@ -86301,7 +86301,7 @@
   active formatting elements</dfn>, the UA must perform the following
   steps:</p>
 
-  <ol><li>If there are no entries in the <a href=#list-of-active-formatting-elements>list of active formatting
+  <ol><!--CLEANUP--><!--<p>s--><li>If there are no entries in the <a href=#list-of-active-formatting-elements>list of active formatting
    elements</a>, then there is nothing to reconstruct; stop this
    algorithm.</li>
 
@@ -86314,35 +86314,30 @@
    element in the <a href=#list-of-active-formatting-elements>list of active formatting
    elements</a>.</li>
 
-   <li>If there are no entries before <var title="">entry</var> in the
-   <a href=#list-of-active-formatting-elements>list of active formatting elements</a>, then jump to step
-   8.</li>
+   <li><i>Rewind</i>: If there are no entries before <var title="">entry</var> in the
+   <a href=#list-of-active-formatting-elements>list of active formatting elements</a>, then jump to the step
+   labeled <i>create</i>.</li>
 
    <li>Let <var title="">entry</var> be the entry one earlier than
    <var title="">entry</var> in the <a href=#list-of-active-formatting-elements>list of active formatting
    elements</a>.</li>
 
    <li>If <var title="">entry</var> is neither a marker nor an element
-   that is also in the <a href=#stack-of-open-elements>stack of open elements</a>, go to step
-   4.</li>
+   that is also in the <a href=#stack-of-open-elements>stack of open elements</a>, go to the step labeled
+   <i>rewind</i>.</li>
 
-   <li>Let <var title="">entry</var> be the element one later than
+   <li><i>Advance</i>: Let <var title="">entry</var> be the element one later than
    <var title="">entry</var> in the <a href=#list-of-active-formatting-elements>list of active formatting
    elements</a>.</li>
 
-   <li><a href=#create-an-element-for-the-token>Create an element for the token</a> for which the
-   element <var title="">entry</var> was created, to obtain <var title="">new element</var>.</li>
+   <li><i>Create</i>: <a href=#insert-an-html-element>Insert an HTML element</a> for the token for which the element <var title="">entry</var> was created, to obtain <var title="">new element</var>.</li>
 
-   <li>Insert <var title="">new element</var> <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate
-   place">in the appropriate place</a> and push it onto the <a href=#stack-of-open-elements>stack of open elements</a>
-   so that it is the new <a href=#current-node>current node</a>.</li>
-
    <li>Replace the entry for <var title="">entry</var> in the list
    with an entry for <var title="">new element</var>.</li>
 
    <li>If the entry for <var title="">new element</var> in the
    <a href=#list-of-active-formatting-elements>list of active formatting elements</a> is not the last
-   entry in the list, return to step 7.</li>
+   entry in the list, return to the step labeled <i>advance</i>.</li>
 
   </ol><p>This has the effect of reopening all the formatting elements that
   were opened in the current body, cell, or caption (whichever is
@@ -88642,50 +88637,133 @@
 
   <h5 id=creating-and-inserting-nodes><span class=secno>12.2.5.1 </span>Creating and inserting nodes</h5>
 
-  <p>When the steps below require the UA to <dfn id=create-an-element-for-the-token title="create an element for the token">create an
-  element for a token</dfn> in a particular namespace, the UA must create a node implementing the
-  interface appropriate for the element type corresponding to the tag name of the token in the given
-  namespace (as given in the specification that defines that element, e.g. for an <code><a href=#the-a-element>a</a></code>
-  element in the <a href=#html-namespace-0>HTML namespace</a>, this specification defines it to be the
-  <code><a href=#htmlanchorelement>HTMLAnchorElement</a></code> interface), with the tag name being the name of that element, with
-  the node being in the given namespace, and with the attributes on the node being those given in
-  the given token.</p>
+  <p>The <dfn id=appropriate-place-for-inserting-a-node>appropriate place for inserting a node</dfn>, optionally using a particular
+  <i>override target</i>, is the position in an element returned by running the following steps:</p>
 
-  <p>The interface appropriate for an element in the <a href=#html-namespace-0>HTML namespace</a> that is not defined
-  in this specification (or <a href=#other-applicable-specifications>other applicable specifications</a>) is
-  <code><a href=#htmlunknownelement>HTMLUnknownElement</a></code>. Elements in other namespaces whose interface is not defined by
-  that namespace's specification must use the interface <code><a href=#element>Element</a></code>.</p>
+  <ol><li>
 
-  <p>When a <a href=#category-reset title=category-reset>resettable element</a> is created in this manner, its
-  <a href=#concept-form-reset-control title=concept-form-reset-control>reset algorithm</a> must be invoked once the
-  attributes are set. (This initializes the element's <a href=#concept-fe-value title=concept-fe-value>value</a>
-  and <a href=#concept-fe-checked title=concept-fe-checked>checkedness</a> based on the element's attributes.)</p>
+    <p>If there was an <i>override target</i> specified, then let <var title="">target</var> be the
+    <i>override target</i>.</p>
 
-  <hr><!-- The names of these algorithms are kinda confusing; e.g. see the confusion in
+    <p>Otherwise, let <var title="">target</var> be the <a href=#current-node>current node</a>.</p>
+
+   </li>
+
+   <li>
+
+    <p>Determine the <var title="">adjusted insertion location</var> using the first matching steps
+    from the following list:</p>
+
+    <dl class=switch><dt>If <dfn id=foster-parent title="foster parent">foster parenting</dfn> is enabled and <var title="">target</var> is a <code><a href=#the-table-element>table</a></code>, <code><a href=#the-tbody-element>tbody</a></code>, <code><a href=#the-tfoot-element>tfoot</a></code>,
+     <code><a href=#the-thead-element>thead</a></code>, or <code><a href=#the-tr-element>tr</a></code> element</dt>
+
+     <dd>
+
+      <p class=note>Foster parenting happens when content is misnested in tables.</p>
+
+      <p>The <dfn id=foster-parent-element>foster parent element</dfn> is the parent element of the last <code><a href=#the-table-element>table</a></code>
+      element in the <a href=#stack-of-open-elements>stack of open elements</a>, if there is a <code><a href=#the-table-element>table</a></code> element and
+      it has such a parent element.</p>
+
+      <p class=note>It might have no parent or some other kind parent if a script manipulated the
+      DOM after the element was inserted by the parser.</p>
+
+      <p>If there is no <code><a href=#the-table-element>table</a></code> element in the <a href=#stack-of-open-elements>stack of open elements</a>
+      (<a href=#fragment-case>fragment case</a>), then the <i><a href=#foster-parent-element>foster parent element</a></i> is the first element in the
+      <a href=#stack-of-open-elements>stack of open elements</a> (the <code><a href=#the-html-element>html</a></code> element). Otherwise, if there is a
+      <code><a href=#the-table-element>table</a></code> element in the <a href=#stack-of-open-elements>stack of open elements</a>, but the last
+      <code><a href=#the-table-element>table</a></code> element in the <a href=#stack-of-open-elements>stack of open elements</a> has no parent, or its
+      parent node is not an element, then the <i><a href=#foster-parent-element>foster parent element</a></i> is the element before the
+      last <code><a href=#the-table-element>table</a></code> element in the <a href=#stack-of-open-elements>stack of open elements</a>.</p>
+
+      <p>If the <i><a href=#foster-parent-element>foster parent element</a></i> is the parent element of the last <code><a href=#the-table-element>table</a></code>
+      element in the <a href=#stack-of-open-elements>stack of open elements</a>, then the <var title="">adjusted insertion
+      location</var> is inside the <i><a href=#foster-parent-element>foster parent element</a></i>, immediately <em>before</em> the
+      last <code><a href=#the-table-element>table</a></code> element in the <a href=#stack-of-open-elements>stack of open elements</a>; otherwise, the
+      <var title="">adjusted insertion location</var> is inside the <i><a href=#foster-parent-element>foster parent element</a></i>,
+      after its last child (if any).</p>
+
+     </dd>
+
+     <dt>Otherwise</dt>
+
+     <dd>
+
+      <p>The <var title="">adjusted insertion location</var> is inside <var title="">target</var>,
+      after its last child (if any).</p>
+
+     </dd>
+
+    </dl></li>
+
+   <li>
+
+    <p>Return the <var title="">adjusted insertion location</var>.</p>
+
+   </li>
+
+  </ol><hr><p>When the steps below require the UA to <dfn id=create-an-element-for-the-token title="create an element for the token">create an
+  element for a token</dfn> in a particular <var title="">given namespace</var> and with a
+  particular <var title="">intended parent</var>, the UA must run the following steps:</p>
+
+  <ol><li>
+
+    <p>Create a node implementing the interface appropriate for the element type corresponding to
+    the tag name of the token in <var title="">given namespace</var> (as given in the specification
+    that defines that element, e.g. for an <code><a href=#the-a-element>a</a></code> element in the <a href=#html-namespace-0>HTML
+    namespace</a>, this specification defines it to be the <code><a href=#htmlanchorelement>HTMLAnchorElement</a></code>
+    interface), with the tag name being the name of that element, with the node being in the given
+    namespace, and with the attributes on the node being those given in the given token.</p>
+
+    <p>The interface appropriate for an element in the <a href=#html-namespace-0>HTML namespace</a> that is not defined
+    in this specification (or <a href=#other-applicable-specifications>other applicable specifications</a>) is
+    <code><a href=#htmlunknownelement>HTMLUnknownElement</a></code>. Elements in other namespaces whose interface is not defined by
+    that namespace's specification must use the interface <code><a href=#element>Element</a></code>.</p>
+
+    <p>The <code title=dom-Node-ownerDocument><a href=#dom-node-ownerdocument>ownerDocument</a></code> of the newly created element
+    must be the same as that of the <var title="">intended parent</var>.</p>
+
+   </li>
+
+   <li>
+
+    <p>If the newly created element is a <a href=#category-reset title=category-reset>resettable element</a>,
+    invoke its <a href=#concept-form-reset-control title=concept-form-reset-control>reset algorithm</a>. (This initializes
+    the element's <a href=#concept-fe-value title=concept-fe-value>value</a> and <a href=#concept-fe-checked title=concept-fe-checked>checkedness</a> based on the element's attributes.)</p>
+
+   </li>
+
+   <li><p>Return the newly created element.</li>
+
+  </ol><hr><!-- The names of these algorithms are kinda confusing; e.g. see the confusion in
          https://www.w3.org/Bugs/Public/show_bug.cgi?id=18367
-       Not sure what we could call them instead, though... --><p>When the steps below require the UA to <dfn id=insert-an-html-element>insert an HTML element</dfn> for a token,
-  optionally in a specific place, the UA must run the following steps:</p>
+       Not sure what we could call them instead, though... --><p>When the steps below require the UA to <dfn id=insert-an-html-element>insert an HTML element</dfn> for a token, the UA
+  must run the following steps:</p>
 
-  <ol><li><p><a href=#create-an-element-for-the-token>Create an element for the token</a> in the <a href=#html-namespace-0>HTML namespace</a>.</li>
+  <ol><li><p>Let the <var title="">adjusted insertion location</var> be the <a href=#appropriate-place-for-inserting-a-node>appropriate
+   place for inserting a node</a>.</li>
 
+   <li><p><a href=#create-an-element-for-the-token>Create an element for the token</a> in the <a href=#html-namespace-0>HTML namespace</a>, with the
+   intended parent being the element in which the <var title="">adjusted insertion location</var>
+   finds itself.</li>
+
+   <!-- this could just as easily be in the "create..." algorithm I guess -->
    <li><p>If the element is a <a href=#form-associated-element>form-associated element</a>, and the <a href=#form-element-pointer><code title="">form</code> element pointer</a> is not null, and the newly created element doesn't
    have a <code title=attr-fae-form><a href=#attr-fae-form>form</a></code> attribute, <a href=#concept-form-association title=concept-form-association>associate</a> the newly created element with the
    <code><a href=#the-form-element>form</a></code> element pointed to by the <a href=#form-element-pointer><code title="">form</code> element
    pointer</a>, and suppress the running of the <a href=#reset-the-form-owner>reset the form owner</a> algorithm in
    the next step.</li>
 
-   <li><p>If no specific place has been specified, <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate
-   place">insert the node in the appropriate place</a>; otherwise, if a specific place has been
-   specified, insert or append the node as specified.</li>
+   <li><p>Insert the newly created element at the <var title="">adjusted insertion
+   location</var>.</li>
 
    <li><p>Push the element onto the <a href=#stack-of-open-elements>stack of open elements</a> so that it is the new
    <a href=#current-node>current node</a>.</li>
 
-  </ol><p class=note>A specific place is specified in in particular during the parsing of tables with
-  invalid content.</p>
+   <li><p>Return the newly created element.</li>
 
-  <hr><p>When the steps below require the UA to <dfn id=insert-a-foreign-element>insert a foreign element</dfn> for a token, the UA
-  must first <a href=#create-an-element-for-the-token>create an element for the token</a> in the given namespace, and then append
+  </ol><hr><p>When the steps below require the UA to <dfn id=insert-a-foreign-element>insert a foreign element</dfn> for a token, the UA
+  must first <a href=#create-an-element-for-the-token>create an element for the token</a> in the given namespace, with the <a href=#current-node>current node</a> as the intended parent, and then append
   this node to the <a href=#current-node>current node</a>, and push it onto the <a href=#stack-of-open-elements>stack of open
   elements</a> so that it is the new <a href=#current-node>current node</a>. If the newly created element has
   an <code title="">xmlns</code> attribute in the <a href=#xmlns-namespace>XMLNS namespace</a> whose value is not
@@ -88694,8 +88772,8 @@
   namespace</a> whose value is not the <a href=#xlink-namespace>XLink Namespace</a>, that is a <a href=#parse-error>parse
   error</a>.</p>
 
-  <p class=note>The <a href=#insert-a-foreign-element>insert a foreign element</a> algorithm isn't affected by the <a href=#foster-parent title="foster parent">foster parenting</a> logic (it doesn't use the <a href=#insert-a-node-in-the-appropriate-place>insert a node in the
-  appropriate place</a> algorithm); the <a href=#current-node>current node</a>, when the <a href=#insert-a-foreign-element>insert a
+  <p class=note>The <a href=#insert-a-foreign-element>insert a foreign element</a> algorithm isn't affected by the <a href=#foster-parent title="foster parent">foster parenting</a> logic (it doesn't use the <a href=#appropriate-place-for-inserting-a-node>appropriate place for
+  inserting a node</a> algorithm); the <a href=#current-node>current node</a>, when the <a href=#insert-a-foreign-element>insert a
   foreign element</a> algorithm is invoked, is always itself a non-HTML element.</p>
 
   <p>When the steps below require the user agent to <dfn id=adjust-mathml-attributes>adjust MathML attributes</dfn> for a token,
@@ -88792,98 +88870,30 @@
     <tr><td> <code title="">xml:space</code> <td> <code title="">xml</code> <td> <code title="">space</code> <td> <a href=#xml-namespace>XML namespace</a>
     <tr><td> <code title="">xmlns</code> <td> (none) <td> <code title="">xmlns</code> <td> <a href=#xmlns-namespace>XMLNS namespace</a>
     <tr><td> <code title="">xmlns:xlink</code> <td> <code title="">xmlns</code> <td> <code title="">xlink</code> <td> <a href=#xmlns-namespace>XMLNS namespace</a>
-  </table><hr><p>When the steps below require the user agent to <dfn id=insert-a-character>insert a character</dfn> for a token, the
-  user agent must insert it <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the appropriate
-  place</a>.</p>
+  </table><hr><p>When the steps below require the user agent to <dfn id=insert-a-character>insert a character</dfn> while processing a
+  token, the user agent must run the following steps:</p>
 
-  <hr><p>When the user agent is required to <dfn id=insert-a-node-in-the-appropriate-place>insert a node in the appropriate place</dfn>,
-  optionally using a particular <i>override target</i>, the user agent must follow the following
-  steps:</p>
+  <ol><li><p>Let <var title="">data</var> be the characters passed to the algorithm, or, if no
+   characters were explicitly specified, the character of the character token being
+   processed.</li>
 
-  <ol><li>
+   <li><p>Let the <var title="">adjusted insertion location</var> be the <a href=#appropriate-place-for-inserting-a-node>appropriate
+   place for inserting a node</a>.</li>
 
-    <p>If there was an <i>override target</i> specified, then let <var title="">target</var> be the
-    <i>override target</i>.</p>
-
-    <p>Otherwise, let <var title="">target</var> be the <a href=#current-node>current node</a>.</p>
-
-   </li>
-
    <li>
 
-    <p>Determine the <var title="">adjusted insertion location</var> using the first matching steps
-    from the following list:</p>
+    <p>If there is a <code><a href=#text>Text</a></code> node immediately before the <var title="">adjusted insertion
+    location</var>, then append <var title="">data</var> to that <code><a href=#text>Text</a></code> node's data.</p>
 
-    <dl class=switch><dt>If <dfn id=foster-parent title="foster parent">foster parenting</dfn> is enabled and <var title="">target</var> is a <code><a href=#the-table-element>table</a></code>, <code><a href=#the-tbody-element>tbody</a></code>, <code><a href=#the-tfoot-element>tfoot</a></code>,
-     <code><a href=#the-thead-element>thead</a></code>, or <code><a href=#the-tr-element>tr</a></code> element</dt>
+    <p>Otherwise, create a new <code><a href=#text>Text</a></code> node whose data is <var title="">data</var> and
+    whose <code title=dom-Node-ownerDocument><a href=#dom-node-ownerdocument>ownerDocument</a></code> is the same as that of the
+    element in which the <var title="">adjusted insertion location</var> finds itself, and insert
+    the newly created node at the <var title="">adjusted insertion location</var>.</p>
 
-     <dd>
+   </li>
 
-      <p class=note>Foster parenting happens when content is misnested in tables.</p>
+  </ol><div class=example>
 
-      <p>The <dfn id=foster-parent-element>foster parent element</dfn> is the parent element of the last <code><a href=#the-table-element>table</a></code>
-      element in the <a href=#stack-of-open-elements>stack of open elements</a>, if there is a <code><a href=#the-table-element>table</a></code> element and
-      it has such a parent element.</p>
-
-      <p class=note>It might have no parent or some other kind parent if a script manipulated the
-      DOM after the element was inserted by the parser.</p>
-
-      <p>If there is no <code><a href=#the-table-element>table</a></code> element in the <a href=#stack-of-open-elements>stack of open elements</a>
-      (<a href=#fragment-case>fragment case</a>), then the <i><a href=#foster-parent-element>foster parent element</a></i> is the first element in the
-      <a href=#stack-of-open-elements>stack of open elements</a> (the <code><a href=#the-html-element>html</a></code> element). Otherwise, if there is a
-      <code><a href=#the-table-element>table</a></code> element in the <a href=#stack-of-open-elements>stack of open elements</a>, but the last
-      <code><a href=#the-table-element>table</a></code> element in the <a href=#stack-of-open-elements>stack of open elements</a> has no parent, or its
-      parent node is not an element, then the <i><a href=#foster-parent-element>foster parent element</a></i> is the element before the
-      last <code><a href=#the-table-element>table</a></code> element in the <a href=#stack-of-open-elements>stack of open elements</a>.</p>
-
-      <p>If the <i><a href=#foster-parent-element>foster parent element</a></i> is the parent element of the last <code><a href=#the-table-element>table</a></code>
-      element in the <a href=#stack-of-open-elements>stack of open elements</a>, then the <var title="">adjusted insertion
-      location</var> is inside the <i><a href=#foster-parent-element>foster parent element</a></i>, immediately <em>before</em> the
-      last <code><a href=#the-table-element>table</a></code> element in the <a href=#stack-of-open-elements>stack of open elements</a>; otherwise, the
-      <var title="">adjusted insertion location</var> is inside the <i><a href=#foster-parent-element>foster parent element</a></i>,
-      after its last child (if any).</p>
-
-     </dd>
-
-     <dt>Otherwise</dt>
-
-     <dd>
-
-      <p>The <var title="">adjusted insertion location</var> is inside <var title="">target</var>,
-      after its last child (if any).</p>
-
-     </dd>
-
-    </dl></li>
-
-   <li>
-
-    <p>Run the first matching steps from the following list to actually perform the insertion:</p>
-
-    <dl class=switch><dt>If the node being inserted is a character</dt>
-
-     <dd>
-
-      <p>If there is a <code><a href=#text>Text</a></code> node immediately before the <var title="">adjusted
-      insertion location</var>, then append the character to that <code><a href=#text>Text</a></code> node.</p>
-
-      <p>Otherwise, create a new <code><a href=#text>Text</a></code> node whose data is just that character, and
-      insert it at the <var title="">adjusted insertion location</var>.</p>
-
-     </dd>
-
-     <dt>Otherwise</dt>
-
-     <dd>
-
-      <p>Insert the node at the <var title="">adjusted insertion location</var>.</p>
-
-     </dd>
-
-    </dl></li>
-
-  </ol><hr><div class=example>
-
    <p>Here are some sample inputs to the parser and the corresponding number of <code><a href=#text>Text</a></code>
    nodes that they result in, assuming a user agent that executes scripts.</p>
 
@@ -88912,7 +88922,26 @@
       <td>One <code><a href=#text>Text</a></code> node before the table, containing "A BC" (A-space-B-C), and one <code><a href=#text>Text</a></code> node inside the table (as a child of a <code><a href=#the-tbody-element>tbody</a></code>) with a single space character. (Space characters separated from non-space characters by non-character tokens are not affected by <a href=#foster-parent title="foster parent">foster parenting</a>, even if those other tokens then get ignored.)
    </table></div>
 
-  <p id=mutation-during-parsing>DOM mutation events must not fire for changes caused by the UA
+  <hr><p>When the steps below require the user agent to <dfn id=insert-a-comment>insert a comment</dfn> while processing a
+  comment token, optionally with an explicitly insertion position <var title="">position</var>, the
+  user agent must run the following steps:</p>
+
+  <ol><li><p>Let <var title="">data</var> be the data given in the comment token being
+   processed.</li>
+
+   <li><p>If <var title="">position</var> was specified, then let the <var title="">adjusted
+   insertion location</var> be <var title="">position</var>. Otherwise, let <var title="">adjusted
+   insertion location</var> be the <a href=#appropriate-place-for-inserting-a-node>appropriate place for inserting a node</a>.</li>
+
+   <li><p>Create a <code><a href=#comment-0>Comment</a></code> node whose <code title="">data</code> attribute is set to
+   <var title="">data</var> and whose <code title=dom-Node-ownerDocument><a href=#dom-node-ownerdocument>ownerDocument</a></code> is
+   the same as that of the node in which the <var title="">adjusted insertion location</var> finds
+   itself.</p>
+
+   <li><p>Insert the newly created node at the <var title="">adjusted insertion
+   location</var>.</li>
+
+  </ol><hr><p id=mutation-during-parsing>DOM mutation events must not fire for changes caused by the UA
   parsing the document. This includes the parsing of any content inserted using <code title=dom-document-write><a href=#dom-document-write>document.write()</a></code> and <code title=dom-document-writeln><a href=#dom-document-writeln>document.writeln()</a></code> calls. <a href=#refsDOMEVENTS>[DOMEVENTS]</a></p>
 
   <p>However, mutation observers <em>do</em> fire, as required by the DOM specification.</p>
@@ -88971,9 +89000,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node to the <code><a href=#document>Document</a></code>
-    object with the <code title="">data</code> attribute set to the
-    data given in the comment token.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a> as the last child of the <code><a href=#document>Document</a></code> object.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -89163,9 +89190,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node to the <code><a href=#document>Document</a></code>
-    object with the <code title="">data</code> attribute set to the
-    data given in the comment token.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a> as the last child of the <code><a href=#document>Document</a></code> object.</p>
    </dd>
 
    <dt>A character token that is one of U+0009 CHARACTER
@@ -89179,7 +89204,7 @@
    <dd>
 
     <p><a href=#create-an-element-for-the-token>Create an element for the token</a> in the <a href=#html-namespace-0>HTML
-    namespace</a>. Append it to the <code><a href=#document>Document</a></code>
+    namespace</a>, with the <code><a href=#document>Document</a></code> as the intended parent. Append it to the <code><a href=#document>Document</a></code>
     object. Put this element in the <a href=#stack-of-open-elements>stack of open
     elements</a>.</p>
 
@@ -89214,7 +89239,7 @@
    <dt>Anything else</dt>
    <dd>
 
-    <p>Create an <code><a href=#the-html-element>html</a></code> element. Append it to the
+    <p>Create an <code><a href=#the-html-element>html</a></code> element whose <code title=dom-Node-ownerDocument><a href=#dom-node-ownerdocument>ownerDocument</a></code> is the <code><a href=#document>Document</a></code> object. Append it to the
     <code><a href=#document>Document</a></code> object. Put this element in the <a href=#stack-of-open-elements>stack
     of open elements</a>.</p>
 
@@ -89247,9 +89272,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the
-    appropriate place</a>.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -89312,9 +89335,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the
-    appropriate place</a>.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -89391,9 +89412,13 @@
 
     <p>Run these steps:</p>
 
-    <ol><li><p><a href=#create-an-element-for-the-token>Create an element for the token</a> in the
-     <a href=#html-namespace-0>HTML namespace</a>.</li>
+    <ol><li><p>Let the <var title="">adjusted insertion location</var> be the <a href=#appropriate-place-for-inserting-a-node>appropriate
+     place for inserting a node</a>.</li>
 
+     <li><p><a href=#create-an-element-for-the-token>Create an element for the token</a> in the <a href=#html-namespace-0>HTML namespace</a>, with the
+     intended parent being the element in which the <var title="">adjusted insertion location</var>
+     finds itself.</li>
+
      <li>
 
       <p>Mark the element as being <a href=#parser-inserted>"parser-inserted"</a> and
@@ -89413,9 +89438,12 @@
      <code><a href=#the-script-element>script</a></code> element as <a href=#already-started>"already
      started"</a>. (<a href=#fragment-case>fragment case</a>)</li>
 
-     <li><p><a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">Insert the node in the appropriate
-     place</a>, and then push it onto the <a href=#stack-of-open-elements>stack of open elements</a>.</li>
+     <li><p>Insert the newly created element at the <var title="">adjusted insertion
+     location</var>.</li>
 
+     <li><p>Push the element onto the <a href=#stack-of-open-elements>stack of open elements</a> so that it is the new
+     <a href=#current-node>current node</a>.</li>
+
      <li><p>Switch the tokenizer to the <a href=#script-data-state>script data
      state</a>.</li>
 
@@ -89531,9 +89559,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the
-    appropriate place</a>.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -89653,9 +89679,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the
-    appropriate place</a>.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -90338,7 +90362,7 @@
        in the overall algorithm.</li>
 
        <li><a href=#create-an-element-for-the-token>Create an element for the token</a> for which the
-       element <var title="">node</var> was created, replace the entry
+       element <var title="">node</var> was created, with <var title="">common ancestor</var> as the intended parent; replace the entry
        for <var title="">node</var> in the <a href=#list-of-active-formatting-elements>list of active
        formatting elements</a> with an entry for the new element,
        replace the entry for <var title="">node</var> in the
@@ -90359,10 +90383,12 @@
 
       </ol></li>
 
-     <li><p>Insert whatever <var title="">last node</var> ended up being in the previous step <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the appropriate place</a>, but using <var title="">common ancestor</var> as the <i>override target</i>.</li>
+     <li><p>Insert whatever <var title="">last node</var> ended up being in the previous step at the <a href=#appropriate-place-for-inserting-a-node>appropriate
+     place for inserting a node</a>, but using <var title="">common ancestor</var> as the <i>override target</i>.</li>
 
      <li><p><a href=#create-an-element-for-the-token>Create an element for the token</a> for which the
-     <var title="">formatting element</var> was created.</li>
+     <var title="">formatting element</var> was created, with <var title="">furthest
+     block</var> as the intended parent.</li>
 
      <li><p>Take all of the child nodes of the <var title="">furthest
      block</var> and append them to the element created in the last
@@ -91016,9 +91042,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the
-    appropriate place</a>.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -91322,9 +91346,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the
-    appropriate place</a>.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -91682,9 +91704,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the
-    appropriate place</a>.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -91860,10 +91880,9 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node to the first element in
+    <p><a href=#insert-a-comment>Insert a comment</a> as the last child of the first element in
     the <a href=#stack-of-open-elements>stack of open elements</a> (the <code><a href=#the-html-element>html</a></code>
-    element), with the <code title="">data</code> attribute set to
-    the data given in the comment token.</p>
+    element).</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -91916,9 +91935,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the
-    appropriate place</a>.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -92008,9 +92025,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the
-    appropriate place</a>.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -92052,9 +92067,7 @@
 
   <dl class=switch><dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node to the <code><a href=#document>Document</a></code>
-    object with the <code title="">data</code> attribute set to the
-    data given in the comment token.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a> as the last child of the <code><a href=#document>Document</a></code> object.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -92085,9 +92098,7 @@
 
   <dl class=switch><dt>A comment token</dt>
    <dd>
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node to the <code><a href=#document>Document</a></code>
-    object with the <code title="">data</code> attribute set to the
-    data given in the comment token.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a> as the last child of the <code><a href=#document>Document</a></code> object.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -92148,9 +92159,7 @@
    <dt>A comment token</dt>
    <dd>
 
-    <p>Append a <code><a href=#comment-0>Comment</a></code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <a href=#insert-a-node-in-the-appropriate-place title="insert a node in the appropriate place">in the
-    appropriate place</a>.</p>
+    <p><a href=#insert-a-comment>Insert a comment</a>.</p>
 
    </dd>
 

Modified: source
===================================================================
--- source	2013-06-25 05:37:58 UTC (rev 7998)
+++ source	2013-06-25 20:55:18 UTC (rev 7999)
@@ -96336,6 +96336,7 @@
 
   <ol>
 
+<!--CLEANUP--><!--<p>s-->
    <li>If there are no entries in the <span>list of active formatting
    elements</span>, then there is nothing to reconstruct; stop this
    algorithm.</li>
@@ -96349,36 +96350,31 @@
    element in the <span>list of active formatting
    elements</span>.</li>
 
-   <li>If there are no entries before <var title="">entry</var> in the
-   <span>list of active formatting elements</span>, then jump to step
-   8.</li>
+   <li><i>Rewind</i>: If there are no entries before <var title="">entry</var> in the
+   <span>list of active formatting elements</span>, then jump to the step
+   labeled <i>create</i>.</li>
 
    <li>Let <var title="">entry</var> be the entry one earlier than
    <var title="">entry</var> in the <span>list of active formatting
    elements</span>.</li>
 
    <li>If <var title="">entry</var> is neither a marker nor an element
-   that is also in the <span>stack of open elements</span>, go to step
-   4.</li>
+   that is also in the <span>stack of open elements</span>, go to the step labeled
+   <i>rewind</i>.</li>
 
-   <li>Let <var title="">entry</var> be the element one later than
+   <li><i>Advance</i>: Let <var title="">entry</var> be the element one later than
    <var title="">entry</var> in the <span>list of active formatting
    elements</span>.</li>
 
-   <li><span>Create an element for the token</span> for which the
-   element <var title="">entry</var> was created, to obtain <var
-   title="">new element</var>.</li>
+   <li><i>Create</i>: <span>Insert an HTML element</span> for the token for which the element <var
+   title="">entry</var> was created, to obtain <var title="">new element</var>.</li>
 
-   <li>Insert <var title="">new element</var> <span title="insert a node in the appropriate
-   place">in the appropriate place</span> and push it onto the <span>stack of open elements</span>
-   so that it is the new <span>current node</span>.</li>
-
    <li>Replace the entry for <var title="">entry</var> in the list
    with an entry for <var title="">new element</var>.</li>
 
    <li>If the entry for <var title="">new element</var> in the
    <span>list of active formatting elements</span> is not the last
-   entry in the list, return to step 7.</li>
+   entry in the list, return to the step labeled <i>advance</i>.</li>
 
   </ol>
 
@@ -99024,38 +99020,139 @@
 
   <h5>Creating and inserting nodes</h5>
 
+  <p>The <dfn>appropriate place for inserting a node</dfn>, optionally using a particular
+  <i>override target</i>, is the position in an element returned by running the following steps:</p>
+
+  <ol>
+
+   <li>
+
+    <p>If there was an <i>override target</i> specified, then let <var title="">target</var> be the
+    <i>override target</i>.</p>
+
+    <p>Otherwise, let <var title="">target</var> be the <span>current node</span>.</p>
+
+   </li>
+
+   <li>
+
+    <p>Determine the <var title="">adjusted insertion location</var> using the first matching steps
+    from the following list:</p>
+
+    <dl class="switch">
+
+     <dt>If <dfn title="foster parent">foster parenting</dfn> is enabled and <var
+     title="">target</var> is a <code>table</code>, <code>tbody</code>, <code>tfoot</code>,
+     <code>thead</code>, or <code>tr</code> element</dt>
+
+     <dd>
+
+      <p class="note">Foster parenting happens when content is misnested in tables.</p>
+
+      <p>The <dfn>foster parent element</dfn> is the parent element of the last <code>table</code>
+      element in the <span>stack of open elements</span>, if there is a <code>table</code> element and
+      it has such a parent element.</p>
+
+      <p class="note">It might have no parent or some other kind parent if a script manipulated the
+      DOM after the element was inserted by the parser.</p>
+
+      <p>If there is no <code>table</code> element in the <span>stack of open elements</span>
+      (<span>fragment case</span>), then the <i>foster parent element</i> is the first element in the
+      <span>stack of open elements</span> (the <code>html</code> element). Otherwise, if there is a
+      <code>table</code> element in the <span>stack of open elements</span>, but the last
+      <code>table</code> element in the <span>stack of open elements</span> has no parent, or its
+      parent node is not an element, then the <i>foster parent element</i> is the element before the
+      last <code>table</code> element in the <span>stack of open elements</span>.</p>
+
+      <p>If the <i>foster parent element</i> is the parent element of the last <code>table</code>
+      element in the <span>stack of open elements</span>, then the <var title="">adjusted insertion
+      location</var> is inside the <i>foster parent element</i>, immediately <em>before</em> the
+      last <code>table</code> element in the <span>stack of open elements</span>; otherwise, the
+      <var title="">adjusted insertion location</var> is inside the <i>foster parent element</i>,
+      after its last child (if any).</p>
+
+     </dd>
+
+     <dt>Otherwise</dt>
+
+     <dd>
+
+      <p>The <var title="">adjusted insertion location</var> is inside <var title="">target</var>,
+      after its last child (if any).</p>
+
+     </dd>
+
+    </dl>
+
+   </li>
+
+   <li>
+
+    <p>Return the <var title="">adjusted insertion location</var>.</p>
+
+   </li>
+
+  </ol>
+
+  <hr>
+
   <p>When the steps below require the UA to <dfn title="create an element for the token">create an
-  element for a token</dfn> in a particular namespace, the UA must create a node implementing the
-  interface appropriate for the element type corresponding to the tag name of the token in the given
-  namespace (as given in the specification that defines that element, e.g. for an <code>a</code>
-  element in the <span>HTML namespace</span>, this specification defines it to be the
-  <code>HTMLAnchorElement</code> interface), with the tag name being the name of that element, with
-  the node being in the given namespace, and with the attributes on the node being those given in
-  the given token.</p>
+  element for a token</dfn> in a particular <var title="">given namespace</var> and with a
+  particular <var title="">intended parent</var>, the UA must run the following steps:</p>
 
-  <p>The interface appropriate for an element in the <span>HTML namespace</span> that is not defined
-  in this specification (or <span>other applicable specifications</span>) is
-  <code>HTMLUnknownElement</code>. Elements in other namespaces whose interface is not defined by
-  that namespace's specification must use the interface <code>Element</code>.</p>
+  <ol>
 
-  <p>When a <span title="category-reset">resettable element</span> is created in this manner, its
-  <span title="concept-form-reset-control">reset algorithm</span> must be invoked once the
-  attributes are set. (This initializes the element's <span title="concept-fe-value">value</span>
-  and <span title="concept-fe-checked">checkedness</span> based on the element's attributes.)</p>
+   <li>
 
+    <p>Create a node implementing the interface appropriate for the element type corresponding to
+    the tag name of the token in <var title="">given namespace</var> (as given in the specification
+    that defines that element, e.g. for an <code>a</code> element in the <span>HTML
+    namespace</span>, this specification defines it to be the <code>HTMLAnchorElement</code>
+    interface), with the tag name being the name of that element, with the node being in the given
+    namespace, and with the attributes on the node being those given in the given token.</p>
+
+    <p>The interface appropriate for an element in the <span>HTML namespace</span> that is not defined
+    in this specification (or <span>other applicable specifications</span>) is
+    <code>HTMLUnknownElement</code>. Elements in other namespaces whose interface is not defined by
+    that namespace's specification must use the interface <code>Element</code>.</p>
+
+    <p>The <code title="dom-Node-ownerDocument">ownerDocument</code> of the newly created element
+    must be the same as that of the <var title="">intended parent</var>.</p>
+
+   </li>
+
+   <li>
+
+    <p>If the newly created element is a <span title="category-reset">resettable element</span>,
+    invoke its <span title="concept-form-reset-control">reset algorithm</span>. (This initializes
+    the element's <span title="concept-fe-value">value</span> and <span
+    title="concept-fe-checked">checkedness</span> based on the element's attributes.)</p>
+
+   </li>
+
+   <li><p>Return the newly created element.</p></li>
+
+  </ol>
+
   <hr>
 
   <!-- The names of these algorithms are kinda confusing; e.g. see the confusion in
          https://www.w3.org/Bugs/Public/show_bug.cgi?id=18367
        Not sure what we could call them instead, though... -->
 
-  <p>When the steps below require the UA to <dfn>insert an HTML element</dfn> for a token,
-  optionally in a specific place, the UA must run the following steps:</p>
+  <p>When the steps below require the UA to <dfn>insert an HTML element</dfn> for a token, the UA
+  must run the following steps:</p>
 
   <ol>
 
-   <li><p><span>Create an element for the token</span> in the <span>HTML namespace</span>.</p></li>
+   <li><p>Let the <var title="">adjusted insertion location</var> be the <span>appropriate
+   place for inserting a node</span>.</p></li>
 
+   <li><p><span>Create an element for the token</span> in the <span>HTML namespace</span>, with the
+   intended parent being the element in which the <var title="">adjusted insertion location</var>
+   finds itself.</p></li>
+
+   <!-- this could just as easily be in the "create..." algorithm I guess -->
    <li><p>If the element is a <span>form-associated element</span>, and the <span><code
    title="">form</code> element pointer</span> is not null, and the newly created element doesn't
    have a <code title="attr-fae-form">form</code> attribute, <span
@@ -99064,22 +99161,20 @@
    pointer</span>, and suppress the running of the <span>reset the form owner</span> algorithm in
    the next step.</p></li>
 
-   <li><p>If no specific place has been specified, <span title="insert a node in the appropriate
-   place">insert the node in the appropriate place</span>; otherwise, if a specific place has been
-   specified, insert or append the node as specified.</p></li>
+   <li><p>Insert the newly created element at the <var title="">adjusted insertion
+   location</var>.</p></li>
 
    <li><p>Push the element onto the <span>stack of open elements</span> so that it is the new
    <span>current node</span>.</p></li>
 
+   <li><p>Return the newly created element.</p></li>
+
   </ol>
 
-  <p class="note">A specific place is specified in in particular during the parsing of tables with
-  invalid content.</p>
-
   <hr>
 
   <p>When the steps below require the UA to <dfn>insert a foreign element</dfn> for a token, the UA
-  must first <span>create an element for the token</span> in the given namespace, and then append
+  must first <span>create an element for the token</span> in the given namespace, with the <span>current node</span> as the intended parent, and then append
   this node to the <span>current node</span>, and push it onto the <span>stack of open
   elements</span> so that it is the new <span>current node</span>. If the newly created element has
   an <code title="">xmlns</code> attribute in the <span>XMLNS namespace</span> whose value is not
@@ -99089,8 +99184,8 @@
   error</span>.</p>
 
   <p class="note">The <span>insert a foreign element</span> algorithm isn't affected by the <span
-  title="foster parent">foster parenting</span> logic (it doesn't use the <span>insert a node in the
-  appropriate place</span> algorithm); the <span>current node</span>, when the <span>insert a
+  title="foster parent">foster parenting</span> logic (it doesn't use the <span>appropriate place for
+  inserting a node</span> algorithm); the <span>current node</span>, when the <span>insert a
   foreign element</span> algorithm is invoked, is always itself a non-HTML element.</p>
 
   <p>When the steps below require the user agent to <dfn>adjust MathML attributes</dfn> for a token,
@@ -99199,113 +99294,32 @@
 
   <hr>
 
-  <p>When the steps below require the user agent to <dfn>insert a character</dfn> for a token, the
-  user agent must insert it <span title="insert a node in the appropriate place">in the appropriate
-  place</span>.</p>
+  <p>When the steps below require the user agent to <dfn>insert a character</dfn> while processing a
+  token, the user agent must run the following steps:</p>
 
-  <hr>
-
-  <p>When the user agent is required to <dfn>insert a node in the appropriate place</dfn>,
-  optionally using a particular <i>override target</i>, the user agent must follow the following
-  steps:</p>
-
   <ol>
 
-   <li>
+   <li><p>Let <var title="">data</var> be the characters passed to the algorithm, or, if no
+   characters were explicitly specified, the character of the character token being
+   processed.</p></li>
 
-    <p>If there was an <i>override target</i> specified, then let <var title="">target</var> be the
-    <i>override target</i>.</p>
+   <li><p>Let the <var title="">adjusted insertion location</var> be the <span>appropriate
+   place for inserting a node</span>.</p></li>
 
-    <p>Otherwise, let <var title="">target</var> be the <span>current node</span>.</p>
-
-   </li>
-
    <li>
 
-    <p>Determine the <var title="">adjusted insertion location</var> using the first matching steps
-    from the following list:</p>
+    <p>If there is a <code>Text</code> node immediately before the <var title="">adjusted insertion
+    location</var>, then append <var title="">data</var> to that <code>Text</code> node's data.</p>
 
-    <dl class="switch">
+    <p>Otherwise, create a new <code>Text</code> node whose data is <var title="">data</var> and
+    whose <code title="dom-Node-ownerDocument">ownerDocument</code> is the same as that of the
+    element in which the <var title="">adjusted insertion location</var> finds itself, and insert
+    the newly created node at the <var title="">adjusted insertion location</var>.</p>
 
-     <dt>If <dfn title="foster parent">foster parenting</dfn> is enabled and <var
-     title="">target</var> is a <code>table</code>, <code>tbody</code>, <code>tfoot</code>,
-     <code>thead</code>, or <code>tr</code> element</dt>
-
-     <dd>
-
-      <p class="note">Foster parenting happens when content is misnested in tables.</p>
-
-      <p>The <dfn>foster parent element</dfn> is the parent element of the last <code>table</code>
-      element in the <span>stack of open elements</span>, if there is a <code>table</code> element and
-      it has such a parent element.</p>
-
-      <p class="note">It might have no parent or some other kind parent if a script manipulated the
-      DOM after the element was inserted by the parser.</p>
-
-      <p>If there is no <code>table</code> element in the <span>stack of open elements</span>
-      (<span>fragment case</span>), then the <i>foster parent element</i> is the first element in the
-      <span>stack of open elements</span> (the <code>html</code> element). Otherwise, if there is a
-      <code>table</code> element in the <span>stack of open elements</span>, but the last
-      <code>table</code> element in the <span>stack of open elements</span> has no parent, or its
-      parent node is not an element, then the <i>foster parent element</i> is the element before the
-      last <code>table</code> element in the <span>stack of open elements</span>.</p>
-
-      <p>If the <i>foster parent element</i> is the parent element of the last <code>table</code>
-      element in the <span>stack of open elements</span>, then the <var title="">adjusted insertion
-      location</var> is inside the <i>foster parent element</i>, immediately <em>before</em> the
-      last <code>table</code> element in the <span>stack of open elements</span>; otherwise, the
-      <var title="">adjusted insertion location</var> is inside the <i>foster parent element</i>,
-      after its last child (if any).</p>
-
-     </dd>
-
-     <dt>Otherwise</dt>
-
-     <dd>
-
-      <p>The <var title="">adjusted insertion location</var> is inside <var title="">target</var>,
-      after its last child (if any).</p>
-
-     </dd>
-
-    </dl>
-
    </li>
 
-   <li>
-
-    <p>Run the first matching steps from the following list to actually perform the insertion:</p>
-
-    <dl class="switch">
-
-     <dt>If the node being inserted is a character</dt>
-
-     <dd>
-
-      <p>If there is a <code>Text</code> node immediately before the <var title="">adjusted
-      insertion location</var>, then append the character to that <code>Text</code> node.</p>
-
-      <p>Otherwise, create a new <code>Text</code> node whose data is just that character, and
-      insert it at the <var title="">adjusted insertion location</var>.</p>
-
-     </dd>
-
-     <dt>Otherwise</dt>
-
-     <dd>
-
-      <p>Insert the node at the <var title="">adjusted insertion location</var>.</p>
-
-     </dd>
-
-    </dl>
-
-   </li>
-
   </ol>
 
-  <hr>
-
   <div class="example">
 
    <p>Here are some sample inputs to the parser and the corresponding number of <code>Text</code>
@@ -99348,6 +99362,33 @@
 
   </div>
 
+  <hr>
+
+  <p>When the steps below require the user agent to <dfn>insert a comment</dfn> while processing a
+  comment token, optionally with an explicitly insertion position <var title="">position</var>, the
+  user agent must run the following steps:</p>
+
+  <ol>
+
+   <li><p>Let <var title="">data</var> be the data given in the comment token being
+   processed.</p></li>
+
+   <li><p>If <var title="">position</var> was specified, then let the <var title="">adjusted
+   insertion location</var> be <var title="">position</var>. Otherwise, let <var title="">adjusted
+   insertion location</var> be the <span>appropriate place for inserting a node</span>.</p></li>
+
+   <li><p>Create a <code>Comment</code> node whose <code title="">data</code> attribute is set to
+   <var title="">data</var> and whose <code title="dom-Node-ownerDocument">ownerDocument</code> is
+   the same as that of the node in which the <var title="">adjusted insertion location</var> finds
+   itself.</p>
+
+   <li><p>Insert the newly created node at the <var title="">adjusted insertion
+   location</var>.</p></li>
+
+  </ol>
+
+  <hr>
+
   <p id="mutation-during-parsing">DOM mutation events must not fire for changes caused by the UA
   parsing the document. This includes the parsing of any content inserted using <code
   title="dom-document-write">document.write()</code> and <code
@@ -99417,9 +99458,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code>Comment</code> node to the <code>Document</code>
-    object with the <code title="">data</code> attribute set to the
-    data given in the comment token.</p>
+    <p><span>Insert a comment</span> as the last child of the <code>Document</code> object.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -99635,9 +99674,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code>Comment</code> node to the <code>Document</code>
-    object with the <code title="">data</code> attribute set to the
-    data given in the comment token.</p>
+    <p><span>Insert a comment</span> as the last child of the <code>Document</code> object.</p>
    </dd>
 
    <dt>A character token that is one of U+0009 CHARACTER
@@ -99651,7 +99688,7 @@
    <dd>
 
     <p><span>Create an element for the token</span> in the <span>HTML
-    namespace</span>. Append it to the <code>Document</code>
+    namespace</span>, with the <code>Document</code> as the intended parent. Append it to the <code>Document</code>
     object. Put this element in the <span>stack of open
     elements</span>.</p>
 
@@ -99689,7 +99726,7 @@
    <dt>Anything else</dt>
    <dd>
 
-    <p>Create an <code>html</code> element. Append it to the
+    <p>Create an <code>html</code> element whose <code title="dom-Node-ownerDocument">ownerDocument</code> is the <code>Document</code> object. Append it to the
     <code>Document</code> object. Put this element in the <span>stack
     of open elements</span>.</p>
 
@@ -99729,9 +99766,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code>Comment</code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <span title="insert a node in the appropriate place">in the
-    appropriate place</span>.</p>
+    <p><span>Insert a comment</span>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -99801,9 +99836,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code>Comment</code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <span title="insert a node in the appropriate place">in the
-    appropriate place</span>.</p>
+    <p><span>Insert a comment</span>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -99887,9 +99920,13 @@
 
     <ol>
 
-     <li><p><span>Create an element for the token</span> in the
-     <span>HTML namespace</span>.</p></li>
+     <li><p>Let the <var title="">adjusted insertion location</var> be the <span>appropriate
+     place for inserting a node</span>.</p></li>
 
+     <li><p><span>Create an element for the token</span> in the <span>HTML namespace</span>, with the
+     intended parent being the element in which the <var title="">adjusted insertion location</var>
+     finds itself.</p></li>
+
      <li>
 
       <p>Mark the element as being <span>"parser-inserted"</span> and
@@ -99909,9 +99946,12 @@
      <code>script</code> element as <span>"already
      started"</span>. (<span>fragment case</span>)</p></li>
 
-     <li><p><span title="insert a node in the appropriate place">Insert the node in the appropriate
-     place</span>, and then push it onto the <span>stack of open elements</span>.</p></li>
+     <li><p>Insert the newly created element at the <var title="">adjusted insertion
+     location</var>.</p></li>
 
+     <li><p>Push the element onto the <span>stack of open elements</span> so that it is the new
+     <span>current node</span>.</p></li>
+
      <li><p>Switch the tokenizer to the <span>script data
      state</span>.</p></li>
 
@@ -100044,9 +100084,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code>Comment</code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <span title="insert a node in the appropriate place">in the
-    appropriate place</span>.</p>
+    <p><span>Insert a comment</span>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -100177,9 +100215,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code>Comment</code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <span title="insert a node in the appropriate place">in the
-    appropriate place</span>.</p>
+    <p><span>Insert a comment</span>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -100920,7 +100956,7 @@
        in the overall algorithm.</li>
 
        <li><span>Create an element for the token</span> for which the
-       element <var title="">node</var> was created, replace the entry
+       element <var title="">node</var> was created, with <var title="">common ancestor</var> as the intended parent; replace the entry
        for <var title="">node</var> in the <span>list of active
        formatting elements</span> with an entry for the new element,
        replace the entry for <var title="">node</var> in the
@@ -100946,12 +100982,13 @@
 
      </li>
 
-     <li><p>Insert whatever <var title="">last node</var> ended up being in the previous step <span
-     title="insert a node in the appropriate place">in the appropriate place</span>, but using <var
+     <li><p>Insert whatever <var title="">last node</var> ended up being in the previous step at the <span>appropriate
+     place for inserting a node</span>, but using <var
      title="">common ancestor</var> as the <i>override target</i>.</p></li>
 
      <li><p><span>Create an element for the token</span> for which the
-     <var title="">formatting element</var> was created.</p></li>
+     <var title="">formatting element</var> was created, with <var title="">furthest
+     block</var> as the intended parent.</p></li>
 
      <li><p>Take all of the child nodes of the <var title="">furthest
      block</var> and append them to the element created in the last
@@ -101660,9 +101697,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code>Comment</code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <span title="insert a node in the appropriate place">in the
-    appropriate place</span>.</p>
+    <p><span>Insert a comment</span>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -101990,9 +102025,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code>Comment</code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <span title="insert a node in the appropriate place">in the
-    appropriate place</span>.</p>
+    <p><span>Insert a comment</span>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -102384,9 +102417,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code>Comment</code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <span title="insert a node in the appropriate place">in the
-    appropriate place</span>.</p>
+    <p><span>Insert a comment</span>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -102579,10 +102610,9 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code>Comment</code> node to the first element in
+    <p><span>Insert a comment</span> as the last child of the first element in
     the <span>stack of open elements</span> (the <code>html</code>
-    element), with the <code title="">data</code> attribute set to
-    the data given in the comment token.</p>
+    element).</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -102642,9 +102672,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code>Comment</code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <span title="insert a node in the appropriate place">in the
-    appropriate place</span>.</p>
+    <p><span>Insert a comment</span>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -102742,9 +102770,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code>Comment</code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <span title="insert a node in the appropriate place">in the
-    appropriate place</span>.</p>
+    <p><span>Insert a comment</span>.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -102794,9 +102820,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code>Comment</code> node to the <code>Document</code>
-    object with the <code title="">data</code> attribute set to the
-    data given in the comment token.</p>
+    <p><span>Insert a comment</span> as the last child of the <code>Document</code> object.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -102833,9 +102857,7 @@
 
    <dt>A comment token</dt>
    <dd>
-    <p>Append a <code>Comment</code> node to the <code>Document</code>
-    object with the <code title="">data</code> attribute set to the
-    data given in the comment token.</p>
+    <p><span>Insert a comment</span> as the last child of the <code>Document</code> object.</p>
    </dd>
 
    <dt>A DOCTYPE token</dt>
@@ -102904,9 +102926,7 @@
    <dt>A comment token</dt>
    <dd>
 
-    <p>Append a <code>Comment</code> node with the <code title="">data</code> attribute set to the
-    data given in the comment token <span title="insert a node in the appropriate place">in the
-    appropriate place</span>.</p>
+    <p><span>Insert a comment</span>.</p>
 
    </dd>
 




More information about the Commit-Watchers mailing list