/[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.3 - (hide annotations) (download)
Fri Oct 17 07:14:29 2008 UTC (16 years ago) by wakaba
Branch: MAIN
Changes since 1.2: +58 -3 lines
++ whatpm/t/ChangeLog	17 Oct 2008 07:14:01 -0000
2008-10-17  Wakaba  <wakaba@suika.fam.cx>

	* XML-Parser.t: "xml/attlists-1.dat" added.

++ whatpm/t/xml/ChangeLog	17 Oct 2008 07:14:24 -0000
2008-10-17  Wakaba  <wakaba@suika.fam.cx>

	* attlists-1.dat: New test data file.

	* doctypes-2.dat: New tests added.

++ whatpm/Whatpm/ChangeLog	17 Oct 2008 07:11:25 -0000
2008-10-17  Wakaba  <wakaba@suika.fam.cx>

	* NanoDOM.pm (node_name): New attribute.
	(ELEMENT_TYPE_DEFINITION_NODE, ATTRIBUTE_DEFINITION_NODE): New
	constants.
	(create_element_type_definition_node, create_attribute_definition,
	create_notation, create_general_entity,
	get_element_type_definition_node,
	set_element_type_definition_node, get_general_entity_node,
	set_general_entity_node, get_notation_node, set_notation_node,
	get_attribute_definition_node, set_attribute_definition_node): New
	methods.
	(element_types, entities, notations, attribute_definitions): New
	attributes.
	(DocumentType): Support for child nodes, entities, notations, and
	element types.
	(Entity, Notation, ElementTypeDefinition, AttributeDefinition):
	New classes.

	* Dumper.pm: Support for general entities, notations, element type
	definitions, and attribute definitions.

++ whatpm/Whatpm/HTML/ChangeLog	17 Oct 2008 07:12:26 -0000
2008-10-17  Wakaba  <wakaba@suika.fam.cx>

	* Tokenizer.pm.src: New token types AtTLIST_TOKEN, ELEMENT_TOKEN,
	GENERAL_ENTITY_TOKEN, PARAMETER_ENTITY_TOKEN, and NOTATION_TOKEN
	are added.  New intertion modes for markup declarations are added.

++ whatpm/Whatpm/XML/ChangeLog	17 Oct 2008 07:13:47 -0000
2008-10-17  Wakaba  <wakaba@suika.fam.cx>

	* Parser.pm.src (_tree_in_subset): Support for ELEMENT_TOKEN,
	ATTLIST_TOKEN, GENERAL_ENTITY_TOKEN, PARAMETER_ENTITY_TOKEN, and
	NOTATION_TOKEN.

1 wakaba 1.1 package Whatpm::HTML::Dumper;
2     use strict;
3 wakaba 1.3 our $VERSION=do{my @r=(q$Revision: 1.2 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
4 wakaba 1.1
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 wakaba 1.2 q<http://www.w3.org/2000/xmlns/> => 'xmlns',
21 wakaba 1.1 };
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 wakaba 1.3 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 wakaba 1.1 } elsif ($nt == $child->[0]->PROCESSING_INSTRUCTION_NODE) {
86     $r .= $child->[1] . '<?' . $child->[0]->target . ' ';
87     $r .= $child->[0]->data . "?>\x0A";
88 wakaba 1.3 } elsif ($nt == $child->[0]->ENTITY_NODE) {
89     $r .= $child->[1] . '<!ENTITY ' . $child->[0]->node_name . ' "';
90     $r .= $child->[0]->public_id if defined $child->[0]->public_id;
91     $r .= '" "';
92     $r .= $child->[0]->system_id if defined $child->[0]->system_id;
93     $r .= '" ';
94     $r .= $child->[0]->notation_name if defined $child->[0]->notation_name;
95     $r .= ">\x0A";
96     unshift @node,
97     map { [$_, $child->[1] . ' '] } @{$child->[0]->child_nodes};
98     } elsif ($nt == $child->[0]->NOTATION_NODE) {
99     $r .= $child->[1] . '<!NOTATION ' . $child->[0]->node_name . ' "';
100     $r .= $child->[0]->public_id if defined $child->[0]->public_id;
101     $r .= '" "';
102     $r .= $child->[0]->system_id if defined $child->[0]->system_id;
103     $r .= qq[">\x0A];
104     } elsif ($nt == $child->[0]->ELEMENT_TYPE_DEFINITION_NODE) {
105     $r .= $child->[1] . '<!ELEMENT ' . $child->[0]->node_name . ' ';
106     $r .= $child->[0]->content_model_text;
107     $r .= ">\x0A";
108     unshift @node,
109     map { [$_, $child->[1] . ' '] }
110     sort { $a->node_name cmp $b->node_name }
111     values %{$child->[0]->attribute_definitions};
112     } elsif ($nt == $child->[0]->ATTRIBUTE_DEFINITION_NODE) {
113     $r .= $child->[1] . $child->[0]->node_name . ' ';
114     $r .= [
115     0, 'CDATA', 'ID', 'IDREF', 'IDREFS', 'ENTITY', 'ENTITIES',
116     'NMTOKEN', 'NMTOKENS', 'NOTATION', 'ENUMERATION', 11,
117     ]->[$child->[0]->declared_type] || $child->[0]->declared_type;
118     if ($child->[0]->declared_type == 9 or
119     $child->[0]->declared_type == 10) {
120     $r .= '(' . join ('|', @{$child->[0]->allowed_tokens}) . ')';
121     }
122     $r .= ' ';
123     $r .= [
124     0, 'FIXED', 'REQUIRED', 'IMPLIED', 'EXPLICIT',
125     ]->[$child->[0]->default_type] || $child->[0]->default_type;
126     if ($child->[0]->default_type == 1 or
127     $child->[0]->default_type == 4) {
128     $r .= ' "' . $child->[0]->text_content . '"';
129     }
130     $r .= "\x0A";
131 wakaba 1.1 } else {
132     $r .= $child->[1] . $child->[0]->node_type . "\x0A"; # error
133     }
134     }
135    
136     return $r;
137     } # dumptree
138    
139     ## NOTE: Based on <http://wiki.whatwg.org/wiki/Parser_tests>.
140     ## TDOO: Document
141    
142     1;
143 wakaba 1.3 ## $Date: 2008/10/14 10:36:33 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24