HTML — 動的マークアップ挿入, DOM の構文解析 API と直列化 API

8.4. 動的~markup挿入

注記: ~markupを文書の中へ動的に挿入するための~APIは、 構文解析器と相互作用するので,それらの挙動は[ `~HTML文書$(および`~HTML構文解析器$), `~XML文書$(および`~XML構文解析器$) ]のどちらで利用されるかに依存して変わる。 ◎ APIs for dynamically inserting markup into the document interact with the parser, and thus their behavior varies depending on whether they are used with HTML documents (and the HTML parser) or XML documents (and the XML parser).

各 `文書$には `動的~markup挿入-時には投出する~counter@ があり、 初期~時は 0 に設定するモノトスル。 この~counterは、 `~tokenから要素を作成-$する~algoと併用され,[ `~custom要素~構築子$が構文解析器から呼出されたときに,`文書$上の[ `open()$m / `close()$m / `write()$m ]が利用-可能になる ]のを防ぐために利用される。 ◎ Document objects have a throw-on-dynamic-markup-insertion counter, which is used in conjunction with the create an element for the token algorithm to prevent custom element constructors from being able to use document.open(), document.close(), and document.write() when they are invoked by the parser. Initially, the counter must be set to zero.

8.4.1. 入力~streamの~open法

%document = %document.`open()$m
`文書$をその場で置換する — それまでの~objを再利用しつつ,それが新たな`文書$であったかのように。 その~objが返される。 ◎ Causes the Document to be replaced in-place, as if it was a new Document object, but reusing the previous object, which is then returned.
結果の`文書$には、 ~HTML構文解析器が結付けられる — それには `document.write()$c を利用して構文解析する~dataを与えれる。 ◎ The resulting Document has an HTML parser associated with it, which can be given data to parse using document.write().
`文書$が依然として構文解析-中にある場合、 この~methodの効果は無い。 ◎ The method has no effect if the Document is still being parsed.
次の場合、 `InvalidStateError$E 例外を投出する ⇒# `文書$は`~XML文書$である / `~custom要素~構築子$を現在~実行している ◎ Throws an "InvalidStateError" DOMException if the Document is an XML document. ◎ Throws an "InvalidStateError" DOMException if the parser is currently executing a custom element constructor.
%window = %document.`~openW(url, name, features)$m
`window.open()@~WINDOW#dom-window-open$c ~methodと同様に働く。 ◎ Works like the window.open() method.

