【譯】12.2.4 解析狀態 Parse state
HTML
Living Standard — Last Updated 20 August 2017
Parts of this specification are ? Copyright 2004-2014 Apple Inc., Mozilla Foundation, and Opera Software ASA.
You are granted a license to use, reproduce and create derivative works of this document.
The insertion mode is a state variable that controls the primary operation of the tree construction stage.
insertion mode 是一個狀態變量,它控制樹在構建階段的主要操纵。
Initially, the insertion mode is "initial". It can change to "before html", "before head", "in head", "in head noscript", "after head", "in body", "text", "in table", "in table text", "in caption", "in column group", "in table body", "in row", "in cell", "in select", "in select in table", "in template", "after body", "in frameset", "after frameset", "after after body", and "after after frameset" during the course of the parsing, as described in the stage. The insertion mode affects how tokens are processed and whether CDATA sections are supported.
最初,insertion mode 為 initial。在解析過程中,它可以改變為 before html、before head、in head、in head noscript、after head、in body、text、in table、in table text、in caption、in column group、in table body、in row、in cell、in select、in select in table、in template、after body、in frameset、after frameset、after after body、after after frameset,正如 階段中所描述的。insertion mode 影響如何處理 tokens ,以及是否撑持 CDATA 區段。
Several of these modes, namely "in head", "in body", "in table", and "in select", are special, in that the other modes defer to them at various times. When the algorithm below says that the user agent is to do something "using the rules for the m insertion mode", where m is one of these modes, the user agent must use the rules described under the m insertion mode‘s section, but must leave the insertion mode unchanged unless the rules in m themselves switch the insertion mode to a new value.
in heai、in body、in table、select,上述幾種模式是特殊的,因為其他模式在差别時候對他們進行響應。當下面的算法表白用戶代办代理是做某事「使用規則到達插入模式m」,這里的m是上述特殊模式之一,用戶代办代理必须使用不才面 m 插入模式的章節中描述的規則,但必须连结插入模式不變,除非該規則在 m 自身切換 insertion mode 為新值。
When the insertion mode is switched to "text" or "in table text", the original insertion mode is also set. This is the insertion mode to which the tree construction stage will return.
當插入模式切換為 text 或 in table text 時,也設置了原始插入模式。這是樹構建階段將返回的插入模式。
Similarly, to parse nested template elements, a stack of template insertion modes is used. It is initially empty. The current template insertion mode is the insertion mode that was most recently added to the stack of template insertion modes. The algorithms in the sections below will push insertion modes onto this stack, meaning that the specified insertion mode is to be added to the stack, and pop insertion modes from the stack, which means that the most recently added insertion mode must be removed from the stack.
類似的,使用一個模版插入模式的堆棧,來解析嵌套 template 元素。它最初是空的。當前插入模式是比来添加到插入模式堆棧的插入模式。下面章節中的算法將插入模式 push 到這個堆棧中,這意味著指定的插入模式將添加到堆棧中;並且從堆棧中 pop 插入模式,這意味著必须從堆棧中移除比来添加的插入模式。
When the steps below require the UA to reset the insertion mode appropriately, it means the UA must follow these steps:
當下面的步驟要求用戶代办代理適當的重置插入模式,意味著用戶代办代理必须遵循這些步驟:
Let last be false.
設 last 為 false。
Let node be the last node in the stack of open elements.
設 node 為打開元素堆棧的最後一個節點。
Loop: If node is the first node in the stack of open elements, then set last to true, and, if the parser was originally created as part of the HTML fragment parsing algorithm (fragment case), set node to the context element passed to that algorithm.
Loop:如果 node 是打開元素堆棧的第一個節點,那麼最後設置為 true ,並且,如果解析器最初是作為 HTML 片段解析算法(fragment case)的一部分創建的,那麼 node 設置為傳遞給該算法的上下文元素。
If node is a select element, run these substeps:
如果 node 是一個 select 元素,運行這些子步驟:
If last is true, jump to the step below labeled done.
如果 last 為 true,,跳到下面的步驟標記 done。
Let ancestor be node.
設 ancestor 為 node。
温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/31360.html