#pattern
* Parsing HTML documents
#ja
$1 HTML 文書の構文解析
#en
This section only applies to user agents, data mining tools, and
conformance checkers.
#ja
この節は利用者エージェント、データ・マイニング・ツール、
適合性検査器のみに適用されます。
#en
The rules for parsing XML documents (and
thus XHTML documents) into DOM trees are covered by
the XML and Namespaces in XML specifications, and are out of scope of this
specification. [XML] [XMLNS]
#ja
XML 文書 (や XHTML 文書)
を構文解析して DOM 木を得るための規則は XML や XML 名前空間の仕様書で扱われており、
この仕様書の適用範囲外です。 [XML] HTML documents, user agents must use the
parsing rules described in this section to generate the DOM trees.
Together, these rules define what is referred to as the HTML parser.
#ja
HTML 文書については、利用者エージェントは、 DOM
木を生成するためにこの節で説明する構文解析規則を使用しなければ[[MUST:なりません]]。
また、この規則はHTML 構文解析器と呼ばれるものを定義します。
#en
While the HTML form of HTML5 bears a close resemblance to SGML and XML,
it is a separate language with its own parsing rules.
#ja
HTML5 の HTML 形式は SGML や XML によく似ていますが、
独自の構文解析規則を持つ別の言語です。
#en
Some earlier versions of HTML (in particular from HTML2 to HTML4) were
based on SGML and used SGML parsing rules. However, few (if any) web
browsers ever implemented true SGML parsing for HTML documents; the only
user agents to strictly handle HTML as an SGML application have
historically been validators. The resulting confusion — with
validators claiming documents to have one representation while widely
deployed Web browsers interoperably implemented a different
representation — has wasted decades of productivity. This version
of HTML thus returns to a non-SGML basis.
#ja
以前のいくつかの版の HTML (特に HTML2 から HTML4 まで) は SGML
に基づき、 SGML の構文解析規則を用いていました。しかし、 HTML
文書用に真の SGML 構文解析を実装していたウェブ・ブラウザは (あったとしても)
皆無に近い数でした。 HTML を厳密に SGML 応用として扱う唯一の利用者エージェントは歴史的に妥当性検証器だけでした。
その結果、妥当性検査器は文書がある形式であることを要求し、
一方で広く実用されている Web ブラウザはそれとは異なる形式を相互運用可能な形で実装するという混乱が生じ、
生産性を大きく低下させています。
ですので、この版の HTML は非 SGML ベースに回帰します。
#en
Authors interested in using SGML tools in their authoring pipeline are
encouraged to use XML tools and the XML serialization of HTML5.
#ja
文書準備の過程で SGML ツールを使いたいと考える著者には、
XML ツールと HTML5 の XML 直列化を用いることをお勧めします。
#en
This specification defines the parsing rules for HTML documents, whether
they are syntactically correct or not. Certain points in the parsing
algorithm are said to be parse
errors. The error handling for parse errors is well-defined: user
agents must either act as described below when encountering such problems,
or must abort processing at the first error that they encounter for which
they do not wish to apply the rules described below.
#ja
この仕様書は、構文的に正しいか否かに関わらず HTML
文書を構文解析する規則を定義します。構文解析算法中のいくつかの箇所は構文解析誤りであるとしています。
構文解析誤りの処理は明確に定義します。利用者エージェントは、
そのような問題に遭遇したときに後述のように動作するか、または後述の規則を適用することを望まないような誤りにはじめて遭遇した箇所で処理を停止しなければ[[MUST:なりません]]。
#en
Conformance checkers must report at least one parse error condition to
the user if one or more parse error conditions exist in the document and
must not report parse error conditions if none exist in the document.
Conformance checkers may report more than one parse error condition if
more than one parse error conditions exist in the document. Conformance
checkers are not required to recover from parse errors.
#ja
適合性検査器は、文書中に1つ以上の構文解析誤り条件が存在する場合、利用者に最低1つの構文解析誤り条件を報告しなければ[[MUST:ならず]]、
文書に誤りが存在しない場合、構文解析誤り条件を報告しては[[MUST NOT:なりません]]。
適合性検査器は、文書中に複数の構文解析誤り条件が存在する場合、
複数の構文解析誤り条件を報告して[[MAY:構いません]]。
適合性検査器は構文解析誤りから回復することを[[REQUIRED:要求]]されません。
#en
Parse errors are only errors with the syntax of
HTML. In addition to checking for parse errors, conformance checkers will
also verify that the document obeys all the other conformance requirements
described in this specification.
#ja
構文解析誤りは、 HTML の構文の誤りに過ぎません。
適合性検査器は、構文解析誤りの検査に加え、
文書がこの仕様書で説明されている他の適合性要件に従っているかも検査することになります。
#pattern
* The scripting state
#ja
$1 スクリプティング状態
#en
The scripting flag is set to "enabled" if the
Document with which the parser is associated was with script when the parser was created, and
"disabled" otherwise.
#ja
スクリプティング旗は、構文解析器が関連付けられている
Document が構文解析器の作成の時点でスクリプト付きである場合には「有効」、
それ以外の場合には「無効」です。
#pattern
* Tokenization
#ja
$1 字句化
#en
Implementations must act as if they used the following state machine to
tokenise HTML. The state machine must start in the data state. Most states consume a single character,
which may have various side-effects, and either switches the state machine
to a new state to reconsume the same character, or switches it to
a new state (to consume the next character), or repeats the same state (to
consume the next character). Some states have more complicated behavior
and can consume several characters before switching to another state.
#ja
実装は、次の状態機械を HTML の字句化に用いているかのように作用しなければ[[MUST:なりません]]。
状態機械は、データ状態で開始しなければ[[MUST:なりません]]。
ほとんどの状態は1文字消費しますが、
この時様々な副作用を持っても[[MAY:構わない]]他、
状態機械が新しい状態に切り替えられて同じ文字を再消費するか、
(次の文字を消費するために) 新しい状態に切り替えられるか、
(次の文字を消費するために) 同じ状態を繰り返すかのいずれかとなります。
より複雑な動作を持っていて、他の状態に切り替える前に複数の文字を消費することがある状態もあります。
#en
The exact behavior of certain states depends on a content model flag that is set after certain tokens are
emitted. The flag has several states: PCDATA, RCDATA, CDATA, and PLAINTEXT. Initially it must be in the PCDATA state. In the
RCDATA and CDATA states, a further escape flag is
used to control the behavior of the tokeniser. It is either true or false,
and initially must be set to the false state. The insertion
mode and the stack of open elements also
affects tokenization.
#ja
特定の状態の正確な動作は、特定の字句が放出された後に設定される内容モデル旗に依存します。
この旗は状態 PCDATA, RCDATA, CDATA, PLAINTEXT を持ちます。はじめは PCDATA
状態でなければ[[MUST:なりません]]。 RCDATA 状態と CDATA 状態では、
更に逃避旗が字句化器の動作を制御するために用いられます。
これは真か偽かのいずれかであり、はじめは偽の状態に設定されなければ[[MUST:なりません]]。
挿入モードと開いているようそのスタックも字句化器に影響します。
#en
The output of the tokenization step is a series of zero or more of the
following tokens: DOCTYPE, start tag, end tag, comment, character,
end-of-file. DOCTYPE tokens have a name, a public identifier, a system
identifier, and a force-quirks flag. When a DOCTYPE token is
created, its name, public identifier, and system identifier must be marked
as missing (which is a distinct state from the empty string), and the
force-quirks flag must be set to off (its other state is
on). Start and end tag tokens have a tag name, a self-closing
flag, and a list of attributes, each of which has a name and a value.
When a start or end tag token is created, its self-closing flag
must be unset (its other state is that it be set), and its attributes list
must be empty. Comment and character tokens have data.
#ja
字句化期の出力は、 DOCTYPE、開始タグ、終了タグ、注釈、文字、ファイル末のいずれかの字句の零個以上の系列です。
DOCTYPE 字句は名前、公開識別子、システム識別子、奇癖強制旗を持ちます。
When a DOCTYPE token is
created, its name, public identifier, and system identifier must be marked
as missing (which is a distinct state from the empty string), and the
force-quirks flag must be set to off (its other state is
on). Start and end tag tokens have a tag name, a self-closing
flag, and a list of attributes, each of which has a name and a value.
When a start or end tag token is created, its self-closing flag
must be unset (its other state is that it be set), and its attributes list
must be empty. Comment and character tokens have data.
#pattern
* Parse state
#ja
$1 構文解析状態
#pattern
* The insertion mode
#ja
$1 挿入モード
#en
Initially the insertion mode is "initial". It can change to "before html", "before head", "in head", "in head
noscript", "after
head", "in
body", "in
table", "in
caption", "in column group", "in table body", "in row", "in cell", "in select", "in select in table", "in foreign content", "after body", "in frameset",
"after
frameset", "after after body", and "after after frameset" during the course of the
parsing, as described in the tree
construction stage. The insertion mode affects how tokens are
processed and whether CDATA blocks are supported.
#ja
はじめ、挿入モードは "initial" です。挿入モードは、
構文解析の過程で、木構築期で説明するように、
"before html", "before head", "in head", "in head
noscript", "after
head", "in
body", "in
table", "in
caption", "in column group", "in table body", "in row", "in cell", "in select", "in select in table", "in foreign content", "after body", "in frameset",
"after
frameset", "after after body", "after after frameset"
に変わることができます。挿入モードは、字句がどう処理されるか、 CDATA
ブロックに対応するかどうかに影響します。
#en
Seven of these modes, namely "in head", "in body", "in table", "in table body", "in row", "in cell", 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 that
insertion mode's section, but must leave the insertion
mode unchanged (unless the rules in that section themselves switch
the insertion mode).
#ja
挿入モードのうちの7つ、"in head", "in body", "in table", "in table body", "in row", "in cell", "in select" は特別で、他のモードが数箇所でこれらのモードに委ねています。
後述の算法が利用者エージェントは何かを「m 挿入モードの規則を用いて」
(m はこれらのモードのいずれか。) 行うと言っている時は、
利用者エージェントは、当該挿入モードの節で説明されている規則を用いなければ[[MUST:なりません]]が、
挿入モードは変更しないでおかなければ[[MUST:なりません]] (その節の規則自体が挿入モードを切り替える場合を除きます)。
#en
When the insertion mode is switched to "in foreign content", the
secondary insertion mode is also set. This
secondary mode is used within the rules for the "in foreign content" mode to
handle HTML (i.e. not foreign) content.
#ja
挿入モードが "in foreign content"
に切り替えられる時には、二次挿入モードも設定されます。
この二次モードは、 "in foreign content"
モードの規則の中で HTML (つまり、異言語でない) 内容を取り扱う際に使用します。
#en
When the steps below require the UA to reset the insertion
mode appropriately, it means the UA must follow these steps:
#ja
後述の段階が利用者エージェントに挿入モードを適切に再設定することを要求する場合、
利用者エージェントは次の段階に従わなければ[[MUST:ならない]]ことを意味しています。
#pattern
Let * be false.
#ja
$1 を偽とします。
#en
Let node be the last node in the stack of open elements.
#ja
node を開いている要素のスタックの最後の節点とします。
#en
If node is the first node in the stack of open
elements, then set last to true and set node to the context element. (fragment case)
#ja
node が開いている要素のスタックの最初の節点の場合、
last を真に設定し、 node を context 要素に設定します。
(素片の場合)
#pattern
If node is a * element, then
switch the insertion mode to "*" and abort these steps.
(fragment case)
#ja
node が $1 要素の場合、挿入モードを "$2" に切り替え、
これらの段階を停止します。
(素片の場合)
#pattern
If node is a * element, then
switch the insertion mode to "*" and abort these steps.
#ja
node が $1
要素の場合、挿入モードを "$2" に切り替え、
これらの段階を停止します。
#en
If node is a td or
th element and last is
false, then switch the insertion mode to "in cell" and abort these steps.
#ja
node が td 要素か
th 要素の場合で last
が偽の場合、挿入モードを "in cell" に切り替え、これらの段階を停止します。
#en
If node is an element from the MathML
namespace, then switch
the insertion mode to "in foreign content", let
the secondary insertion mode be "in body", and abort
these steps.
#ja
node が MathML
名前空間の要素の場合、挿入モードを "in foreign content"
に切り替え、二次挿入モードを "in body"
とし、これらの段階を停止します。
#en
If node is a head
element, then switch the insertion mode to "in body" ("in body"! not
"in head"!)
and abort these steps. (fragment case)
#ja
node が head
要素の場合、挿入モードを "in body" ("in body"! "in head"
ではなく!) に切り替え、これらの段階を停止します。
(素片の場合)
#en
If node is an html element, then: if the head element pointer is
null, switch the insertion mode to "before head", otherwise, switch
the insertion mode to "after head". In either case, abort these steps. (fragment case)
#ja
node が html 要素の場合: head 要素指示子が null
である場合には、挿入モードを "before head"
に切り替えます。そうでない場合には、挿入モードを "after head" に切り替えます。いずれの場合にも、
これらの段階を停止します。 (素片の場合)
#en
If last is true, then switch the insertion
mode to "in
body" and abort these steps. (fragment case)
#ja
last が真であれば、挿入モードを
"in
body" に切り替え、これらの段階を停止します。
(素片の場合)
#en
Let node now be the node before node in the stack of open elements.
#ja
新たな node を開いている要素のスタックで node の前にある節点とします。
#pattern
A sequence of bytes starting with: *
#ja
$1 で始まるバイト列
#en
Any other byte
#ja
その他のバイト
#en
Consume the next input character:
#ja
次入力文字を消費:
#en
A comment token
#ja
注釈字句
#en
A DOCTYPE token
#ja
DOCTYPE 字句
#pattern
A start tag whose tag name is "*"
#ja
タグ名が "$1" の開始タグ
#pattern
A start tag whose tag name is one of: *
#ja
タグ名が $1 のいずれかの開始タグ
#pattern
An end tag whose tag name is "*"
#ja
タグ名が "$1" の終了タグ
#pattern
An end tag whose tag name is one of: *
#ja
タグ名が $1 のいずれかの終了タグ
#en
Any other start tag
#ja
その他の開始タグ
#en
Any other end tag
#ja
その他の終了タグ
#en
Anything else
#ja
その他のもの
#en
Run the following algorithm:
#ja
次の算法を実行します:
#en
Otherwise:
#ja
それ以外の場合:
#pattern
Return to step *.
#ja
手順 $1 に戻ります。
#pattern
Act as if a start tag token with the tag name "*" had been seen,
then reprocess the current token.
#ja
タグ名が "$1" の開始タグ字句を見たかのように動作してから、
現在字句を再処理します。
#en
Parse error.
#ja
構文解析誤り。
#en
Parse error. Ignore the token.
#ja
構文解析誤り。字句を無視します。
#en
Take a deep breath, then act as described in the "any other end tag"
entry below.
#ja
深呼吸をして、後述の「その他の終了タグ」の項で説明されているように作用します。
#en
If the list of active formatting elements
contains an element whose tag name is "a" between the end of the list
and the last marker on the list (or the start of the list if there is no
marker on the list), then this is a parse error;
act as if an end tag with the tag name "a" had been seen, then remove
that element from the list of active formatting
elements and the stack of open elements if the
end tag didn't already remove it (it might not have if the element is
not in table
scope).
#ja
活性書式付け要素のリストがタグ名 "a"
の要素をリストの終わりとリスト中のリスト・マーカー (またはリスト中にマーカーがない場合はリストのはじめ)
の間に含まれている場合には、
これは構文解析誤りです。
タグ名 "a" の終了タグを見たかのように作用した後に、
その要素を活性書式付け要素のリストと開いている要素のスタック
(終了タグにより除去されていない場合。要素が表範囲中にない場合には除去されていないかもしれません。) から除去します。
#en
In the non-conforming stream
<a href="a">a<table><a href="b">b</table>x,
the first a element would be closed upon
seeing the second one, and the "x" character would be inside a link to
"b", not to "a". This is despite the fact that the outer a element is not in table scope (meaning that a
regular </a> end tag at the start of the table wouldn't
close the outer a element).
#ja
不適合ストリーム
<a href="a">a<table><a href="b">b</table>x
において、最初の a 要素は2つ目のを見たときに閉じられ、
「x」文字は「a」へのリンクではなく、「b」へのリンクの内側に入ります。
これは、外側の a 要素が表範囲中にないためです
(つまり、表の最初に普通の </a> 終了タグがあったとしても、
外側の a 要素を閉じないということになります)。
#en
Reconstruct the active formatting elements,
if any.
#ja
活性書式付け要素を再構築できれば、します。
#en
Insert an HTML element for the token. Add that
element to the list of active formatting
elements.
#ja
当該字句について HTML 要素を挿入します。
その要素を活性書式付け要素のリストに追加します。
#en
The behavior further depends on the character after the U+0023 NUMBER
SIGN:
#ja
動作は更に U+0023 NUMBER
SIGN の次の文字によって決まります。
#en
Consume the U+0023 NUMBER SIGN.
#ja
U+0023 NUMBER SIGN を消費します。
#en
Consume the X.
#ja
X を消費します。
#en
Follow the steps below, but using the range of characters U+0030
DIGIT ZERO through to U+0039 DIGIT NINE, U+0061 LATIN SMALL LETTER A
through to U+0066 LATIN SMALL LETTER F, and U+0041 LATIN CAPITAL
LETTER A, through to U+0046 LATIN CAPITAL LETTER F (in other words,
0-9, A-F, a-f).
#ja
次の段階に従いますが、範囲 U+0030
DIGIT ZERO ~ U+0039 DIGIT NINE、U+0061 LATIN SMALL LETTER A
~ U+0066 LATIN SMALL LETTER F、 U+0041 LATIN CAPITAL
LETTER A ~ U+0046 LATIN CAPITAL LETTER F (つまり
0-9、A-F、a-f) の文字を使います。