HTML — 動的マークアップ挿入, 他

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()$m を利用して構文解析する~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()$m ~methodと同様に働く。 ◎ Works like the window.open() method.

各 `文書$には,真偽値をとる `作動中な構文解析器は中止されたか@ があり、 初期~時は ~F をとるとする。 これは、[ 文書にて`作動中な構文解析器$が中止された後 ]に[ ~scriptが[ `document.open()$m / `document.write()$m ]~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()$m が[ 構文解析-中に見出された~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()$m が[ %文書 が~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()$m が[ `~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()$m / `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()$m ~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()^m

%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()$m が~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.

各 `文書$には `破壊的な書込nは無視する~counter@ があり、 初期~時は 0 に設定するモノトスル。 この~counterは、 `script$e 要素の処理と併用され,[ 外部~scriptが、[ `document.write()$m を利用して,暗黙的に`document.open()$m を~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()$m ~methodが,~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()^m

%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.
`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の構文解析-法

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().

[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.`~setHTMLUnsafe0(html)$m
~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.

partial interface `Element$I {
  [`CEReactions$] undefined `setHTMLUnsafe$m(`HTMLString$ %html);
};

partial interface `ShadowRoot$I {
  [`CEReactions$] undefined `~setHTMLUnsafe0$m(`HTMLString$ %html);
};

`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 の `~setHTMLUnsafe0(html)@m ~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.