/[suikacvs]/markup/html/whatpm/Whatpm/mkentitylist.pl
Suika

Contents of /markup/html/whatpm/Whatpm/mkentitylist.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Sun Apr 13 06:44:27 2008 UTC (18 years, 5 months ago) by wakaba
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -1 lines
File MIME type: text/plain
++ whatpm/t/ChangeLog	13 Apr 2008 06:43:36 -0000
	* HTML-tokenizer.t, HTML-tree.t, Makefile: Support for html5lib
	new test files.

2008-04-13  Wakaba  <wakaba@suika.fam.cx>

++ whatpm/Whatpm/ChangeLog	13 Apr 2008 06:44:17 -0000
	* mkentitylist.pl: Support for new HTML5 entity table format (the
	definition for |AElig;| was missing).

2008-04-13  Wakaba  <wakaba@suika.fam.cx>

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3    
4     use lib qw[../];
5     my $EntitiesFileName = 'Entities.html';
6     my $Entity = {};
7    
8     require Whatpm::NanoDOM;
9     require Whatpm::HTML;
10     my $doc = Whatpm::NanoDOM::Document->new;
11     {
12     open my $file, '<:encoding(utf8)', $EntitiesFileName
13     or die "$0: $EntitiesFileName: $!";
14     local $/ = undef;
15     Whatpm::HTML->parse_string (scalar <$file> => $doc);
16     }
17    
18     my $table;
19     my @node = @{$doc->child_nodes};
20     while (@node) {
21     my $node = shift @node;
22     if ($node->node_type == 1 and
23     $node->namespace_uri eq q<http://www.w3.org/1999/xhtml> and
24     $node->manakai_local_name eq 'table') {
25     $table = $node;
26     last;
27     } else {
28     push @node, @{$node->child_nodes};
29     }
30     }
31     unless (defined $table) {
32     warn "$0: No <table> in $EntitiesFileName\n";
33     }
34    
35     my @row;
36     @node = @{$table->child_nodes};
37     while (@node) {
38     my $node = shift @node;
39     if ($node->node_type == 1) {
40     if ($node->namespace_uri eq q<http://www.w3.org/1999/xhtml>) {
41     if ($node->manakai_local_name eq 'tr') {
42     push @row, $node;
43     } elsif ({thead => 1, tbody => 1, tfoot => 1}
44     ->{$node->manakai_local_name}) {
45     unshift @node, @{$node->child_nodes};
46     }
47     }
48     }
49     }
50     shift @row; # heading rows
51    
52     my $n = sub { my $s = shift; $s =~ s/\s+/ /g; $s =~ s/^ //; $s =~ s/ $//; $s };
53     for my $tr (@row) {
54     my @td = grep {
55     $_->node_type == 1 and
56     $_->namespace_uri eq q<http://www.w3.org/1999/xhtml> and
57     $_->manakai_local_name eq 'td'
58     } @{$tr->child_nodes};
59     my $name = $n->($td[0]->text_content);
60     my $value = $n->($td[1]->text_content);
61     $Entity->{$name} = chr hex substr $value, 2; # U+HHHH
62     }
63    
64     use Data::Dumper;
65     $Data::Dumper::Sortkeys = 1;
66     $Data::Dumper::Useqq = 1;
67     my $value = Dumper $Entity;
68     $value =~ s/\$VAR1\b/\$Whatpm::HTML::EntityChar/;
69    
70     print $value;
71     print "1;\n";
72     print '__DATA__
73    
74     =head1 NAME
75    
76     mkentitylist.pl - Generate a named entity list for HTML parser
77    
78     _NamedEntityList.pm - A named entity list for HTML parser
79    
80     =head1 DESCRIPTION
81    
82     The C<_NamedEntityList.pm> file contains a list of named entities
83     used in HTML documents, both conforming and non-conforming.
84     It is referenced by C<ContentHTML.pm>. For more
85     information, see L<Whatpm::HTML>.
86    
87     The C<mkentitylist.pl> script is used to generate
88     the C<_NamedEntityList.pm> file from the table in the HTML5
89     specification.
90    
91     =head1 SEE ALSO
92    
93     L<Whatpm::HTML>.
94    
95     HTML 5 - Entities
96     <http://www.whatwg.org/specs/web-apps/current-work/#entities>
97    
98     =head1 LICENSE
99    
100     (C) Copyright 2004-2007 Apple Computer, Inc., Mozilla Foundation,
101     and Opera Software ASA.
102    
103     Copyright 2007 Wakaba <[email protected]>.
104    
105     You are granted a license to use, reproduce and create derivative works
106     of this document.
107    
108     =cut
109    
110     ';

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24