Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editorial: Upstream the createContextualFragment method from DOM Parsing #10283

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
83 changes: 83 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,87 @@ 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>
lukewarlow marked this conversation as resolved.
Show resolved Hide resolved
<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>text</var>);
lukewarlow marked this conversation as resolved.
Show resolved Hide resolved
};</code></pre>

<div w-nodev>

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

lukewarlow marked this conversation as resolved.
Show resolved Hide resolved
<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>set <var>element</var> to the result of <span data-x="create an element">creating an
lukewarlow marked this conversation as resolved.
Show resolved Hide resolved
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>text</var>.</p></li>
lukewarlow marked this conversation as resolved.
Show resolved Hide resolved

<li>
<p><span data-x="list iterate">For each</span> <var>script</var> of <var>fragment node</var>'s
lukewarlow marked this conversation as resolved.
Show resolved Hide resolved
<code data-x="script">script</code> element <span
data-x="concept-tree-descendant">descendants</span>:</p>
<ol>
lukewarlow marked this conversation as resolved.
Show resolved Hide resolved
<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>
lukewarlow marked this conversation as resolved.
Show resolved Hide resolved
</ol>
lukewarlow marked this conversation as resolved.
Show resolved Hide resolved
</li>

lukewarlow marked this conversation as resolved.
Show resolved Hide resolved
<li><p>Return <var>fragment node</var>.</p></li>

lukewarlow marked this conversation as resolved.
Show resolved Hide resolved
</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