/[suikacvs]/markup/html/whatpm/Whatpm/HTML/Dumper.pm
Suika

Contents of /markup/html/whatpm/Whatpm/HTML/Dumper.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download)
Sun Oct 19 06:14:57 2008 UTC (16 years ago) by wakaba
Branch: MAIN
Changes since 1.4: +4 -2 lines
++ whatpm/t/ChangeLog	19 Oct 2008 06:14:42 -0000
2008-10-19  Wakaba  <wakaba@suika.fam.cx>

	* XML-Parser.t: "xml/entities-1.dat" and "xml/entities-2.dat"
	added.  Support for the "#entities" directive.

++ whatpm/t/xml/ChangeLog	19 Oct 2008 06:11:59 -0000
	* entities-1.dat, entities-2.dat: New test data files.

2008-10-19  Wakaba  <wakaba@suika.fam.cx>

++ whatpm/Whatpm/ChangeLog	19 Oct 2008 06:12:27 -0000
2008-10-19  Wakaba  <wakaba@suika.fam.cx>

	* NanoDOM.pm (notation_name): New attribute.

	* NanoDOM.pm (public_id, system_id): New attributes.a
++ whatpm/Whatpm/HTML/ChangeLog	19 Oct 2008 06:13:03 -0000
	* Dumper.pm: Dump text content of Entity nodes.

	* Tokenizer.pm.src: Support for <!ENTITY ... NDATA>.

2008-10-19  Wakaba  <wakaba@suika.fam.cx>

++ whatpm/Whatpm/XML/ChangeLog	19 Oct 2008 06:14:05 -0000
2008-10-19  Wakaba  <wakaba@suika.fam.cx>

	* Parser.pm.src (_tree_in_subset): General and parameter entities
	implemented.