各 `文書$には,真偽値をとる `作動中な構文解析器は中止されたか@ があり、 初期~時は ~F をとるとする。 これは、[ 文書にて`作動中な構文解析器$が中止された後 ]に[ ~scriptが[ `document.open()$c / `document.write()$c ]~methodを(直接間接問わず)呼出す ]のを防止するために利用される。 ◎ Document objects have an active parser was aborted boolean, which is used to prevent scripts from invoking the document.open() and document.write() methods (directly or indirectly) after the document's active parser has been aborted. It is initially false.

`document.open 手続き@ は, 所与の ( %文書 ) に対し,次を走らす: ◎ The document open steps, given a document, are as follows:

  1. ~IF[ %文書 は`~XML文書$である ] ⇒ ~THROW `InvalidStateError$E ◎ If document is an XML document, then throw an "InvalidStateError" DOMException exception.
  2. ~IF[ %文書 の`動的~markup挿入-時には投出する~counter$ ~GT 0 ] ⇒ ~THROW `InvalidStateError$E ◎ If document's throw-on-dynamic-markup-insertion counter is greater than 0, then throw an "InvalidStateError" DOMException.
  3. %入口~文書 ~LET `入口~大域~obj$に`結付けられた文書$ ◎ Let entryDocument be the entry global object's associated Document.
  4. ~IF[ ( %文書 の`生成元$doc, %入口~文書 の`生成元$doc ) は`同一-生成元$でない ] ⇒ ~THROW `SecurityError$E ◎ If document's origin is not same origin to entryDocument's origin, then throw a "SecurityError" DOMException.
  5. ~IF[ %文書 には`作動中な構文解析器$がある ]~AND[ その`~script入子ng~level$ ~GT 0 ] ⇒ ~RET %文書 ◎ If document has an active parser whose script nesting level is greater than 0, then return document.

    注記: これは、 `document.open()$c が[ 構文解析-中に見出された~inline~script内で~callされたとき ]には,基本的に無視させる — ~timer~callbackや~event~handlerなどの,構文解析器によらない~taskから~callされたときには、 依然として効果があるようにしつつ。 ◎ This basically causes document.open() to be ignored when it's called in an inline script found during parsing, while still letting it have an effect when called from a non-parser task such as a timer callback or event handler.

  6. ~IF[ %文書 の`~unload~counter$ ~GT 0 ] ⇒ ~RET %文書 ◎ Similarly, if document's unload counter is greater than 0, then return document.

    注記: これは、 `document.open()$c が[ %文書 が~unloadされている間に[ `beforeunload$et / `pagehide$et / `unload$et ]~event~handlerから~callされたとき ]には,基本的に無視させる。 ◎ This basically causes document.open() to be ignored when it's called from a beforeunload, pagehide, or unload event handler while the Document is being unloaded.

  7. ~IF[ %文書 の`作動中な構文解析器は中止されたか$ ~EQ ~T ] ⇒ ~RET %文書 ◎ If document's active parser was aborted is true, then return document.

    注記: これは特に、 `document.open()$c が[ `~navi$が開始された後に~callされたとき ]には,初期~構文解析-の間に限り無視させる。 更なる背景0は `課題 #4723@~HTMLissue/4723$ を見よ。 ◎ This notably causes document.open() to be ignored if it is called after a navigation has started, but only during the initial parse. See issue #4723 for more background.

  8. ~IF[ %文書 の`~node~navigable$ ~NEQ ~NULL ]~AND[ %文書 の`~node~navigable$の`進行中な~navi$は`~navi~ID$である ] ⇒ `読込ngを停止する$( %文書 の`~node~navigable$ ) ◎ If document's node navigable is non-null and document's node navigable's ongoing navigation is a navigation ID, then stop loading document's node navigable.
  9. %文書 の ~EACH( `~shadowも含めた広義-子孫$ %~node ) に対し ⇒ `すべての~event~listener/~event~handlerを消去する$( %~node ) ◎ For each shadow-including inclusive descendant node of document, erase all event listeners and handlers given node.
  10. %~window ~LET %文書 に`関連な大域~obj$ ◎ ↓
  11. ~IF[ %文書 ~EQ %~window に`結付けられた文書$ ] ⇒ `すべての~event~listener/~event~handlerを消去する$( %~window ) ◎ If document is the associated Document of document's relevant global object, then erase all event listeners and handlers given document's relevant global object.
  12. %旧-~flag ~LET %文書 の`変異~eventを発火するか$doc ◎ Let oldFlag be the value of document's fire mutation events flag.
  13. %文書 の`変異~eventを発火するか$doc ~SET ~F ◎ Set document's fire mutation events flag to false.
  14. %文書 の`全~内容を~nodeで置換する$( ~NULL ) ◎ Replace all with null within document.
  15. %文書 の`変異~eventを発火するか$doc ~SET %旧-~flag ◎ Set document's fire mutation events flag to oldFlag.
  16. ~IF[ %文書 は`全部的に作動中$である ]: ◎ If document is fully active, then:

    1. %新~URL ~LET %入口~文書 の`~URL$docの複製 ◎ Let newURL be a copy of entryDocument's URL.
    2. ~IF[ %入口~文書 ~NEQ %文書 ] ⇒ %新~URL の`素片$url ~SET ~NULL ◎ If entryDocument is not document, then set newURL's fragment to null.
    3. `~URLと履歴を更新する$( %文書, %新~URL ) ◎ Run the URL and history update steps with document and newURL.
  17. %文書 の`初期~about_blankか$doc ~SET ~F ◎ Set document's is initial about:blank to false.
  18. ~IF[ %文書 の`~iframe~loadは進捗-中か$ ~EQ ~T ] ⇒ %文書 の`~iframe~loadを黙らすか$ ~SET ~T ◎ If document's iframe load in progress flag is set, then set document's mute iframe load flag.
  19. %文書 の`~mode$doc ~SET `no-quirks^l ◎ Set document to no-quirks mode.
  20. 次のようにされた新たな`~HTML構文解析器$を %文書 に結付ける ⇒ 符号化法の`確度$ ~SET `無関連^i ◎ Create a new HTML parser and associate it with document.\

    これは、 `~scriptにより作成された構文解析器@ とされる。 ◎ This is a script-created parser\

    それは、 次の 2 つを意味する:

    • [ `document.open()$c / `document.close()$m ]~methodにより~closeできる。
    • その~tokenizerは、 ~end-of-file~tokenを発する前に,明示的な `document.close()$m の~callを待機する。
    ◎ (meaning that it can be closed by the document.open() and document.close() methods, and that the tokenizer will wait for an explicit call to document.close() before emitting an end-of-file token). The encoding confidence is irrelevant.
  21. `挿入~地点$ ~SET `入力~stream$の終端の直前 (入力~streamは、 この時点で空になる。) ◎ Set the insertion point to point at just before the end of the input stream (which at this point will be empty).
  22. `文書の現在の準備度を更新する$( %文書, `loading^l ) ◎ Update the current document readiness of document to "loading".

    注記: これにより `readystatechange$et ~eventが発火されるが、 その~eventは,実際には作者~codeから観測-可能にならない — 上の段が,それを観測できる `すべての~event~listener/~event~handlerを消去する$ので。 ◎ This causes a readystatechange event to fire, but the event is actually unobservable to author code, because of the previous step which erased all event listeners and handlers that could observe it.

  23. ~RET %文書 ◎ Return document.

注記: `document.open 手続き$は、 `文書$が[ `~load後~task用に準備済み$, `完全に読込まれ$る ]のどちらになるかには影響しない。 ◎ The document open steps do not affect whether a Document is ready for post-load tasks or completely loaded.

`open(unused1, unused2)@m ~method手続きは ⇒ ~RET `document.open 手続き$( コレ ) ◎ The open(unused1, unused2) method must return the result of running the document open steps with this.

注記: %unused1, %unused2 引数は無視されるが、 1 〜 2 個の引数で関数を~callする~codeが働き続けられるよう,~IDLには保たれる。 それらは Web IDL の`多重定義~解決~algo$の規則に因り必要yである — その規則は、 引数が無い~callに対し `TypeError^E 例外を投出する。 `whatwg/webidl 課題 #581@https://github.com/whatwg/webidl/issues/581$ にて、 除去を許容するために~algoを変更することについて,究明-中にある。 `WEBIDL$r ◎ The unused1 and unused2 arguments are ignored, but kept in the IDL to allow code that calls the function with one or two arguments to continue working. They are necessary due to Web IDL overload resolution algorithm rules, which would throw a TypeError exception for such calls had the arguments not been there. whatwg/webidl issue #581 investigates changing the algorithm to allow for their removal. [WEBIDL]

`~openW(url, name, features)@m ~method手続きは: ◎ The open(url, name, features) method must run these steps:

  1. ~IF[ コレは`全部的に作動中$でない ] ⇒ ~THROW `InvalidAccessError$E ◎ If this is not fully active, then throw an "InvalidAccessError" DOMException exception.
  2. ~RET `~window~open手続き$( %url, %name, %features ) ◎ Return the result of running the window open steps with url, name, and features.

8.4.2. 入力~streamの~close法

%document.`close()$m
`document.open()$c ~methodで~openされた入力~streamを~closeする。 ◎ Closes the input stream that was opened by the document.open() method.
次の場合、 `InvalidStateError$E 例外を投出する ⇒# `文書$は`~XML文書$である / `~custom要素~構築子$を現在~実行している ◎ Throws an "InvalidStateError" DOMException if the Document is an XML document. ◎ Throws an "InvalidStateError" DOMException if the parser is currently executing a custom element constructor.

`Document$I の `close()@m ~method手続きは: ◎ The close() method must run the following steps:

  1. ~IF[ コレは`~XML文書$である ] ⇒ ~THROW `InvalidStateError$E ◎ If this is an XML document, then throw an "InvalidStateError" DOMException.
  2. ~IF[ コレの`動的~markup挿入-時には投出する~counter$ ~GT 0 ] ⇒ ~THROW `InvalidStateError$E ◎ If this's throw-on-dynamic-markup-insertion counter is greater than zero, then throw an "InvalidStateError" DOMException.
  3. %構文解析器 ~LET コレの`~scriptにより作成された構文解析器$は[ 在るならば それ / 無いならば ε ] ◎ ↓
  4. ~IF[ %構文解析器 ~EQ ε ] ⇒ ~RET ◎ If there is no script-created parser associated with this, then return.
  5. %構文解析器 の`入力~stream$の終端に`明示的な~EOF$を挿入する ◎ Insert an explicit "EOF" character at the end of the parser's input stream.
  6. ~IF[ コレの`構文解析器を阻んでいる~script$ ~NEQ ~NULL ] ⇒ ~RET ◎ If this's pending parsing-blocking script is not null, then return.
  7. %構文解析器 の~tokenizerを走らす ⇒ ~tokenizerから~tokenが発されるごとに,それを処理する。 [ ~tokenizerが`明示的な~EOF$に達するか,`~event~loopを回す$ ]時点で停止する。 ◎ Run the tokenizer, processing resulting tokens as they are emitted, and stopping when the tokenizer reaches the explicit "EOF" character or spins the event loop.

8.4.3. `document.write()^c

%document.`write(...text)$m
一般に,所与の文字列(たち)を`文書$の入力~streamに追加する。 ◎ In general, adds the given string(s) to the Document's input stream.
この~methodの挙動は、 とても特異的である。 一部の事例では、 `~HTML構文解析器$が走っている間に 構文解析器の状態に影響し得る — その結果、 文書の~sourceに対応しない~DOMになり得る(例:書込まれた文字列が `<plaintext>^l や `<!--^l であった場合など)。 別の事例では、 `document.open()$c が~callされていたかのように,現在の~pageをまず~clearすることもある。 さらには、 単純に無視されたり, 例外を投出する事例もある。 ~UAには、 この~methodを介して挿入された `script^e 要素に対しては, `実行するのを避けることが明示的に許容される@~HTMLparsing#document-written-scripts-intervention$。 この~methodの正確な挙動は、 ~network待時間に依存する事例すらあり、 とても~debugし難い失敗へ導く。 これらすべての理由から、 この~methodは利用しないことが強く奨励される。 ◎ This method has very idiosyncratic behavior. In some cases, this method can affect the state of the HTML parser while the parser is running, resulting in a DOM that does not correspond to the source of the document (e.g. if the string written is the string "<plaintext>" or "<!--"). In other cases, the call can clear the current page first, as if document.open() had been called. In yet more cases, the method is simply ignored, or throws an exception. Users agents are explicitly allowed to avoid executing script elements inserted via this method. And to make matters even worse, the exact behavior of this method can in some cases be dependent on network latency, which can lead to failures that are very hard to debug. For all these reasons, use of this method is strongly discouraged.
次の場合、 `InvalidStateError$E 例外を投出する ⇒# `文書$は`~XML文書$である / `~custom要素~構築子$を現在~実行している ◎ Throws an "InvalidStateError" DOMException when invoked on XML documents. ◎ Throws an "InvalidStateError" DOMException if the parser is currently executing a custom element constructor.

この~methodは、 `script$e や`~event~handler内容~属性$の様な危険にもなり得る[ 要素, 属性 ]を除去するための無毒化を遂行しない。 ◎ This method performs no sanitization to remove potentially-dangerous elements and attributes like script or event handler content attributes.

各 `文書$には `破壊的な書込nは無視する~counter@ があり、 初期~時は 0 に設定するモノトスル。 この~counterは、 `script$e 要素の処理と併用され,[ 外部~scriptが、[ `document.write()$c を利用して,暗黙的に `document.open()$c を~callする ]ことにより,文書を吹飛ばす ]のを防ぐために利用される。 ◎ Document objects have an ignore-destructive-writes counter, which is used in conjunction with the processing of script elements to prevent external scripts from being able to use document.write() to blow away the document by implicitly calling document.open(). Initially, the counter must be set to zero.

`document.write 手続き@ は、 所与の ( `文書$ %文書, 文字列 %入力 ) に対し,次を走らす: ◎ The document write steps, given a Document object document and a string input, are as follows:

  1. ~IF[ %文書 は`~XML文書$である ] ⇒ ~THROW `InvalidStateError$E ◎ If document is an XML document, then throw an "InvalidStateError" DOMException.
  2. ~IF[ %文書 の`動的~markup挿入-時には投出する~counter$ ~GT 0 ] ⇒ ~THROW `InvalidStateError$E ◎ If document's throw-on-dynamic-markup-insertion counter is greater than 0, then throw an "InvalidStateError" DOMException.
  3. ~IF[ %文書 の`作動中な構文解析器は中止されたか$ ~EQ ~T ] ⇒ ~RET ◎ If document's active parser was aborted is true, then return.
  4. ~IF[ `挿入~地点$ ~EQ ε ]: ◎ If the insertion point is undefined, then:

    1. ~IF[ %文書 の`~unload~counter$ ~GT 0 ]~OR[ %文書 の`破壊的な書込nは無視する~counter$ ~GT 0 ] ⇒ ~RET ◎ If document's unload counter is greater than 0 or document's ignore-destructive-writes counter is greater than 0, then return.
    2. `document.open 手続き$( %文書 ) ◎ Run the document open steps with document.
  5. %入力 を`入力~stream$内の`挿入~地点$に挿入する ◎ Insert input into the input stream just before the insertion point.
  6. ~IF[ %文書 の`構文解析器を阻んでいる~script$ ~NEQ ~NULL ] ⇒ ~RET ◎ If document's pending parsing-blocking script is null,\
  7. %入力 を`~HTML構文解析器$に処理させる: ◎ then have the HTML parser process input,\

    • 符号位置を 1 個ずつ与え,結果の~tokenが発される度にそれを処理する。 ◎ one code point at a time, processing resulting tokens as they are emitted, and\
    • 次のいずれかが生じたときに停止する ⇒ ~tokenizerが挿入~地点に達したとき / ~tokenizerの処理が ~tree構築~段階にて中止されたとき (これは、 `script$e 終了~tag~tokenが~tokenizerにより発された場合に起こり得る)。 ◎ stopping when the tokenizer reaches the insertion point or when the processing of the tokenizer is aborted by the tree construction stage (this can happen if a script end tag token is emitted by the tokenizer).

    注記: `document.write()$c が,~inlineに実行している~scriptから~callされている場合(すなわち,構文解析器が `script$e を終了~tagまで構文解析したことにより,~callされた)、 これは `構文解析器の再入呼出し@~HTMLparsing#nestedParsing$になる。 [ 構文解析器の`静止するか$ ~EQ ~T ]の場合、 ~tokenizerにおける `静止するかの検査@~HTMLparsing#check-parser-pause-flag$により,[ ~tokenizerは即時に中止され,~HTMLは構文解析されない ]ことになる。 ◎ If the document.write() method was called from script executing inline (i.e. executing because the parser parsed a set of script tags), then this is a reentrant invocation of the parser. If the parser pause flag is set, the tokenizer will abort immediately and no HTML will be parsed, per the tokenizer's parser pause flag check.

`Document$I の `write(...)@m ~method手続きは ⇒ `document.write 手続き$( コレ, 次に与える文字列 ) ⇒ 渡されたすべての引数を順に連結した結果 ◎ The document.write(...) method steps are to run the document write steps with this and a string that is the concatenation of all arguments passed.

8.4.4. `document.writeln()^c

%document.`writeln(...text)$m
所与の文字列(たち)を `文書$の入力~streamに追加した上で、 改行文字も追加する。 必要yなら, `open()$m ~methodも暗黙的に~callする。 ◎ Adds the given string(s) to the Document's input stream, followed by a newline character. If necessary, calls the open() method implicitly first.
次の場合、 `InvalidStateError$E 例外を投出する ⇒# `文書$は`~XML文書$である / `~custom要素~構築子$を現在~実行している ◎ Throws an "InvalidStateError" DOMException when invoked on XML documents. ◎ Throws an "InvalidStateError" DOMException if the parser is currently executing a custom element constructor.

この~methodは、 `script$e や`~event~handler内容~属性$の様な危険にもなり得る[ 要素, 属性 ]を除去するための無毒化を遂行しない。 ◎ This method performs no sanitization to remove potentially-dangerous elements and attributes like script or event handler content attributes.

`Document$I の `writeln(...)@m ~method手続きは ⇒ `document.write 手続き$( コレ, 次に与える文字列 ) ⇒ 渡されたすべての引数を順に連結した結果に `000A^U LINE FEED を付加した結果 ◎ The document.writeln(...) method steps are to run the document write steps with this and a string that is the concatenation of all arguments passed and U+000A LINE FEED.

8.5. ~DOMの構文解析~APIと直列化~API

partial interface `Element$I {
  [`CEReactions$] undefined `setHTMLUnsafe$m(`HTMLString$ %html);
  DOMString `getHTML$m(optional `GetHTMLOptions$I %options = {});

  [`CEReactions$] attribute [`LegacyNullToEmptyString$] `HTMLString$ `innerHTML$m;
  [`CEReactions$] attribute [`LegacyNullToEmptyString$] `HTMLString$ `outerHTML$m;
  [`CEReactions$] undefined `insertAdjacentHTML$m(DOMString position, `HTMLString$ %string);
};

partial interface `ShadowRoot$I {
  [`CEReactions$] undefined `setHTMLUnsafe$m1(`HTMLString$ %html);
  DOMString `getHTML$m1(optional `GetHTMLOptions$I options = {});

  [`CEReactions$] attribute [`LegacyNullToEmptyString$] `HTMLString$ `innerHTML$m1;
};

dictionary `GetHTMLOptions@I {
  boolean `serializableShadowRoots@mb = false;
  sequence<`ShadowRoot$I> `shadowRoots@mb = [];
};

8.5.1. `DOMParser^I ~interface

`DOMParser$I ~interfaceは、 文字列を[ ~HTML/~XML ]として構文解析して,新たな`文書$を作成することを,作者に許容する。 ◎ The DOMParser interface allows authors to create new Document objects by parsing strings, as either HTML or XML.

%parser = `new DOMParser()$m
新たな `DOMParser$I ~objを構築する。 ◎ Constructs a new DOMParser object.
%document = %parser.`parseFromString$m( %string, %type )
%string を, %type に応じて[ ~HTML構文解析器/~XML構文解析器 ]を利用する下で構文解析して、 結果の`文書$を返す。 %type は、 次に挙げるいずれかをとり得る ⇒# `text/html$mt (これは、~HTML構文解析器を呼出すことになる), (以下は、~XML構文解析器を呼出すことになる) `text/xml$mt, `application/xml$mt, `application/xhtml+xml$mt, `image/svg+xml$mt ◎ Parses string using either the HTML or XML parser, according to type, and returns the resulting Document. type can be "text/html" (which will invoke the HTML parser), or any of "text/xml", "application/xml", "application/xhtml+xml", or "image/svg+xml" (which will invoke the XML parser).
~XML構文解析器においては、 %string を構文解析できない場合、 返される`文書$は,結果の~errorを述べている要素を包含することになる。 ◎ For the XML parser, if string cannot be parsed, then the returned Document will contain elements describing the resulting error.
構文解析の間は, `script$e 要素は評価されず、 結果の文書の`符号化法$docは,常に`~UTF-8$になることに注意。 文書の`~URL$docは, %構文解析器 に`関連な大域~obj$から継承されることになる。 ◎ Note that script elements are not evaluated during parsing, and the resulting document's encoding will always be UTF-8. The document's URL will be inherited from parser's relevant global object.
上に挙げたもの以外の %type 値は、 【 `DOMParserSupportedType$I 値でないので,】 `TypeError^E 例外を投出させることになる。 ◎ Values other than the above for type will cause a TypeError exception to be thrown.

注記: `DOMParser$I の設計が,~classとして構築してから `parseFromString()$m ~methodを~callする必要があるのは、 不幸な歴史的~遺物である。 この機能性を今日~設計するなら,自立的な関数にするであろう。 ~HTMLを構文解析するための現代の代替は、 `Document$I の `parseHTMLUnsafe()$m である。 ◎ The design of DOMParser, as a class that needs to be constructed and then have its parseFromString() method called, is an unfortunate historical artifact. If we were designing this functionality today it would be a standalone function. For parsing HTML, the modern alternative is Document.parseHTMLUnsafe().

この~methodは、 `script$e や`~event~handler内容~属性$の様な危険にもなり得る[ 要素, 属性 ]を除去するための無毒化を遂行しない。 ◎ This method performs no sanitization to remove potentially-dangerous elements and attributes like script or event handler content attributes.

[Exposed=Window]
interface `DOMParser@I {
  `constructor@#dom-domparser-constructor$();

  [NewObject] `Document$I `parseFromString$m(`HTMLString$ %string, `DOMParserSupportedType$I %type);
};

enum `DOMParserSupportedType@I {
  `text/html$l,
  `text/xml$l,
  `application/xml$l,
  `application/xhtml+xml$l,
  `image/svg+xml$l
};
`new DOMParser()@m 構築子~手続きは、 何もしない。 ◎ The new DOMParser() constructor steps are to do nothing.

`parseFromString(string, type)@m ~method手続きは: ◎ The parseFromString(string, type) method steps are:

  1. %文書 ~LET 新たな`文書$ — その ⇒# `内容~型$doc ~SET %type, `~URL$doc ~SET コレに`関連な大域~obj$に`結付けられた文書$の`~URL$doc ◎ Let document be a new Document, whose content type is type and URL is this's relevant global object's associated Document's URL.

    %文書 の`符号化法$docは、 既定の`~UTF-8$のままにされることになる。 特に, %文字列 を構文解析する間に見出された どの[ ~XML宣言/ `meta$e 要素 ]にも効果はない。 ◎ The document's encoding will be left as its default, of UTF-8. In particular, any XML declarations or meta elements found while parsing string will have no effect.

  2. ~IF[ %type ~EQ `text/html@l ] ⇒ `文字列から~HTMLを構文解析する$( %文書, %文字列 ) ◎ Switch on type: ◎ "text/html" • Parse HTML from a string given document and string.

    注記: %文書 が`属する閲覧~文脈$は無いので、 %文書 用の`~scriptingは不能化される@~WAPI#concept-n-noscript$。 ◎ Since document does not have a browsing context, scripting is disabled.

  3. ~ELSE: ◎ Otherwise

    1. `~XML構文解析器$ %構文解析器 を作成して, %文書 に結付ける — その`~XML~scriptingの~supportは不能化する@~HTMLxml#xml-scripting-support-disabled$ ◎ Create an XML parser parse, associated with document, and with XML scripting support disabled.
    2. %構文解析器 を利用して %文字列 を構文解析する ◎ Parse string using parser.
    3. ~IF[ 前~段の結果は[ ~XML整形式性 / ~XML名前空間 整形式性 ]~errorになった ]: ◎ If the previous step resulted in an XML well-formedness or XML namespace well-formedness error, then:

      1. ~Assert: %文書 には子~nodeは無い。 ◎ Assert: document has no child nodes.
      2. %根 ~LET `要素を作成する$( %文書, `parsererror^l, `http://www.mozilla.org/newlayout/xml/parsererror.xml^l ) ◎ Let root be the result of creating an element given document, "parsererror", and "http://www.mozilla.org/newlayout/xml/parsererror.xml".
      3. 任意選択で ⇒ 構文解析~errorの資質を述べるような属性や子を %根 に追加する ◎ Optionally, add attributes or children to root to describe the nature of the parsing error.
      4. %文書 に`~nodeを付加する$( %根 ) ◎ Append root to document.
  4. ~RET %文書 ◎ Return document.

`文字列から~HTMLを構文解析する@ ときは、 所与の ( `文書$ %文書, `文字列$ %~HTML ) に対し: ◎ To parse HTML from a string, given a document Document and a string html:

  1. %文書 の`種別$doc ~SET `html^l ◎ Set document's type to "html".
  2. `~HTML構文解析器$ %構文解析器 を作成して, %文書 に結付ける ◎ Create an HTML parser parser, associated with document.
  3. %構文解析器 の符号化法の`確度$ ~SET `無関連^i ◎ ↓
  4. %構文解析器 の`入力~stream$の中へ %~HTML を設置する ◎ Place html into the input stream for parser. The encoding confidence is irrelevant.
  5. %構文解析器 を開始して,挿入した %文字列 を成すすべての文字を消費するまで走らす ◎ Start parser and let it run until it has consumed all the characters just inserted into the input stream.

    注記: 文書の`~mode$docは、 この段で変異するかもしれない。 ◎ This might mutate the document's mode.

8.5.2. 安全でない~HTML構文解析~method

%element.`setHTMLUnsafe(html)$m
~HTML構文解析器を利用して %html を構文解析する — その結果で %element の子~群を置換する。 %element が,当の~HTML構文解析器~用の文脈を供する。 ◎ Parses html using the HTML parser, and replaces the children of element with the result. element provides context for the HTML parser.
%shadowRoot.`setHTMLUnsafe(html)$m1
~HTML構文解析器を利用して %html を構文解析する — その結果で %shadowRoot の子~群を置換する。 %shadowRoot の`~host$が,当の~HTML構文解析器~用の文脈を供する。 ◎ Parses html using the HTML parser, and replaces the children of shadowRoot with the result. shadowRoot's host provides context for the HTML parser.
%doc = `Document$I.`parseHTMLUnsafe(html)$m
~HTML構文解析器を利用して %html を構文解析した結果の`文書$を返す。 ◎ Parses html using the HTML parser, and returns the resulting Document.
`script$e 要素は構文解析する間に評価されないことに加え, 結果の文書の`符号化法$docは常に `~UTF-8$ になることに注意。 文書の`~URL$docは `~about_blank$sc になる。 ◎ Note that script elements are not evaluated during parsing, and the resulting document's encoding will always be UTF-8. The document's URL will be about:blank.

これらの~methodは、[ `script$e や `~event~handler内容~属性$の様な危険になり得る要素や属性 ]を除去するための無毒化を遂行しない。 ◎ These methods perform no sanitization to remove potentially-dangerous elements and attributes like script or event handler content attributes.

`Element$I の `setHTMLUnsafe(html)@m ~method手続きは: ◎ Element's setHTMLUnsafe(html) method steps are:

  1. %~target ~LET コレ ◎ ↓
  2. ~IF[ コレは `template$e 要素である ] ⇒ %~target ~LET コレの`~template内容$ ◎ Let target be this's template contents if this is a template element; otherwise this.
  3. `~HTMLを安全でなく設定する$( %~target, コレ, %html ) ◎ Unsafely set HTML given target, this, and html.

`ShadowRoot$I の `setHTMLUnsafe(html)@m1 ~method手続きは ⇒ `~HTMLを安全でなく設定する$( コレ, コレの`~host$, %html ) ◎ ShadowRoot's setHTMLUnsafe(html) method steps are to unsafely set HTML given this, this's shadow host, and html.

`~HTMLを安全でなく設定する@ ときは、 所与の ( [ `要素$/`文書片$ ] %~target, `要素$ %文脈~要素, `文字列$ %~HTML ) に対し: ◎ To unsafely set HTML, given an Element or DocumentFragment target, an Element contextElement, and a string html:

  1. %新たな子~群 ~LET `~HTML素片の構文解析~algo$( %文脈~要素, %~HTML, ~T ) ◎ Let newChildren be the result of the HTML fragment parsing algorithm given contextElement, html, and true.
  2. %文書片 ~LET 新たな`文書片$ — その ⇒# `~node文書$ ~SET %文脈~要素 の`~node文書$ ◎ Let fragment be a new DocumentFragment whose node document is contextElement's node document.
  3. %新たな子~群 を成す ~EACH( %~node ) に対し ⇒ %文書片 に`~nodeを付加する$( %~node ) ◎ For each node in newChildren, append node to fragment.
  4. %~target の`全~内容を~nodeで置換する$( %文書片 ) ◎ Replace all with fragment within target.

静的な `parseHTMLUnsafe(html)@m ~method手続きは: ◎ The static parseHTMLUnsafe(html) method steps are:

  1. %文書 ~LET 新たな`文書$ — その ⇒# `内容~型$doc ~SET `text/html^l ◎ Let document be a new Document, whose content type is "text/html".

    注記: %文書 が`属する閲覧~文脈$は無いので、 %文書 用の`~scriptingは不能化される@~WAPI#concept-n-noscript$。 ◎ Since document does not have a browsing context, scripting is disabled.

  2. %文書 の`宣言的な~shadow根を許容するか$doc ~SET ~T ◎ Set document's allow declarative shadow roots to true.
  3. `文字列から~HTMLを構文解析する$( %文書, %html ) ◎ Parse HTML from a string given document and html.
  4. ~RET %文書 ◎ Return document.

8.5.3 ~HTMLの直列化~method

%html = %element.`getHTML(options)$m ◎ html = element.getHTML({ serializableShadowRoots, shadowRoots })

%element を~HTMLへ直列化した結果を返す。 %element の中の各`~shadow根$は、 供された各~optionに則って直列化される: ◎ Returns the result of serializing element to HTML. Shadow roots within element are serialized according to the provided options:

  • %options[ "`serializableShadowRoots$mb" ] ~EQ ~T の場合、 次を満たす~shadow根は,すべて直列化される ⇒ `直列化-可能か$sR ~EQ ~T ◎ If serializableShadowRoots is true, then all shadow roots marked as serializable are serialized.
  • %options[ "`shadowRoots$mb" ] に供された配列~内に指定された すべての~shadow根は、 その`直列化-可能か$sRを問わず,直列化される。 ◎ If the shadowRoots array is provided, then all shadow roots specified in the array are serialized, regardless of whether or not they are marked as serializable.

どちらの~optionも供されなかった場合、 直列化される~shadow根は無い。 ◎ If neither option is provided, then no shadow roots are serialized.

%html = %shadowRoot.`getHTML(options)$m1 ◎ html = shadowRoot.getHTML({ serializableShadowRoots, shadowRoots })
%shadowRoot を~HTMLへ直列化した結果を返す — 文脈~要素として %shadowRoot の`~host$を利用する下で。 %shadowRoot の中の`~shadow根$は、 上と同じく,供された各~optionに則って直列化される。 ◎ Returns the result of serializing shadowRoot to HTML, using its shadow host as the context element. Shadow roots within shadowRoot are serialized according to the provided options, as above.
`Element$I の `getHTML(options)@m ~method手続きは ⇒ ~RET `~HTML素片~直列化~algo$( コレ, %options[ "`serializableShadowRoots$mb" ], %options[ "`shadowRoots$mb" ] ) ◎ Element's getHTML(options) method steps are to return the result of HTML fragment serialization algorithm with this, options["serializableShadowRoots"], and options["shadowRoots"].
`ShadowRoot$I の `getHTML(options)@m1 ~method手続きは ⇒ ~RET `~HTML素片~直列化~algo$( コレ, %options[ "`serializableShadowRoots$mb" ], %options[ "`shadowRoots$mb" ] ) ◎ ShadowRoot's getHTML(options) method steps are to return the result of HTML fragment serialization algorithm with this, options["serializableShadowRoots"], and options["shadowRoots"].

8.5.4. `innerHTML^m ~prop

`innerHTML$m ~propには、 `DOMPARSING$r の`課題~追跡器@https://github.com/w3c/DOM-Parsing/issues$において,いくつか未決な課題がある — そこには、 その仕様に伴われる様々な問題が文書化されている。 ◎ The innerHTML property has a number of outstanding issues in the DOM Parsing and Serialization issue tracker, documenting various problems with its specification.

%element.`innerHTML$m
%element の内容を表現する[[ ~HTML/~XML ]を成す素片 ]を返す。 ◎ Returns a fragment of HTML or XML that represents the element's contents.
~XML文書の事例では、 %element を~XMLへ直列化できない場合には, `InvalidStateError$E 例外を投出する。 ◎ In the case of an XML document, throws a "InvalidStateError" DOMException if the element cannot be serialized to XML.
%element.`innerHTML$m = %value
所与の文字列を構文解析した結果の~nodeたちで, %element の内容を置換する。 ◎ Replaces the contents of the element with nodes parsed from the given string.
~XML文書の事例では、 所与の文字列は整形式でない場合には, `SyntaxError$E 例外を投出する。 ◎ In the case of an XML document, throws a "SyntaxError" DOMException if the given string is not well-formed.
%shadowRoot.`innerHTML$m1
%element の内容を表現する[[ ~HTML【/~XML】 ]を成す素片 ]を返す。 ◎ Returns a fragment of HTML that represents the shadow roots's contents.
%shadowRoot.`innerHTML$m1 = %value
所与の文字列を構文解析した結果の~nodeたちで, %shadowRoot の内容を置換する。 ◎ Replaces the contents of the shadow root with nodes parsed from the given string.

これらの~propの設定子は、 `script$e や`~event~handler内容~属性$の様な危険にもなり得る[ 要素, 属性 ]を除去するための無毒化を遂行しない。 ◎ These properties' setters perform no sanitization to remove potentially-dangerous elements and attributes like script or event handler content attributes.

`素片に直列化する@ ときは、 所与の ( [ `要素$/`文書片$ ] %~node, 真偽値 %整形式が要求されるか ) に対し ⇒ ~RET %~node の`~node文書$に応じて ⇒# `~HTML文書$であるならば `~HTML素片~直列化~algo$( %~node, ~F, « » ) / `~XML文書$であるならば `~XML直列化$( %~node, %整形式が要求されるか ) ◎ The fragment serializing algorithm steps, given an Element or DocumentFragment node and a boolean require well-formed, are: • Let context document be node's node document. • If context document is an HTML document, return the result of HTML fragment serialization algorithm with node, false, and « ». • Return the XML serialization of node given require well-formed.

`素片を構文解析する@ ときは、 所与の ( [ `要素$/`文書片$ ]%文脈, 文字列 %~markup ) に対し: ◎ The fragment parsing algorithm steps, given an Element or DocumentFragment context and a string markup, are:

  1. %~algo ~LET %文脈 の`~node文書$に応じて ⇒# `~HTML文書$であるならば `~HTML素片の構文解析~algo$ / `~XML文書$であるならば `~XML素片の構文解析~algo$ ◎ Let algorithm be the HTML fragment parsing algorithm. ◎ If context's node document is an XML document, then set algorithm to the XML fragment parsing algorithm.
  2. %新たな子~群 ~LET %~algo( %文脈, %~markup ) ◎ Let new children be the result of invoking algorithm given markup, with context set to context.
  3. %文書片 ~LET 新たな`文書片$ — その ⇒ `~node文書$ ~SET %文脈 の`~node文書$ ◎ Let fragment be a new DocumentFragment whose node document is context's node document.
  4. %新たな子~群 を成す ~EACH( %~node ) に対し,`~tree順序$で ⇒ %文書片 に`~nodeを付加する$( %~node ) ◎ Append each Node in new children to fragment (in tree order).

    注記: これは、 %~node 用の`~node文書$が正しくなることを確保する。 ◎ This ensures the node document for the new nodes is correct.

  5. ~RET %文書片 ◎ Return fragment.

`Element$I の `innerHTML@m 属性の ◎ ↓

  • 取得子~手続きは ⇒ ~RET `素片に直列化する$( コレ, ~T ) ◎ Element's innerHTML getter steps are to return the result of running fragment serializing algorithm steps with this and true. ◎ ↓ ShadowRoot's innerHTML getter steps are to return the result of running fragment serializing algorithm steps with this and true.

  • 設定子~手続きは: ◎ Element's innerHTML setter steps are:

    1. %文脈 ~LET コレ ◎ Let context be this.
    2. %文書片 ~LET `素片を構文解析する$( %文脈, 所与の値 ) ◎ Let fragment be the result of invoking the fragment parsing algorithm steps with context and the given value.
    3. ~IF[ %文脈 は `template$e 要素である ] ⇒ %文脈 ~SET %文脈 の`~template内容$ (ある`文書片$) ◎ If context is a template element, then set context to the template element's template contents (a DocumentFragment).

      注記: `template$e 要素に対し `innerHTML$m を設定した場合、 その`子~群$ではなく,その`~template内容$を成すすべての~nodeを置換することになる。 ◎ Setting innerHTML on a template element will replace all the nodes in its template contents rather than its children.

    4. %文脈 の`全~内容を~nodeで置換する$( %文書片 ) ◎ Replace all with fragment within context.

`ShadowRoot$I の `innerHTML@m1 属性の: ◎ ↓

  • 取得子~手続きは ⇒ ~RET `素片に直列化する$( コレ, ~T ) ◎ ↑
  • 設定子~手続きは: ◎ ShadowRoot's innerHTML setter steps are:

    1. %文脈 ~LET コレの`~host$ ◎ Let context be this's host.
    2. %文書片 ~LET `素片を構文解析する$( %文脈, 所与の値 ) ◎ Let fragment be the result of invoking the fragment parsing algorithm steps with context and the given value.
    3. コレの`全~内容を~nodeで置換する$( %文書片 ) ◎ Replace all with fragment within this.

8.5.5. `outerHTML^m ~prop

`outerHTML$m ~propには、 `DOMPARSING$r の`課題~追跡器@https://github.com/w3c/DOM-Parsing/issues$において,いくつか未決な課題がある — そこには、 その仕様に伴われる様々な問題が文書化されている。 ◎ The outerHTML property has a number of outstanding issues in the DOM Parsing and Serialization issue tracker, documenting various problems with its specification.

%element.`outerHTML$m
[ 要素とその内容 ]を表現する[[ ~HTML/~XML ]を成す素片 ]を返す。 ◎ Returns a fragment of HTML or XML that represents the element and its contents.
~XML文書の事例では、 %element を~XMLに直列化できない場合, `InvalidStateError$E 例外が投出される。 ◎ In the case of an XML document, throws a "InvalidStateError" DOMException if the element cannot be serialized to XML.
%element.`outerHTML$m = %value
%element を所与の文字列から構文解析した結果の~nodeたちで置換する。 ◎ Replaces the element with nodes parsed from the given string.
~XML文書の事例では、 所与の文字列は整形式でない場合, `SyntaxError$E 例外が投出される。 ◎ In the case of an XML document, throws a "SyntaxError" DOMException if the given string is not well-formed.
%element の親は`文書$である場合、 `NoModificationAllowedError$E 例外が投出される。 ◎ Throws a "NoModificationAllowedError" DOMException if the parent of the element is a Document.

この~propの設定子は、 `script$e や`~event~handler内容~属性$の様な危険にもなり得る[ 要素, 属性 ]を除去するための無毒化を遂行しない。 ◎ This property's setter performs no sanitization to remove potentially-dangerous elements and attributes like script or event handler content attributes.

`Element$I の `outerHTML@m 属性の: ◎ ↓

  • 取得子~手続きは: ◎ Element's outerHTML getter steps are:

    1. %文書片 ~LET 新たな`文書片$ — その ⇒ `~node文書$ ~SET コレの`~node文書$ ◎ Let element be a fictional node\
    2. %文書片 に`~nodeを付加する$( コレ ) ◎ whose only child is this.
    3. ~RET `素片に直列化する$( %文書片, ~T ) ◎ Return the result of running fragment serializing algorithm steps with element and true.

    【 %文書片 は、 要素~自身の~tagも含めて直列化するために必要になる — これは、 原文では “`fictional node^en (架空な~node)” としか記されていないが, `文書片$で用を成すであろう。 】

  • 設定子~手続きは: ◎ Element's outerHTML setter steps are:

    1. %親 ~LET コレの`親$ ◎ Let parent be this's parent.
    2. ~IF[ %親 ~EQ ~NULL ] ⇒ ~RET (以降の手続きを走らせても,作成される~nodeへの参照を得する仕方はないので。) ◎ If parent is null, return. There would be no way to obtain a reference to the nodes created even if the remaining steps were run.
    3. ~IF[ %親 は`文書$である ] ⇒ ~THROW `NoModificationAllowedError$E ◎ If parent is a Document, throw a "NoModificationAllowedError" DOMException.
    4. ~IF[ %親 は`文書片$である ] ⇒ %親 ~LET `要素を作成する$( コレの`~node文書$, "`body$e", `~HTML名前空間$ ) ◎ If parent is a DocumentFragment, set parent to the result of creating an element given this's node document, body, and the HTML namespace.
    5. %文書片 ~LET `素片を構文解析する$( %親, 所与の値 ) ◎ Let fragment be the result of invoking the fragment parsing algorithm steps given parent and the given value.
    6. コレの`親$の中で`子を~nodeに置換する$( コレ, %文書片 ) ◎ Replace this with fragment within this's parent.

8.5.6. `insertAdjacentHTML()^m ~method

`insertAdjacentHTML()$m ~methodには、 `DOMPARSING$r の`課題~追跡器@https://github.com/w3c/DOM-Parsing/issues$において,いくつか未決な課題がある — そこには、 その仕様に伴われる様々な問題が文書化されている。 ◎ The insertAdjacentHTML() method has a number of outstanding issues in the DOM Parsing and Serialization issue tracker, documenting various problems with its specification.

%element.`insertAdjacentHTML(position, string)$m

%string を[ ~HTML/~XML ]として構文解析した上で、 その結果の~nodeを[ %position に応じて次に与える位置 ]に挿入する: ◎ Parses string as HTML or XML and inserts the resulting nodes into the tree in the position given by the position argument, as follows:

`beforebegin^l
%element の前 (すなわち,直前の同胞との合間) ◎ Before the element itself (i.e., after element's previous sibling)
`afterbegin^l
%element の内側の先頭 (すなわち,最初の子の前) ◎ Just inside the element, before its first child.
`beforeend^l
%element の内側の末尾 (すなわち,最後の子の後) ◎ Just inside the element, after its last child.
`afterend^l
%element の後 (すなわち,直後の同胞との合間) ◎ After the element itself (i.e., before element's next sibling)
引数の値が妥当でない場合、 `SyntaxError$E 例外が投出される (例:`~XML文書$の事例では、 所与の文字列が整形式でない場合)。 ◎ Throws a "SyntaxError" DOMException if the arguments have invalid values (e.g., in the case of an XML document, if the given string is not well-formed).
所与の位置に挿入し得ない場合、 `NoModificationAllowedError$E 例外が投出される。 (例: `文書$の根~要素の後に要素を挿入しようとしたとき。) ◎ Throws a "NoModificationAllowedError" DOMException if the given position isn't possible (e.g. inserting elements after the root element of a Document).

この~methodは、 `script$e や`~event~handler内容~属性$の様な危険にもなり得る[ 要素, 属性 ]を除去するための無毒化を遂行しない。 ◎ This method performs no sanitization to remove potentially-dangerous elements and attributes like script or event handler content attributes.

`Element$I の `insertAdjacentHTML(position, string)@m ~method手続きは: ◎ Element's insertAdjacentHTML(position, string) method steps are:

  1. %文脈 ~LET ~NULL ◎ Let context be null.
  2. %position ~LET `~ASCII小文字~化する$( %position ) ◎ ↓
  3. %position に応じて: ◎ Use the first matching item from this list:

    `beforebegin^l ◎ If position is an ASCII case-insensitive match for the string "beforebegin"
    `afterend^l ◎ If position is an ASCII case-insensitive match for the string "afterend"
    1. %文脈 ~SET コレの`親$ ◎ Set context to this's parent.
    2. ~IF[ %文脈 ~EQ ~NULL ]~OR[ %文脈 は`文書$である ] ⇒ ~THROW `NoModificationAllowedError$E ◎ If context is null or a Document, throw a "NoModificationAllowedError" DOMException.
    `afterbegin^l ◎ If position is an ASCII case-insensitive match for the string "afterbegin"
    `beforeend^l ◎ If position is an ASCII case-insensitive match for the string "beforeend"
    %文脈 ~SET コレ ◎ Set context to this.
    他の場合 ◎ Otherwise
    ~THROW `SyntaxError$E ◎ Throw a "SyntaxError" DOMException.
  4. ~IF[ %文脈 は`要素$でない ]~OR[ ~AND↓ ]… ◎ If context is not an Element or all of the following are true:

    • %文脈 の`~node文書$は`~HTML文書$である ◎ context's node document is an HTML document;
    • %文脈 の`局所~名$el ~EQ "`html$e" ◎ context's local name is "html"; and
    • %文脈 の`名前空間$el ~EQ `~HTML名前空間$ ◎ context's namespace is the HTML namespace,

    …ならば ⇒ %文脈 ~SET `要素を作成する$( コレの`~node文書$, "`body$e", `~HTML名前空間$ ) ◎ set context to the result of creating an element given this's node document, body, and the HTML namespace.

  5. %文書片 ~LET `素片を構文解析する$( %文脈, %string ) ◎ Let fragment be the result of invoking the fragment parsing algorithm steps with context and string.
  6. %position に応じて: ◎ Use the first matching item from this list:

    `beforebegin^l ◎ If position is an ASCII case-insensitive match for the string "beforebegin"
    コレの`親$の中で`~nodeを子の前に挿入する$( %文書片, コレ ) ◎ Insert fragment into this's parent before this.
    `afterend^l ◎ If position is an ASCII case-insensitive match for the string "afterend"
    コレの中で`~nodeを子の前に挿入する$( %文書片, コレの`最初の子?$ ) ◎ Insert fragment into this before its first child.
    `beforeend^l† ◎ If position is an ASCII case-insensitive match for the string "afterbegin"
    コレに`~nodeを付加する$( %文書片 ) ◎ Append fragment to this.
    `afterend^l† ◎ If position is an ASCII case-insensitive match for the string "beforeend"
    コレの`親$の中で`~nodeを子の前に挿入する$( %文書片, コレの`直後の同胞?$ ) ◎ Insert fragment into this's parent before this's next sibling.

    【† 原文では `beforeend^l と `afterend^l が逆になっているが、 誤りであろう。 】

注記: `~node$を直に操作する他の~APIと同じく(および `innerHTML$m とは違って )、 `insertAdjacentHTML()$m は, `template$e 要素 %要素 に対する特別な取扱いを含まない。 ほとんどの事例では、 %要素 の子~nodeたちを直に操作する代わりに, %要素 の`~template内容$に対し `insertAdjacentHTML()$m を利用することが求まれよう。 ◎ As with other direct Node-manipulation APIs (and unlike innerHTML), insertAdjacentHTML() does not include any special handling for template elements. In most cases you will want to use templateEl.content.insertAdjacentHTML() instead of directly manipulating the child nodes of a template element.

8.5.7. `createContextualFragment()^m ~method

`createContextualFragment()$m ~methodには、 `DOMPARSING$r の`課題~追跡器@https://github.com/w3c/DOM-Parsing/issues$において,いくつか未決な課題がある — そこには、 その仕様に伴われる様々な問題が文書化されている。 ◎ The createContextualFragment() method has a number of outstanding issues in the DOM Parsing and Serialization issue tracker, documenting various problems with its specification.

%docFragment = %range.`createContextualFragment(string)$m
~markup文字列 %string から作成される`文書片$を返す — %string を構文解析する際の文脈として, %range の`始端~node$を利用する下で。 ◎ Returns a DocumentFragment created from the markup string string using range's start node as the context in which fragment is parsed.

この~methodは、 `script$e や`~event~handler内容~属性$の様な危険にもなり得る[ 要素, 属性 ]を除去するための無毒化を遂行しない。 ◎ This method performs no sanitization to remove potentially-dangerous elements and attributes like script or event handler content attributes.

partial interface `Range$I {
  [`CEReactions$, NewObject] `DocumentFragment$I `createContextualFragment$m(`HTMLString$ %string);
};

`createContextualFragment(string)@m ~method手続きは: ◎ Range's createContextualFragment(string) method steps are:

  1. %~node ~LET コレの`始端~node$ ◎ Let node be this's start node.
  2. %要素 ~LET ~NULL ◎ Let element be null.
  3. ~IF[ %~node は `Element$I を`実装-$する ] ⇒ %要素 ~SET %~node ◎ If node implements Element, set element to node.
  4. ~ELIF[ %~node は `Text$I を`実装-$する ]~OR[ %~node は `Comment$I を`実装-$する ] ⇒ %要素 ~SET %~node の`親~要素$ ◎ Otherwise, if node implements Text or Comment, set element to node's parent element.
  5. ~IF[ %要素 ~EQ ~NULL ]~OR[ ~AND↓ ]… ◎ If element is null or all of the following are true:

    • %要素 の`~node文書$は~HTML文書である ◎ element's node document is an HTML document;
    • %要素 の`局所~名$el ~EQ "`html$e" ◎ element's local name is "html"; and
    • %要素 の`名前空間$el ~EQ `~HTML名前空間$ ◎ element's namespace is the HTML namespace,

    …ならば ⇒ %要素 ~SET `要素を作成する$( コレの`~node文書$, "`body$e", `~HTML名前空間$ ) ◎ then set element to the result of creating an element given this's node document, body, and the HTML namespace.

  6. %文書片 ~LET `素片を構文解析する$( %要素, %string ) ◎ Let fragment node be the result of invoking the fragment parsing algorithm steps with element and string.
  7. %文書片 の`子孫$である ~EACH( `script$e 要素 %~script ) に対し ⇒ %~script の ⇒# `すでに開始したか$scE ~SET ~F `構文解析器~文書$scE ~SET ~NULL ◎ For each script of fragment node's script element descendants: • Set script's already started to false. • Set script's parser document to null.
  8. ~RET %文書片 ◎ Return fragment node.