[インデックス 10736] ファイルの概要
このコミットは、Go言語のhtml
パッケージにおけるコメントの更新に関するものです。具体的には、HTML5仕様のセクション番号の変更に合わせて、コード内のコメントが参照するセクション番号を修正しています。
コミット
commit 66113ac8188026cb57ae043670d1004860831e2d
Author: Nigel Tao <nigeltao@golang.org>
Date: Tue Dec 13 14:20:26 2011 +1100
html: update comments to match latest spec.
R=dsymonds
CC=golang-dev
https://golang.org/cl/5482054
GitHub上でのコミットページへのリンク
https://github.com/golang/go/commit/66113ac8188026cb57ae043670d1004860831e2d
元コミット内容
html: update comments to match latest spec.
R=dsymonds
CC=golang-dev
https://golang.org/cl/5482054
変更の背景
このコミットの背景には、HTML5仕様の進化と、W3CおよびWHATWGという二つの主要な標準化団体間の関係性の変化があります。2011年頃、HTML5の仕様はまだ活発に開発されており、その構造やセクション番号は頻繁に変更されていました。
特に重要なのは、2011年にW3CとWHATWGがHTML仕様の策定に関して異なるアプローチを取り始めたことです。W3Cは「HTML5」として特定のバージョンをリリースすることを目指したのに対し、WHATWGは「HTML Living Standard」として継続的に更新される単一の標準を維持する方針を採りました。この方針の違いにより、WHATWGのLiving Standardではセクション番号や内容の構成が動的に変化するようになりました。
Go言語のhtml
パッケージは、HTML5のパースやレンダリングに関連する機能を提供しており、その実装はHTML5仕様に厳密に準拠する必要があります。そのため、仕様の変更、特にセクション番号の変更があった場合、コード内のコメントが参照する仕様の箇所も追従して更新する必要がありました。このコミットは、まさにその「最新の仕様にコメントを合わせる」という目的で行われました。具体的には、多くのコメントで参照されているセクション番号が「11.x.x」から「12.x.x」に変更されています。これは、HTML Living Standardの継続的な改訂の中で、仕様の章立てが再編成された結果と考えられます。
前提知識の解説
- HTML5仕様: World Wide Web Consortium (W3C) と Web Hypertext Application Technology Working Group (WHATWG) によって共同で開発された、HTMLの最新バージョン。ウェブページの構造と内容を定義する。
- WHATWG (Web Hypertext Application Technology Working Group): HTMLおよび関連技術の標準化を推進するコミュニティ。HTML Living Standardを管理している。
- W3C (World Wide Web Consortium): ウェブ技術の標準化を行う国際的な主要団体。
- HTMLパーサー: HTMLドキュメントを読み込み、その構造を解析して、プログラムが扱えるデータ構造(通常はDOMツリー)に変換するソフトウェアコンポーネント。HTMLは非常に寛容な文法を持つため、エラーのあるHTMLでも適切に解析できる堅牢なパーサーが必要とされる。
- スタック・オブ・オープン・エレメンツ (Stack of open elements): HTMLパーサーがHTMLドキュメントを解析する際に内部的に保持するデータ構造の一つ。現在開いている要素(開始タグが処理されたが、まだ対応する終了タグが処理されていない要素)のスタックであり、要素の親子関係やスコープを管理するために使用される。
- アクティブ・フォーマット要素 (Active formatting elements): HTMLパーサーが内部的に管理するもう一つのリスト。
<b>
,<i>
,<u>
などのフォーマット要素がネストされたり、不適切に閉じられたりした場合でも、正しいDOM構造を構築するために使用される。 - フォスターペアレンティング (Foster parenting): HTMLパーサーの特殊なルールの一つ。
<table>
要素の内部で誤って配置された要素(例:<table>
の直下に<div>
など)を、テーブル構造の外側に「養子縁組」させることで、ブラウザがエラーを発生させずにレンダリングを試みるメカニズム。
技術的詳細
このコミットは、Go言語のhtml
パッケージ内の複数のファイルにわたって、HTML5仕様への参照コメントを更新しています。変更のほとんどは、コメント内のセクション番号「11」を「12」に置き換えるという単純なものです。
具体的に影響を受けているファイルは以下の通りです。
src/pkg/html/const.go
: HTML要素の特性に関する定数を定義しているファイル。src/pkg/html/node.go
: HTMLノードの型定義に関するファイル。src/pkg/html/parse.go
: HTMLパーサーの主要なロジックが実装されているファイル。このファイルが最も多くの変更を含んでいます。src/pkg/html/render.go
: HTMLノードをレンダリングする機能に関するファイル。
parse.go
における変更は、パーサーの内部状態やアルゴリズムに関するコメントが中心です。例えば、「スタック・オブ・オープン・エレメンツ」や「アクティブ・フォーマット要素」、「フォスターペアレンティング」といったHTMLパーシングの重要な概念に関するコメントが更新されています。これらの概念はHTML5仕様の複雑なパースアルゴリズムの根幹をなすものであり、コメントが参照する仕様のセクション番号が正確であることは、コードの理解と保守において非常に重要です。
この変更は、コードの動作自体には影響を与えません。しかし、コードの可読性と、それが準拠する外部仕様との整合性を高める上で重要なメンテナンス作業です。開発者がHTML5仕様を参照しながらhtml
パッケージのコードを理解しようとした際に、古いセクション番号が記載されていると混乱を招く可能性があるため、このようなコメントの更新は不可欠です。
コアとなるコードの変更箇所
このコミットのコアとなる変更は、主にsrc/pkg/html/parse.go
ファイルに集中しています。以下に代表的な変更箇所を抜粋し、その前後の差分を示します。
src/pkg/html/const.go
--- a/src/pkg/html/const.go
+++ b/src/pkg/html/const.go
@@ -4,7 +4,7 @@
package html
-// Section 11.2.3.2 of the HTML5 specification says "The following elements
+// Section 12.2.3.2 of the HTML5 specification says "The following elements
// have varying levels of special parsing rules".
// http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#the-stack-of-open-elements
var isSpecialElement = map[string]bool{
src/pkg/html/node.go
--- a/src/pkg/html/node.go
+++ b/src/pkg/html/node.go
@@ -17,7 +17,7 @@ const (
scopeMarkerNode
)
-// Section 11.2.3.3 says "scope markers are inserted when entering applet
+// Section 12.2.3.3 says "scope markers are inserted when entering applet
// elements, buttons, object elements, marquees, table cells, and table
// captions, and are used to prevent formatting from 'leaking'".
var scopeMarker = Node{Type: scopeMarkerNode}
src/pkg/html/parse.go
--- a/src/pkg/html/parse.go
+++ b/src/pkg/html/parse.go
@@ -22,12 +22,12 @@ type parser struct {
hasSelfClosingToken bool
// doc is the document root element.
doc *Node
-// The stack of open elements (section 11.2.3.2) and active formatting
-// elements (section 11.2.3.3).
+// The stack of open elements (section 12.2.3.2) and active formatting
+// elements (section 12.2.3.3).
oe, afe nodeStack
-// Element pointers (section 11.2.3.4).
+// Element pointers (section 12.2.3.4).
head, form *Node
-// Other parsing state flags (section 11.2.3.5).
+// Other parsing state flags (section 12.2.3.5).
scripting, framesetOK bool
// im is the current insertion mode.
im insertionMode
@@ -35,12 +35,12 @@ type parser struct {
// or inTableText insertion mode.
originalIM insertionMode
// fosterParenting is whether new elements should be inserted according to
-// the foster parenting rules (section 11.2.5.3).
+// the foster parenting rules (section 12.2.5.3).
fosterParenting bool
// quirks is whether the parser is operating in "quirks mode."
quirks bool
// context is the context element when parsing an HTML fragment
-// (section 11.4).
+// (section 12.4).
context *Node
}
@@ -51,7 +51,7 @@ func (p *parser) top() *Node {
return p.doc
}
-// stopTags for use in popUntil. These come from section 11.2.3.2.
+// stopTags for use in popUntil. These come from section 12.2.3.2.
var (
defaultScopeStopTags = []string{"applet", "caption", "html", "table", "td", "th", "marquee", "object"}
listItemScopeStopTags = []string{"applet", "caption", "html", "table", "td", "th", "marquee", "object", "ol", "ul"}
@@ -130,14 +130,14 @@ func (p *parser) addChild(n *Node) {
}
// fosterParent adds a child node according to the foster parenting rules.
-// Section 11.2.5.3, "foster parenting".
+// Section 12.2.5.3, "foster parenting".
func (p *parser) fosterParent(n *Node) {
p.fosterParenting = false
var table, parent *Node
@@ -199,14 +199,14 @@ func (p *parser) addElement(tag string, attr []Attribute) {
})\n
}\n
-// Section 11.2.3.3.\n
+// Section 12.2.3.3.\n
func (p *parser) addFormattingElement(tag string, attr []Attribute) {
p.addElement(tag, attr)
p.afe = append(p.afe, p.top())
// TODO.
}\n
-// Section 11.2.3.3.\n
+// Section 12.2.3.3.\n
func (p *parser) clearActiveFormattingElements() {
for {
n := p.afe.pop()
@@ -216,7 +216,7 @@ func (p *parser) clearActiveFormattingElements() {
}
}\n
-// Section 11.2.3.3.\n
+// Section 12.2.3.3.\n
func (p *parser) reconstructActiveFormattingElements() {
n := p.afe.top()
if n == nil {
@@ -266,12 +266,12 @@ func (p *parser) read() error {
return nil
}\n
-// Section 11.2.4.\n
+// Section 12.2.4.\n
func (p *parser) acknowledgeSelfClosingTag() {
p.hasSelfClosingToken = false
}\n
-// An insertion mode (section 11.2.3.1) is the state transition function from\n
+// An insertion mode (section 12.2.3.1) is the state transition function from\n
// a particular state in the HTML5 parser's state machine. It updates the\n
// parser's fields depending on parser.tok (where ErrorToken means EOF).\n
// It returns whether the token was consumed.\n
@@ -279,7 +279,7 @@ type insertionMode func(*parser) bool
// setOriginalIM sets the insertion mode to return to after completing a text or\n
// inTableText insertion mode.\n
-// Section 11.2.3.1, "using the rules for".\n
+// Section 12.2.3.1, "using the rules for".\n
func (p *parser) setOriginalIM() {
if p.originalIM != nil {
panic("html: bad parser state: originalIM was set twice")
@@ -287,7 +287,7 @@ func (p *parser) setOriginalIM() {
p.originalIM = p.im
}\n
-// Section 11.2.3.1, "reset the insertion mode".\n
+// Section 12.2.3.1, "reset the insertion mode".\n
func (p *parser) resetInsertionMode() {
for i := len(p.oe) - 1; i >= 0; i-- {
n := p.oe[i]
@@ -331,7 +331,7 @@ func (p *parser) resetInsertionMode() {
const whitespace = " \t\r\n\f"\n
-// Section 11.2.5.4.1.\n
+// Section 12.2.5.4.1.\n
func initialIM(p *parser) bool {
switch p.tok.Type {
case TextToken:
@@ -358,7 +358,7 @@ func initialIM(p *parser) bool {
return false
}\n
-// Section 11.2.5.4.2.\n
+// Section 12.2.5.4.2.\n
func beforeHTMLIM(p *parser) bool {
switch p.tok.Type {
case TextToken:
@@ -394,7 +394,7 @@ func beforeHTMLIM(p *parser) bool {
return false
}\n
-// Section 11.2.5.4.3.\n
+// Section 12.2.5.4.3.\n
func beforeHeadIM(p *parser) bool {
var (
add bool
@@ -443,7 +443,7 @@ func beforeHeadIM(p *parser) bool {
return !implied
}\n
-// Section 11.2.5.4.4.\n
+// Section 12.2.5.4.4.\n
func inHeadIM(p *parser) bool {
var (
pop bool
@@ -510,7 +510,7 @@ func inHeadIM(p *parser) bool {
return true
}\n
-// Section 11.2.5.4.6.\n
+// Section 12.2.5.4.6.\n
func afterHeadIM(p *parser) bool {
var (
add bool
@@ -598,7 +598,7 @@ func copyAttributes(dst *Node, src Token) {
}
}\n
-// Section 11.2.5.4.7.\n
+// Section 12.2.5.4.7.\n
func inBodyIM(p *parser) bool {
switch p.tok.Type {
case TextToken:
@@ -989,7 +989,7 @@ func (p *parser) inBodyEndTagOther(tag string) {
}
}\n
-// Section 11.2.5.4.8.\n
+// Section 12.2.5.4.8.\n
func textIM(p *parser) bool {
switch p.tok.Type {
case ErrorToken:
@@ -1005,7 +1005,7 @@ func textIM(p *parser) bool {
return p.tok.Type == EndTagToken
}\n
-// Section 11.2.5.4.9.\n
+// Section 12.2.5.4.9.\n
func inTableIM(p *parser) bool {
switch p.tok.Type {
case ErrorToken:
@@ -1094,7 +1094,7 @@ func (p *parser) clearStackToContext(stopTags []string) {
}
}\n
-// Section 11.2.5.4.11.\n
+// Section 12.2.5.4.11.\n
func inCaptionIM(p *parser) bool {
switch p.tok.Type {
case StartTagToken:
@@ -1134,7 +1134,7 @@ func inCaptionIM(p *parser) bool {
return inBodyIM(p)
}\n
-// Section 11.2.5.4.12.\n
+// Section 12.2.5.4.12.\n
func inColumnGroupIM(p *parser) bool {
switch p.tok.Type {
case CommentToken:
@@ -1176,7 +1176,7 @@ func inColumnGroupIM(p *parser) bool {
return false
}\n
-// Section 11.2.5.4.13.\n
+// Section 12.2.5.4.13.\n
func inTableBodyIM(p *parser) bool {
var (
add bool
@@ -1232,7 +1232,7 @@ func inTableBodyIM(p *parser) bool {
return inTableIM(p)
}\n
-// Section 11.2.5.4.14.\n
+// Section 12.2.5.4.14.\n
func inRowIM(p *parser) bool {
switch p.tok.Type {
case ErrorToken:
@@ -1291,7 +1291,7 @@ func inRowIM(p *parser) bool {
return inTableIM(p)
}\n
-// Section 11.2.5.4.15.\n
+// Section 12.2.5.4.15.\n
func inCellIM(p *parser) bool {
var (
closeTheCellAndReprocess bool
@@ -1336,7 +1336,7 @@ func inCellIM(p *parser) bool {
return inBodyIM(p)
}\n
-// Section 11.2.5.4.16.\n
+// Section 12.2.5.4.16.\n
func inSelectIM(p *parser) bool {
endSelect := false
switch p.tok.Type {
@@ -1413,7 +1413,7 @@ func inSelectIM(p *parser) bool {
return true
}\n
-// Section 11.2.5.4.18.\n
+// Section 12.2.5.4.18.\n
func afterBodyIM(p *parser) bool {
switch p.tok.Type {
case ErrorToken:
@@ -1443,7 +1443,7 @@ func afterBodyIM(p *parser) bool {
return false
}\n
-// Section 11.2.5.4.19.\n
+// Section 12.2.5.4.19.\n
func inFramesetIM(p *parser) bool {
switch p.tok.Type {
case CommentToken:
@@ -1493,7 +1493,7 @@ func inFramesetIM(p *parser) bool {
return true
}\n
-// Section 11.2.5.4.20.\n
+// Section 12.2.5.4.20.\n
func afterFramesetIM(p *parser) bool {
switch p.tok.Type {
case CommentToken:
@@ -1532,7 +1532,7 @@ func afterFramesetIM(p *parser) bool {
return true
}\n
-// Section 11.2.5.4.21.\n
+// Section 12.2.5.4.21.\n
func afterAfterBodyIM(p *parser) bool {
switch p.tok.Type {
case ErrorToken:
@@ -1555,7 +1555,7 @@ func afterAfterBodyIM(p *parser) bool {
return false
}\n
-// Section 11.2.5.4.22.\n
+// Section 12.2.5.4.22.\n
func afterAfterFramesetIM(p *parser) bool {
switch p.tok.Type {
case CommentToken:
@@ -1576,8 +1576,6 @@ func afterAfterFramesetIM(p *parser) bool {
return true
}\n
-// TODO: fix up the other IM's section numbers to match the latest spec.\n
-\n
// Section 12.2.5.5.\n
func inForeignContentIM(p *parser) bool {
switch p.tok.Type {
src/pkg/html/render.go
--- a/src/pkg/html/render.go
+++ b/src/pkg/html/render.go
@@ -247,7 +247,7 @@ func writeQuoted(w writer, s string) error {
return nil
}\n
-// Section 13.1.2, "Elements", gives this list of void elements. Void elements\n
+// Section 12.1.2, "Elements", gives this list of void elements. Void elements\n
// are those that can't have any contents.\n
var voidElements = map[string]bool{
"area": true,
コアとなるコードの解説
上記の変更箇所は、Go言語のhtml
パッケージがHTML5仕様の特定のセクションを参照しているコメントを更新していることを示しています。
src/pkg/html/const.go
:isSpecialElement
マップに関するコメントが更新されています。これは、HTML5仕様の「特殊なパースルールを持つ要素」に関するセクションを参照しています。src/pkg/html/node.go
:scopeMarker
に関するコメントが更新されています。これは、HTMLパーサーが特定の要素(applet
,button
,object
など)の内部で「スコープマーカー」を挿入するルールに関するセクションを参照しています。スコープマーカーは、フォーマットが予期せず「漏れ出す」のを防ぐために使用されます。src/pkg/html/parse.go
: このファイルはHTMLパーサーの核心部分であり、最も多くの変更が含まれています。parser
構造体のフィールドに関するコメント(oe
,afe
,head
,form
,scripting
,framesetOK
,fosterParenting
,context
)が更新されています。これらはそれぞれ、「スタック・オブ・オープン・エレメンツ」、「アクティブ・フォーマット要素」、「要素ポインタ」、「その他のパース状態フラグ」、「フォスターペアレンティング」、「コンテキスト要素」といったHTMLパーシングの重要な概念に対応しており、それらがHTML5仕様のどのセクションで定義されているかを示しています。stopTags
変数に関するコメントも更新されています。これは、パーサーが要素スタックをポップする際に使用する停止タグのリストであり、HTML5仕様の特定のセクションで定義されています。fosterParent
関数、addFormattingElement
関数、clearActiveFormattingElements
関数、reconstructActiveFormattingElements
関数、acknowledgeSelfClosingTag
関数、insertionMode
型、setOriginalIM
関数、resetInsertionMode
関数、そして様々な挿入モード(initialIM
,beforeHTMLIM
,beforeHeadIM
,inHeadIM
,afterHeadIM
,inBodyIM
,textIM
,inTableIM
,inCaptionIM
,inColumnGroupIM
,inTableBodyIM
,inRowIM
,inCellIM
,inSelectIM
,afterBodyIM
,inFramesetIM
,afterFramesetIM
,afterAfterBodyIM
,afterAfterFramesetIM
)に関するコメントが更新されています。これらはすべて、HTML5パーシングアルゴリズムの異なる段階やルールに対応しており、それぞれのコメントが参照する仕様のセクション番号が修正されています。- 特に注目すべきは、
parse.go
の末尾にあった// TODO: fix up the other IM's section numbers to match the latest spec.
というコメントが削除されている点です。これは、このコミットによって、残りの挿入モードのセクション番号も最新の仕様に合わせる作業が完了したことを示唆しています。
src/pkg/html/render.go
:voidElements
マップに関するコメントが更新されています。これは、HTML5仕様の「要素」セクションで定義されている「void要素」(内容を持つことができない要素)のリストを参照しています。
これらの変更は、コードの機能的な振る舞いには影響を与えませんが、Go言語のhtml
パッケージがHTML5仕様のどの部分に準拠しているかを明確にする上で非常に重要です。これにより、開発者はコードと仕様を照らし合わせやすくなり、将来的なメンテナンスや機能追加の際に役立ちます。
関連リンク
- Go言語の
html
パッケージのドキュメント: https://pkg.go.dev/golang.org/x/net/html (コミット当時のパッケージパスはsrc/pkg/html
ですが、現在はgolang.org/x/net/html
に移動しています) - HTML Living Standard: https://html.spec.whatwg.org/multipage/
参考にした情報源リンク
- HTML5 specification section numbers change 2011 WHATWGに関するWeb検索結果
- WHATWGとW3CのHTML標準化に関する歴史的経緯に関する情報源 (Web検索結果に含まれるWikipediaやWHATWGの公式ブログなど)