HTML5仕様書を拾い読みしていこうかと思い索引を見てみたら、全然作られてなくてがっかりしたのでありました。取り敢えず要素索引だけでもと思い、目次を元に自分で作成してみました。
ちなみに作成には以下のようなPerlスクリプトを使用しました。もし要素の抜けなどありましたら、何らかの方法でご報告頂ければ幸いです。
# version: 2009-09-11
use strict;
use warnings;
use XML::LibXML;
my $url = 'http://www.whatwg.org/specs/web-apps/current-work/multipage/';
my $parser = XML::LibXML->new;
my $doc = $parser->parse_html_file($url);
#my $doc = $parser->parse_html_file('html5.html');
# 目次から要素説明へのリンク(a要素)を取得
my $anchor_xpath = q{
//a[
(
starts-with(span, "4.")
or starts-with(span, "12.")
)
and contains( substring-after(., "The"), "element")
and code
]
};
my @anchors = $doc->findnodes($anchor_xpath);
# 出力用文書を読み込む
my $doc_out = $parser->parse_fh( \*DATA );
# 要素を出力用文書へ移入
@anchors = map { $doc_out->importNode($_) } @anchors;
# a要素ノードを変更
for my $anchor (@anchors) {
# 要素名と区切り文字以外を削除
for my $node ($anchor->childNodes) {
next if $node->nodeName eq 'code';
next if $node->textContent =~ /(?:,|and)/;
$anchor->removeChild($node);
}
# href属性に絶対URLを設定
my $href = $anchor->getAttribute('href');
$anchor->setAttribute('href', "$url$href");
}
# 要素名でソート
@anchors = map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [ $_, $_->textContent ] } @anchors;
# 出力用文書にアンカーを挿入
my ($ul) = $doc_out->getElementsByTagName('ul');
for my $anchor (@anchors) {
my $li = $doc_out->createElement('li');
$li->appendChild($anchor);
$ul->appendChild($li);
}
# 出力用文書に時刻を挿入
my ($p_mod) = $doc_out->getElementsByTagName('p');
$p_mod->appendChild( $doc_out->createTextNode(scalar localtime) );
# HTMLとして出力
print $doc_out->toStringHTML;
__DATA__
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<title>index of HTML5 elements</title>
</head>
<body>
<h1>index of HTML5 elements</h1>
<p>last-modified: </p>
<ul/>
<p>cf. <a href="http://www.akatsukinishisu.net/itazuragaki/html/index_of_html5_elements.html" lang="ja">HTML5仕様書の要素索引を作ってみる - 徒書</a></p>
</body>
</html>
XML::LibXMLを使ったHTML文書の操作については、XML::LibXMLでHTML文書を扱うの記事でも言及しています。
meta,
script,
video,
audio,
datagrid,
command,
menu,
applet,
marquee が抜けていたのを修正しました。