1 package Whatpm::HTML::Dumper;
2 use strict;
3 our $VERSION=do{my @r=(q$Revision: 1.4 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
4
5 require Exporter;
6 push our @ISA, 'Exporter';
7
8 our @EXPORT = qw(dumptree);
9
10 sub dumptree ($) {
11 my $node = shift;
12 my $r = '';
13
14 my $ns_id = {
15 q<http://www.w3.org/1999/xhtml> => 'html',
16 q<http://www.w3.org/2000/svg> => 'svg',
17 q<http://www.w3.org/1998/Math/MathML> => 'math',
18 q<http://www.w3.org/1999/xlink> => 'xlink',
19 q<http://www.w3.org/XML/1998/namespace> => 'xml',
20 q<http://www.w3.org/2000/xmlns/> => 'xmlns',
21 };
22
23 my @node = map { [$_, ''] } @{$node->child_nodes};
24 while (@node) {
25 my $child = shift @node;
26 my $nt = $child->[0]->node_type;
27 if ($nt == $child->[0]->ELEMENT_NODE) {
28 my $ns = $child->[0]->namespace_uri;
29 unless (defined $ns) {
30 $ns = '{} ';
31 } elsif ($ns eq q<http://www.w3.org/1999/xhtml>) {
32 $ns = '';
33 } elsif ($ns_id->{$ns}) {
34 $ns = $ns_id->{$ns} . ' ';
35 } else {
36 $ns = '{' . $ns . '} ';
37 }
38 $r .= $child->[1] . '<' . $ns . $child->[0]->manakai_local_name . ">\x0A";
39
40 for my $attr (sort {$a->[0] cmp $b->[0]} map { [do {
41 my $ns = $_->namespace_uri;
42 unless (defined $ns) {
43 $ns = '';
44 } elsif ($ns_id->{$ns}) {
45 $ns = $ns_id->{$ns} . ' ';
46 } else {
47 $ns = '{' . $ns . '} ';
48 }
49 $ns . $_->manakai_local_name;
50 }, $_->value] }
51 @{$child->[0]->attributes}) {
52 $r .= $child->[1] . ' ' . $attr->[0] . '="'; ## ISSUE: case?
53 $r .= $attr->[1] . '"' . "\x0A";
54 }
55
56 unshift @node,
57 map { [$_, $child->[1] . ' '] } @{$child->[0]->child_nodes};
58 } elsif ($nt == $child->[0]->TEXT_NODE) {
59 $r .= $child->[1] . '"' . $child->[0]->data . '"' . "\x0A";
60 } elsif ($nt == $child->[0]->COMMENT_NODE) {
61 $r .= $child->[1] . '<!-- ' . $child->[0]->data . " -->\x0A";
62 } elsif ($nt == $child->[0]->DOCUMENT_TYPE_NODE) {
63 $r .= $child->[1] . '<!DOCTYPE ' . $child->[0]->name;
64 my $pubid = $child->[0]->public_id;
65 my $sysid = $child->[0]->system_id;
66 if (length $pubid or length $sysid) {
67 $r .= ' "' . $pubid . '"';
68 $r .= ' "' . $sysid . '"';
69 }
70 $r .= ">\x0A";
71 unshift @node,
72 map { [$_, $child->[1] . ' '] }
73 sort { $a->node_name cmp $b->node_name }
74 values %{$child->[0]->element_types};
75 unshift @node,
76 map { [$_, $child->[1] . ' '] }
77 sort { $a->node_name cmp $b->node_name }
78 values %{$child->[0]->entities};
79 unshift @node,
80 map { [$_, $child->[1] . ' '] }
81 sort { $a->node_name cmp $b->node_name }
82 values %{$child->[0]->notations};
83 unshift @node,
84 map { [$_, $child->[1] . ' '] } @{$child->[0]->child_nodes};
85 } elsif ($nt == $child->[0]->PROCESSING_INSTRUCTION_NODE) {
86 $r .= $child->[1] . '<?' . $child->[0]->target . ' ';
87 $r .= $child->[0]->data . "?>\x0A";
88 } elsif ($nt == $child->[0]->ENTITY_NODE) {
89 $r .= $child->[1] . '<!ENTITY ' . $child->[0]->node_name . ' "';
90 $r .= $child->[0]->text_content;
91 $r .= '" "';
92 $r .= $child->[0]->public_id if defined $child->[0]->public_id;
93 $r .= '" "';
94 $r .= $child->[0]->system_id if defined $child->[0]->system_id;
95 $r .= '" ';
96 $r .= $child->[0]->notation_name if defined $child->[0]->notation_name;
97 $r .= ">\x0A";
98 unshift @node,
99 map { [$_, $child->[1] . ' '] } @{$child->[0]->child_nodes};
100 } elsif ($nt == $child->[0]->NOTATION_NODE) {
101 $r .= $child->[1] . '<!NOTATION ' . $child->[0]->node_name . ' "';
102 $r .= $child->[0]->public_id if defined $child->[0]->public_id;
103 $r .= '" "';
104 $r .= $child->[0]->system_id if defined $child->[0]->system_id;
105 $r .= qq[">\x0A];
106 } elsif ($nt == $child->[0]->ELEMENT_TYPE_DEFINITION_NODE) {
107 $r .= $child->[1] . '<!ELEMENT ' . $child->[0]->node_name . ' ';
108 $r .= $child->[0]->content_model_text;
109 $r .= ">\x0A";
110 unshift @node,
111 map { [$_, $child->[1] . ' '] }
112 sort { $a->node_name cmp $b->node_name }
113 values %{$child->[0]->attribute_definitions};
114 } elsif ($nt == $child->[0]->ATTRIBUTE_DEFINITION_NODE) {
115 $r .= $child->[1] . $child->[0]->node_name . ' ';
116 $r .= [
117 0, 'CDATA', 'ID', 'IDREF', 'IDREFS', 'ENTITY', 'ENTITIES',
118 'NMTOKEN', 'NMTOKENS', 'NOTATION', 'ENUMERATION', 11,
119 ]->[$child->[0]->declared_type] || $child->[0]->declared_type;
120 $r .= ' (' . join ('|', @{$child->[0]->allowed_tokens}) . ') ';
121 $r .= [
122 0, 'FIXED', 'REQUIRED', 'IMPLIED', 'EXPLICIT',
123 ]->[$child->[0]->default_type] || $child->[0]->default_type;
124 $r .= ' "' . $child->[0]->text_content . '"';
125 $r .= "\x0A";
126 } else {
127 $r .= $child->[1] . $child->[0]->node_type . "\x0A"; # error
128 }
129 }
130
131 return $r;
132 } # dumptree
133
134 ## NOTE: Based on <http://wiki.whatwg.org/wiki/Parser_tests>.
135 ## TDOO: Document
136
137 1;
138 ## $Date: 2008/10/18 08:05:29 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24