Skip to content

Commit

Permalink
Upstream the createContextualFragment method from DOM Parsing and Ser…
Browse files Browse the repository at this point in the history
…ialization
  • Loading branch information
lukewarlow committed Apr 17, 2024
1 parent d6a5f09 commit ece17d4
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions source
Original file line number Diff line number Diff line change
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 @@ -3273,6 +3274,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 @@ -112842,6 +112844,89 @@ enum <dfn enum>DOMParserSupportedType</dfn> {

</div>

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

<p class="XXX">The <code data-x="dom-Range-createContextualFragment">createContextualFragment(<var>fragment</var>)</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>fragment</var>)</code></dt>
<dd>
<p>Returns a <code>DocumentFragment</code> created from the markup string <var>fragment</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>fragment</var>);
};</code></pre>

<div w-nodev>

<p><code>Range</code>'s <dfn method for="Range"><code
data-x="dom-Range-createContextualFragment">createContextualFragment(<var>fragment</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>Switching on <var>node</var>'s interface:</p>
<dl class=switch>
<dt><code>Document</code></dt>
<dt><code>DocumentFragment</code></dt>
<dd>Do nothing.</dd>

<dt><code>Element</code></dt>
<dd>Set <var>element</var> to <var>node</var>.</dd>

<dt><code>Text</code></dt>
<dt><code>Comment</code></dt>
<dd>Set <var>element</var> to <var>node</var>'s <span>parent element</span>.</dd>
</dl>
</li>

<li>
<p>If <var>element</var> is null or the follow are all 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
"html", 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>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>fragment</var>.</p>
</li>

<li>
<p>Unmark all scripts in <var>fragment node</var> as "already started" and as
"parser-inserted".</p>
</li>

<li><p>Return the value of <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 ece17d4

Please sign in to comment.