Skip to content

Commit

Permalink
Upstream createContextualFragment() from DOM Parsing and Serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewarlow committed Apr 24, 2024
1 parent 2a94a9a commit 69f5a4a
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions source
Expand Up @@ -3151,6 +3151,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li><dfn data-x-href="https://dom.spec.whatwg.org/#interface-processinginstruction"><code>ProcessingInstruction</code></dfn> interface</li>
<li><dfn data-x-href="https://dom.spec.whatwg.org/#interface-shadowroot"><code>ShadowRoot</code></dfn> interface</li>
<li><dfn data-x-href="https://dom.spec.whatwg.org/#interface-text"><code>Text</code></dfn> interface</li>
<li><dfn data-x-href="https://dom.spec.whatwg.org/#interface-range"><code>Range</code></dfn> interface</li>

<li><dfn data-x-href="https://dom.spec.whatwg.org/#concept-node-document">node document</dfn> concept</li>
<li><dfn data-x="concept-document-type" data-x-href="https://dom.spec.whatwg.org/#concept-document-type">document type</dfn> concept</li>
Expand Down Expand Up @@ -3274,6 +3275,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li>The term <dfn data-x="concept-supported-tokens" data-x-href="https://dom.spec.whatwg.org/#concept-supported-tokens">supported tokens</dfn></li>

<li>The concept of a DOM <dfn data-x="concept-range" data-x-href="https://dom.spec.whatwg.org/#concept-range">range</dfn>, and the terms
<dfn data-x="concept-range-start-node" data-x-href="https://dom.spec.whatwg.org/#concept-range-start-node">start node</dfn>,
<dfn data-x="concept-range-start" data-x-href="https://dom.spec.whatwg.org/#concept-range-start">start</dfn>,
<dfn data-x="concept-range-end" data-x-href="https://dom.spec.whatwg.org/#concept-range-end">end</dfn>, and
<dfn data-x="concept-range-bp" data-x-href="https://dom.spec.whatwg.org/#concept-range-bp">boundary point</dfn> as applied to ranges.</li>
Expand Down Expand Up @@ -112995,6 +112997,88 @@ enum <dfn enum>DOMParserSupportedType</dfn> {

</div>

<h4>The <code data-x="dom-Range-createContextualFragment">createContextualFragment()</code>
method</h4>

<p class="XXX">The <code
data-x="dom-Range-createContextualFragment">createContextualFragment()</code> method has a number
of outstanding issues in the <cite>DOM Parsing and Serialization</cite> <a
href="https://github.com/w3c/DOM-Parsing/issues">issue tracker</a>, documenting various problems
with its specification.</p>

<dl class="domintro">
<dt><code data-x=""><var>docFragment</var> = <var>range</var>.<span subdfn data-x="dom-Range-createContextualFragment">createContextualFragment</span>(<var>string</var>)</code></dt>
<dd>
<p>Returns a <code>DocumentFragment</code> created from the markup string <var>string</var> using
<var>range</var>'s <span data-x="concept-range-start-node">start node</span> as the context in
which <var>fragment</var> is parsed.</p>
</dd>
</dl>

<p class="warning">This method performs no sanitization to remove potentially-dangerous elements
and attributes like <code>script</code> or <span>event handler content attributes</span>.</p>

<pre><code class="idl">partial interface <span id="Range-partial">Range</span> {
[<span>CEReactions</span>, NewObject] <code>DocumentFragment</code> <span data-x="dom-Range-createContextualFragment">createContextualFragment</span>(<span data-x="tt-htmlstring">HTMLString</span> <var>string</var>);
};</code></pre>

<div w-nodev>

<p><code>Range</code>'s <dfn method for="Range"><code
data-x="dom-Range-createContextualFragment">createContextualFragment(<var>string</var>)</code></dfn>
method steps are:</p>

<ol>
<li><p>Let <var>node</var> be <span>this</span>'s <span data-x="concept-range-start-node">start
node</span>.</p></li>

<li><p>Let <var>element</var> be null.</p></li>

<li><p>If <var>node</var> <span>implements</span> <code>Element</code>, set <var>element</var>
to <var>node</var>.</p></li>

<li><p>Otherwise, if <var>node</var> <span>implements</span> <code>Text</code> or
<code>Comment</code>, set <var>element</var> to <var>node</var>'s <span>parent
element</span>.</p></li>

<li>
<p>If <var>element</var> is null or all of the following are true:</p>

<ul>
<li><p><var>element</var>'s <span>node document</span> is an HTML document;</p></li>

<li><p><var>element</var>'s <span data-x="concept-element-local-name">local name</span> is
"<code>html</code>"; and</p></li>

<li><p><var>element</var>'s <span data-x="concept-element-namespace">namespace</span> is the
<span>HTML namespace</span>,</p></li>
</ul>

<p>then set <var>element</var> to the result of <span data-x="create an element">creating an
element</span> given <span>this</span>'s <span>node document</span>, <code>body</code>, and the
<span>HTML namespace</span>.</p>
</li>

<li><p>Let <var>fragment node</var> be the result of invoking the <span>fragment parsing
algorithm steps</span> with <var>element</var> and <var>string</var>.</p></li>

<li>
<p><span data-x="list iterate">For each</span> <var>script</var> of <var>fragment node</var>'s
<code data-x="script">script</code> element <span
data-x="concept-tree-descendant">descendants</span>:</p>

<ol>
<li><p>Set <var>script</var>'s <span>already started</span> to false.</p></li>

<li><p>Set <var>script</var>'s <span>parser document</span> to null.</p></li>
</ol>
</li>

<li><p>Return <var>fragment node</var>.</p></li>
</ol>

</div>

<h3 split-filename="timers-and-user-prompts" id="timers">Timers</h3>

<p>The <code data-x="dom-setTimeout">setTimeout()</code> and <code
Expand Down

0 comments on commit 69f5a4a

Please sign in to comment.