Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 35 additions & 56 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -123842,17 +123842,11 @@ enum <dfn enum>DOMParserSupportedType</dfn> {
<var>html</var>:</p>

<ol>
<li><p>Let <var>newChildren</var> be the result of the <span>HTML fragment parsing
algorithm</span> given <var>contextElement</var>, <var>html</var>, and true.</p></li>

<li><p>Let <var>fragment</var> be a new <code>DocumentFragment</code> whose <span>node
document</span> is <var>contextElement</var>'s <span>node document</span>.</p></li>

<li><p>For each <var>node</var> in <var>newChildren</var>, <span
data-x="concept-node-append">append</span> <var>node</var> to <var>fragment</var>.</p></li>
<li><p><span data-x="concept-node-remove">Remove</span> all <var>target</var>'s <span
data-x="concept-tree-child">children</span>, in <span>tree order</span>.</p></li>

<li><p><span data-x="concept-node-replace-all">Replace all</span> with <var>fragment</var> within
<var>target</var>.</p></li>
<li><p>Run the <span>HTML fragment parsing algorithm</span> given <var>target</var>,
<var>contextElement</var>, <var>html</var>, and true.</p></li>
</ol>
</div>

Expand Down Expand Up @@ -123997,25 +123991,17 @@ enum <dfn enum>DOMParserSupportedType</dfn> {
<var>context</var> and a string <var>markup</var>, are:</p>

<ol>
<li><p>Let <var>fragment</var> be a new <code>DocumentFragment</code> whose <span>node
document</span> is <var>context</var>'s <span>node document</span>.</p></li>

<li><p>Let <var>algorithm</var> be the <span>HTML fragment parsing algorithm</span>.</p></li>

<li><p>If <var>context</var>'s <span>node document</span> is an <span data-x="XML documents">XML
document</span>, then set <var>algorithm</var> to the <span>XML fragment parsing
algorithm</span>.</p></li>

<li><p>Let <var>newChildren</var> be the result of invoking <var>algorithm</var> given
<var>context</var> and <var>markup</var>.</p></li>

<li><p>Let <var>fragment</var> be a new <code>DocumentFragment</code> whose <span>node
document</span> is <var>context</var>'s <span>node document</span>.</p></li>

<li>
<p>For each <var>node</var> of <var>newChildren</var>, in <span>tree order</span>: <span
data-x="concept-node-append">append</span> <var>node</var> to <var>fragment</var>.</p>

<p class=note>This ensures the <span>node document</span> for the new <span
data-x="node">nodes</span> is correct.</p>
</li>
<li><p>Invoke <var>algorithm</var> given <var>fragment</var>, <var>context</var> and
<var>markup</var>.</p></li>

<li><p>Return <var>fragment</var>.</p></li>
</ol>
Expand Down Expand Up @@ -144509,10 +144495,11 @@ console.assert(container.firstChild instanceof SuperP);
<h3>Parsing HTML fragments</h3>

<div algorithm>
<p>The <dfn>HTML fragment parsing algorithm</dfn>, given an <code>Element</code> node <dfn
data-x="concept-frag-parse-context"><var>context</var></dfn>, string <var>input</var>, and an
optional boolean <var>allowDeclarativeShadowRoots</var> (default false) is the following steps.
They return a list of zero or more nodes.</p>
<p>The <dfn>HTML fragment parsing algorithm</dfn>, given an <code>Element</code> or
<code>DocumentFragment</code> <var>target</var>, an <code>Element</code> <dfn
data-x="concept-frag-parse-context"><var>context</var></dfn>, a string <var>input</var>, and an
optional boolean <var>allowDeclarativeShadowRoots</var> (default false) is the following
steps. Zero or more nodes are inserted into <var>target</var>.</p>

<p class="note">Parts marked <dfn>fragment case</dfn> in algorithms in the <span>HTML
parser</span> section are parts that only occur if the parser was created for the purposes of this
Expand All @@ -144522,22 +144509,13 @@ console.assert(container.firstChild instanceof SuperP);
handling this algorithm, then that is an error in the specification.</p>

<ol>
<li><p>Let <var>document</var> be a <code>Document</code> node whose <span
data-x="concept-document-type">type</span> is "<code data-x="">html</code>".</p></li>
<li><p>Let <var>parser</var> be a new <span>HTML parser</span> associated with
<var>context</var>'s <span>node document</span>.</p></li>

<li><p>If <var data-x="concept-frag-parse-context">context</var>'s <span>node document</span> is
in <span>quirks mode</span>, then set <var>document</var>'s <span
data-x="concept-document-mode">mode</span> to "<code data-x="">quirks</code>".</p></li>
<li><p>Set <var>parser</var>'s TODO target to <var>target</var>.</p></li>

<li><p>Otherwise, if <var data-x="concept-frag-parse-context">context</var>'s <span>node
document</span> is in <span>limited-quirks mode</span>, then set <var>document</var>'s <span
data-x="concept-document-mode">mode</span> to "<code data-x="">limited-quirks</code>".</p></li>

<li><p>If <var>allowDeclarativeShadowRoots</var> is true, then set <var>document</var>'s <span
data-x="concept-document-allow-declarative-shadow-roots">allow declarative shadow roots</span> to
true.</p></li>

<li><p>Create a new <span>HTML parser</span>, and associate it with <var>document</var>.</p></li>
<li><p>If <var>allowDeclarativeShadowRoots</var> is true, then set <var>parser</var>'s
TODO <!-- https://github.com/whatwg/html/pull/11965 --> to true.</p></li>

<li>
<p>Set the state of the <span>HTML parser</span>'s <span>tokenization</span> stage as
Expand Down Expand Up @@ -144577,16 +144555,18 @@ console.assert(container.firstChild instanceof SuperP);
transitions.</p>
</li>

<li><p>Let <var>root</var> be the result of <span data-x="create an element">creating an
element</span> given <var>document</var>, "<code data-x="">html</code>", the <span>HTML
namespace</span>, null, null, false, and <var>context</var>'s <span
data-x="element-custom-element-registry">custom element registry</span>.</p></li>
<li><p>Set up the <span>HTML parser</span>'s <span>stack of open elements</span> so that it
contains just the single node (maybe not element!) <var>target</var>.</p></li>

<li><p><span data-x="concept-node-append">Append</span> <var>root</var> to
<var>document</var>.</p></li>
<!--
Chromium puts the DocumentFragment as the first item on the stack of open elements:
https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/html/parser/html_tree_builder.cc;l=339-344;drc=f94df6678b9dba1f9faf292374830260cc90ae54

<li><p>Set up the <span>HTML parser</span>'s <span>stack of open elements</span> so that it
contains just the single element <var>root</var>.</p></li>
So does WebKit:
https://github.com/WebKit/WebKit/blob/8ffda356226982423d22448a9c656a060773cd73/Source/WebCore/html/parser/HTMLTreeBuilder.cpp#L282-L284

What does Gecko do?
-->

<li><p>If <var data-x="concept-frag-parse-context">context</var> is a <code>template</code>
element, then push "<span data-x="insertion mode: in template">in template</span>" onto the
Expand Down Expand Up @@ -144624,9 +144604,6 @@ console.assert(container.firstChild instanceof SuperP);

<li><p>Start the <span>HTML parser</span> and let it run until it has consumed all the characters
just inserted into the input stream.</p></li>

<li><p>Return <var>root</var>'s <span data-x="concept-tree-child">children</span>, in <span>tree
order</span>.</p></li>
</ol>
</div>

Expand Down Expand Up @@ -144952,9 +144929,10 @@ console.assert(container.firstChild instanceof SuperP);
<h3 id="parsing-xhtml-fragments">Parsing XML fragments</h3>

<div algorithm>
<p>The <dfn>XML fragment parsing algorithm</dfn> given an <code>Element</code> node <var
<p>The <dfn>XML fragment parsing algorithm</dfn> given an <code>Element</code> or
<code>DocumentFragment</code> <var>target</var>, <code>Element</code> node <var
data-x="concept-frag-parse-context">context</var> and a string <var>input</var>, runs the
following steps. They return a list of nodes.</p>
following steps. Zero or more nodes are inserted into <var>target</var>.</p>

<ol>
<li><p>Create a new <span>XML parser</span>.</p></li>
Expand Down Expand Up @@ -144989,8 +144967,9 @@ console.assert(container.firstChild instanceof SuperP);
<!-- This is technically redundant, but apparently it has gone wrong in the past:
https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=1443 -->

<li><p>Return the resulting <code>Document</code> node's <span>document element</span>'s <span
data-x="concept-tree-child">children</span>, in <span>tree order</span>.</p></li>
<li><p><span data-x="concept-node-append">Append</span> the resulting <code>Document</code>
node's <span>document element</span>'s <span data-x="concept-tree-child">children</span> to
<var>target</var>, in <span>tree order</span>.</p></li>
</ol>
</div>

Expand Down