/[suikacvs]/markup/html/whatpm/Whatpm/ContentChecker.pm
Suika

Contents of /markup/html/whatpm/Whatpm/ContentChecker.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.56 - (hide annotations) (download)
Sun Feb 10 04:09:57 2008 UTC (16 years, 8 months ago) by wakaba
Branch: MAIN
Changes since 1.55: +14 -169 lines
++ whatpm/Whatpm/ChangeLog	10 Feb 2008 04:09:00 -0000
2008-02-10  Wakaba  <wakaba@suika.fam.cx>

	* ContentChecker.pm (check_document, check_element): Support
	for second argument ($onsubdoc).
	(_get_css_parser): Removed (now it is part of WDCC).

++ whatpm/Whatpm/ContentChecker/ChangeLog	10 Feb 2008 04:09:52 -0000
2008-02-10  Wakaba  <wakaba@suika.fam.cx>

	* HTML.pm (<style>): CSS validation code removed; instead,
	it does invoke subdoc callback to ask to the callee to validate
	the style sheet separately.

1 wakaba 1.1 package Whatpm::ContentChecker;
2     use strict;
3 wakaba 1.56 our $VERSION=do{my @r=(q$Revision: 1.55 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
4 wakaba 1.1
5 wakaba 1.18 require Whatpm::URIChecker;
6    
7 wakaba 1.13 ## ISSUE: How XML and XML Namespaces conformance can (or cannot)
8     ## be applied to an in-memory representation (i.e. DOM)?
9    
10 wakaba 1.50 ## TODO: Conformance of an HTML document with non-html root element.
11    
12 wakaba 1.42 my $HTML_NS = q<http://www.w3.org/1999/xhtml>;
13 wakaba 1.9 my $XML_NS = q<http://www.w3.org/XML/1998/namespace>;
14     my $XMLNS_NS = q<http://www.w3.org/2000/xmlns/>;
15    
16 wakaba 1.42 my $Namespace = {
17 wakaba 1.43 q<http://www.w3.org/2005/Atom> => {module => 'Whatpm::ContentChecker::Atom'},
18 wakaba 1.42 $HTML_NS => {module => 'Whatpm::ContentChecker::HTML'},
19     $XML_NS => {loaded => 1},
20     $XMLNS_NS => {loaded => 1},
21     };
22    
23     our $AttrChecker = {
24 wakaba 1.9 $XML_NS => {
25 wakaba 1.13 space => sub {
26     my ($self, $attr) = @_;
27     my $value = $attr->value;
28     if ($value eq 'default' or $value eq 'preserve') {
29     #
30     } else {
31     ## NOTE: An XML "error"
32 wakaba 1.33 $self->{onerror}->(node => $attr, level => 'error',
33     type => 'invalid attribute value');
34 wakaba 1.13 }
35     },
36     lang => sub {
37 wakaba 1.35 my ($self, $attr) = @_;
38 wakaba 1.47 my $value = $attr->value;
39     if ($value eq '') {
40     #
41     } else {
42     require Whatpm::LangTag;
43     Whatpm::LangTag->check_rfc3066_language_tag ($value, sub {
44     my %opt = @_;
45     my $type = 'LangTag:'.$opt{type};
46     $type .= ':' . $opt{subtag} if defined $opt{subtag};
47     $self->{onerror}->(node => $attr, type => $type,
48     value => $opt{value}, level => $opt{level});
49     });
50     }
51    
52 wakaba 1.13 ## NOTE: "The values of the attribute are language identifiers
53     ## as defined by [IETF RFC 3066], Tags for the Identification
54     ## of Languages, or its successor; in addition, the empty string
55     ## may be specified." ("may" in lower case)
56 wakaba 1.47 ## NOTE: Is an RFC 3066-valid (but RFC 4647-invalid) language tag
57     ## allowed today?
58    
59     ## TODO: test data
60    
61 wakaba 1.35 if ($attr->owner_document->manakai_is_html) { # MUST NOT
62 wakaba 1.36 $self->{onerror}->(node => $attr, type => 'in HTML:xml:lang');
63 wakaba 1.35 ## TODO: Test data...
64     }
65 wakaba 1.13 },
66     base => sub {
67     my ($self, $attr) = @_;
68     my $value = $attr->value;
69     if ($value =~ /[^\x{0000}-\x{10FFFF}]/) { ## ISSUE: Should we disallow noncharacters?
70     $self->{onerror}->(node => $attr,
71 wakaba 1.33 type => 'invalid attribute value');
72 wakaba 1.13 }
73 wakaba 1.18 ## NOTE: Conformance to URI standard is not checked since there is
74     ## no author requirement on conformance in the XML Base specification.
75 wakaba 1.13 },
76     id => sub {
77     my ($self, $attr) = @_;
78     my $value = $attr->value;
79     $value =~ s/[\x09\x0A\x0D\x20]+/ /g;
80     $value =~ s/^\x20//;
81     $value =~ s/\x20$//;
82     ## TODO: NCName in XML 1.0 or 1.1
83     ## TODO: declared type is ID?
84 wakaba 1.33 if ($self->{id}->{$value}) { ## NOTE: An xml:id error
85     $self->{onerror}->(node => $attr, level => 'error',
86     type => 'duplicate ID');
87 wakaba 1.37 push @{$self->{id}->{$value}}, $attr;
88 wakaba 1.13 } else {
89 wakaba 1.37 $self->{id}->{$value} = [$attr];
90 wakaba 1.13 }
91     },
92 wakaba 1.9 },
93     $XMLNS_NS => {
94 wakaba 1.13 '' => sub {
95     my ($self, $attr) = @_;
96     my $ln = $attr->manakai_local_name;
97     my $value = $attr->value;
98     if ($value eq $XML_NS and $ln ne 'xml') {
99     $self->{onerror}
100 wakaba 1.33 ->(node => $attr, level => 'NC',
101     type => 'Reserved Prefixes and Namespace Names:=xml');
102 wakaba 1.13 } elsif ($value eq $XMLNS_NS) {
103     $self->{onerror}
104 wakaba 1.33 ->(node => $attr, level => 'NC',
105     type => 'Reserved Prefixes and Namespace Names:=xmlns');
106 wakaba 1.13 }
107     if ($ln eq 'xml' and $value ne $XML_NS) {
108     $self->{onerror}
109 wakaba 1.33 ->(node => $attr, level => 'NC',
110     type => 'Reserved Prefixes and Namespace Names:xmlns:xml=');
111 wakaba 1.13 } elsif ($ln eq 'xmlns') {
112     $self->{onerror}
113 wakaba 1.33 ->(node => $attr, level => 'NC',
114     type => 'Reserved Prefixes and Namespace Names:xmlns:xmlns=');
115 wakaba 1.13 }
116     ## TODO: If XML 1.0 and empty
117     },
118     xmlns => sub {
119     my ($self, $attr) = @_;
120     ## TODO: In XML 1.0, URI reference [RFC 3986] or an empty string
121     ## TODO: In XML 1.1, IRI reference [RFC 3987] or an empty string
122 wakaba 1.18 ## TODO: relative references are deprecated
123 wakaba 1.13 my $value = $attr->value;
124     if ($value eq $XML_NS) {
125     $self->{onerror}
126 wakaba 1.33 ->(node => $attr, level => 'NC',
127     type => 'Reserved Prefixes and Namespace Names:=xml');
128 wakaba 1.13 } elsif ($value eq $XMLNS_NS) {
129     $self->{onerror}
130 wakaba 1.33 ->(node => $attr, level => 'NC',
131     type => 'Reserved Prefixes and Namespace Names:=xmlns');
132 wakaba 1.13 }
133     },
134 wakaba 1.9 },
135     };
136    
137 wakaba 1.14 ## ISSUE: Should we really allow these attributes?
138 wakaba 1.13 $AttrChecker->{''}->{'xml:space'} = $AttrChecker->{$XML_NS}->{space};
139     $AttrChecker->{''}->{'xml:lang'} = $AttrChecker->{$XML_NS}->{lang};
140     $AttrChecker->{''}->{'xml:base'} = $AttrChecker->{$XML_NS}->{base};
141     $AttrChecker->{''}->{'xml:id'} = $AttrChecker->{$XML_NS}->{id};
142    
143 wakaba 1.3 ## ANY
144 wakaba 1.42 our $AnyChecker = sub {
145 wakaba 1.4 my ($self, $todo) = @_;
146     my $el = $todo->{node};
147     my $new_todos = [];
148 wakaba 1.3 my @nodes = (@{$el->child_nodes});
149     while (@nodes) {
150     my $node = shift @nodes;
151     $self->_remove_minuses ($node) and next if ref $node eq 'HASH';
152    
153     my $nt = $node->node_type;
154     if ($nt == 1) {
155     my $node_ns = $node->namespace_uri;
156     $node_ns = '' unless defined $node_ns;
157     my $node_ln = $node->manakai_local_name;
158     if ($self->{minuses}->{$node_ns}->{$node_ln}) {
159     $self->{onerror}->(node => $node, type => 'element not allowed');
160     }
161 wakaba 1.54 my ($sib, $ch) = $self->_check_get_children ($node, $todo);
162     unshift @nodes, @$sib;
163     push @$new_todos, @$ch;
164     } elsif ($nt == 3 or $nt == 4) {
165     if ($node->data =~ /[^\x09-\x0D\x20]/) {
166     $todo->{flag}->{has_descendant}->{significant} = 1;
167     }
168 wakaba 1.3 } elsif ($nt == 5) {
169     unshift @nodes, @{$node->child_nodes};
170     }
171     }
172 wakaba 1.4 return ($new_todos);
173 wakaba 1.3 }; # $AnyChecker
174    
175 wakaba 1.42 our $ElementDefault = {
176 wakaba 1.1 checker => sub {
177 wakaba 1.4 my ($self, $todo) = @_;
178 wakaba 1.33 $self->{onerror}->(node => $todo->{node}, level => 'unsupported',
179     type => 'element');
180 wakaba 1.4 return $AnyChecker->($self, $todo);
181 wakaba 1.1 },
182 wakaba 1.9 attrs_checker => sub {
183     my ($self, $todo) = @_;
184     for my $attr (@{$todo->{node}->attributes}) {
185     my $attr_ns = $attr->namespace_uri;
186     $attr_ns = '' unless defined $attr_ns;
187     my $attr_ln = $attr->manakai_local_name;
188     my $checker = $AttrChecker->{$attr_ns}->{$attr_ln}
189     || $AttrChecker->{$attr_ns}->{''};
190     if ($checker) {
191     $checker->($self, $attr);
192 wakaba 1.17 } else {
193 wakaba 1.33 $self->{onerror}->(node => $attr, level => 'unsupported',
194     type => 'attribute');
195 wakaba 1.9 }
196     }
197     },
198 wakaba 1.1 };
199    
200 wakaba 1.7 my $HTMLTransparentElements = {
201     $HTML_NS => {qw/ins 1 font 1 noscript 1/},
202 wakaba 1.29 ## NOTE: |html:noscript| is transparent if scripting is disabled
203     ## and not in |head|.
204 wakaba 1.7 };
205    
206 wakaba 1.42 our $Element = {};
207 wakaba 1.7
208 wakaba 1.56 sub check_document ($$$;$) {
209     my ($self, $doc, $onerror, $onsubdoc) = @_;
210 wakaba 1.42 $self = bless {}, $self unless ref $self;
211     $self->{onerror} = $onerror;
212 wakaba 1.56 $self->{onsubdoc} = $onsubdoc || sub {
213     warn "A subdocument is not conformance-checked";
214     };
215 wakaba 1.1
216 wakaba 1.48 $self->{must_level} = 'm';
217     $self->{fact_level} = 'f';
218     $self->{should_level} = 's';
219 wakaba 1.51 $self->{good_level} = 'w';
220 wakaba 1.48
221 wakaba 1.42 my $docel = $doc->document_element;
222     unless (defined $docel) {
223     ## ISSUE: Should we check content of Document node?
224     $onerror->(node => $doc, type => 'no document element');
225     ## ISSUE: Is this non-conforming (to what spec)? Or just a warning?
226     return {
227     class => {},
228     id => {}, table => [], term => {},
229     };
230 wakaba 1.1 }
231    
232 wakaba 1.42 ## ISSUE: Unexpanded entity references and HTML5 conformance
233 wakaba 1.1
234 wakaba 1.42 my $docel_nsuri = $docel->namespace_uri;
235     $docel_nsuri = '' unless defined $docel_nsuri;
236 wakaba 1.43 unless ($Namespace->{$docel_nsuri}->{loaded}) {
237     if ($Namespace->{$docel_nsuri}->{module}) {
238     eval qq{ require $Namespace->{$docel_nsuri}->{module} } or die $@;
239     } else {
240     $Namespace->{$docel_nsuri}->{loaded} = 1;
241     }
242     }
243 wakaba 1.42 my $docel_def = $Element->{$docel_nsuri}->{$docel->manakai_local_name} ||
244     $Element->{$docel_nsuri}->{''} ||
245     $ElementDefault;
246     if ($docel_def->{is_root}) {
247     #
248 wakaba 1.50 } elsif ($docel_def->{is_xml_root}) {
249     unless ($doc->manakai_is_html) {
250     #
251     } else {
252     $onerror->(node => $docel, type => 'element not allowed:root:xml');
253     }
254 wakaba 1.42 } else {
255 wakaba 1.49 $onerror->(node => $docel, type => 'element not allowed:root');
256 wakaba 1.1 }
257    
258 wakaba 1.42 ## TODO: Check for other items other than document element
259     ## (second (errorous) element, text nodes, PI nodes, doctype nodes)
260 wakaba 1.2
261 wakaba 1.56 my $return = $self->check_element ($docel, $onerror, $onsubdoc);
262 wakaba 1.51
263 wakaba 1.52 ## TODO: Test for these checks are necessary.
264 wakaba 1.51 my $charset_name = $doc->input_encoding;
265     if (defined $charset_name) {
266     require Message::Charset::Info;
267     my $charset = $Message::Charset::Info::IANACharset->{$charset_name};
268    
269     if ($doc->manakai_is_html and
270     not $doc->manakai_has_bom and
271     not defined $doc->manakai_charset) {
272     unless ($charset->{is_html_ascii_superset}) {
273     $onerror->(node => $doc, level => $self->{must_level},
274     type => 'non ascii superset:'.$charset_name);
275     }
276    
277     if (not $self->{has_charset} and
278     not $charset->{iana_names}->{'us-ascii'}) {
279     $onerror->(node => $doc, level => $self->{must_level},
280     type => 'no character encoding declaration:'.$charset_name);
281     }
282     }
283    
284     if ($charset->{iana_names}->{'utf-8'}) {
285     #
286     } elsif ($charset->{iana_names}->{'jis_x0212-1990'} or
287     $charset->{iana_names}->{'x-jis0208'} or
288     $charset->{iana_names}->{'utf-32'} or ## ISSUE: UTF-32BE? UTF-32LE?
289     $charset->{is_ebcdic_based}) {
290     $onerror->(node => $doc,
291     type => 'character encoding:'.$charset_name,
292     level => $self->{should_level});
293     } elsif ($charset->{iana_names}->{'cesu-8'} or
294     $charset->{iana_names}->{'utf-8'} or ## ISSUE: UNICODE-1-1-UTF-7?
295     $charset->{iana_names}->{'bocu-1'} or
296     $charset->{iana_names}->{'scsu'}) {
297     $onerror->(node => $doc,
298     type => 'character encoding:'.$charset_name,
299     level => $self->{must_level});
300     } else {
301     $onerror->(node => $doc,
302     type => 'character encoding:'.$charset_name,
303     level => $self->{good_level});
304     }
305 wakaba 1.52 } elsif ($doc->manakai_is_html) {
306     ## NOTE: MUST and SHOULD requirements above cannot be tested,
307     ## since the document has no input charset encoding information.
308     $onerror->(node => $doc,
309     type => 'character encoding:',
310     level => 'unsupported');
311 wakaba 1.51 }
312    
313     return $return;
314 wakaba 1.42 } # check_document
315 wakaba 1.1
316 wakaba 1.56 sub check_element ($$$;$) {
317     my ($self, $el, $onerror, $onsubdoc) = @_;
318 wakaba 1.42 $self = bless {}, $self unless ref $self;
319     $self->{onerror} = $onerror;
320 wakaba 1.56 $self->{onsubdoc} = $onsubdoc || sub {
321     warn "A subdocument is not conformance-checked";
322     };
323 wakaba 1.2
324 wakaba 1.48 $self->{must_level} = 'm';
325     $self->{fact_level} = 'f';
326     $self->{should_level} = 's';
327 wakaba 1.51 $self->{good_level} = 'w';
328 wakaba 1.48
329 wakaba 1.50 $self->{pluses} = {};
330 wakaba 1.42 $self->{minuses} = {};
331     $self->{id} = {};
332     $self->{term} = {};
333     $self->{usemap} = [];
334     $self->{contextmenu} = [];
335     $self->{map} = {};
336     $self->{menu} = {};
337     $self->{has_link_type} = {};
338 wakaba 1.46 #$self->{has_uri_attr};
339     #$self->{has_hyperlink_element};
340 wakaba 1.51 #$self->{has_charset};
341 wakaba 1.42 $self->{return} = {
342     class => {},
343     id => $self->{id}, table => [], term => $self->{term},
344     };
345 wakaba 1.4
346 wakaba 1.42 my @todo = ({type => 'element', node => $el});
347     while (@todo) {
348     my $todo = shift @todo;
349     if ($todo->{type} eq 'element') {
350     my $prefix = $todo->{node}->prefix;
351     if (defined $prefix and $prefix eq 'xmlns') {
352     $self->{onerror}
353     ->(node => $todo->{node}, level => 'NC',
354     type => 'Reserved Prefixes and Namespace Names:<xmlns:>');
355 wakaba 1.7 }
356 wakaba 1.42 my $nsuri = $todo->{node}->namespace_uri;
357     $nsuri = '' unless defined $nsuri;
358     unless ($Namespace->{$nsuri}->{loaded}) {
359     if ($Namespace->{$nsuri}->{module}) {
360     eval qq{ require $Namespace->{$nsuri}->{module} } or die $@;
361     } else {
362     $Namespace->{$nsuri}->{loaded} = 1;
363 wakaba 1.1 }
364     }
365 wakaba 1.42 my $ln = $todo->{node}->manakai_local_name;
366     my $eldef = $Element->{$nsuri}->{$ln} ||
367     $Element->{$nsuri}->{''} ||
368     $ElementDefault;
369     $eldef->{attrs_checker}->($self, $todo);
370     my ($new_todos) = $eldef->{checker}->($self, $todo);
371     unshift @todo, @$new_todos;
372     } elsif ($todo->{type} eq 'element-attributes') {
373     my $prefix = $todo->{node}->prefix;
374     if (defined $prefix and $prefix eq 'xmlns') {
375     $self->{onerror}
376     ->(node => $todo->{node}, level => 'NC',
377     type => 'Reserved Prefixes and Namespace Names:<xmlns:>');
378     }
379     my $nsuri = $todo->{node}->namespace_uri;
380     $nsuri = '' unless defined $nsuri;
381     unless ($Namespace->{$nsuri}->{loaded}) {
382     if ($Namespace->{$nsuri}->{module}) {
383     eval qq{ require $Namespace->{$nsuri}->{module} } or die $@;
384 wakaba 1.1 } else {
385 wakaba 1.42 $Namespace->{$nsuri}->{loaded} = 1;
386 wakaba 1.1 }
387     }
388 wakaba 1.9 my $ln = $todo->{node}->manakai_local_name;
389     my $eldef = $Element->{$nsuri}->{$ln} ||
390     $Element->{$nsuri}->{''} ||
391     $ElementDefault;
392     $eldef->{attrs_checker}->($self, $todo);
393 wakaba 1.53 } elsif ($todo->{type} eq 'descendant') {
394     for my $key (keys %{$todo->{errors}}) {
395     unless ($todo->{flag}->{has_descendant}->{$key}) {
396     $todo->{errors}->{$key}->($self, $todo);
397     }
398     for my $key (keys %{$todo->{old_values}}) {
399     $todo->{flag}->{has_descendant}->{$key}
400     ||= $todo->{old_values}->{$key};
401     }
402     }
403 wakaba 1.50 } elsif ($todo->{type} eq 'plus' or $todo->{type} eq 'minus') {
404 wakaba 1.4 $self->_remove_minuses ($todo);
405 wakaba 1.30 } elsif ($todo->{type} eq 'code') {
406     $todo->{code}->();
407     } else {
408     die "$0: Internal error: Unsupported checking action type |$todo->{type}|";
409 wakaba 1.4 }
410 wakaba 1.1 }
411 wakaba 1.17
412     for (@{$self->{usemap}}) {
413     unless ($self->{map}->{$_->[0]}) {
414     $self->{onerror}->(node => $_->[1], type => 'no referenced map');
415     }
416     }
417    
418 wakaba 1.32 for (@{$self->{contextmenu}}) {
419     unless ($self->{menu}->{$_->[0]}) {
420     $self->{onerror}->(node => $_->[1], type => 'no referenced menu');
421     }
422     }
423    
424 wakaba 1.50 delete $self->{pluses};
425 wakaba 1.17 delete $self->{minuses};
426     delete $self->{onerror};
427     delete $self->{id};
428     delete $self->{usemap};
429     delete $self->{map};
430 wakaba 1.33 return $self->{return};
431 wakaba 1.1 } # check_element
432    
433 wakaba 1.2 sub _add_minuses ($@) {
434     my $self = shift;
435     my $r = {};
436     for my $list (@_) {
437     for my $ns (keys %$list) {
438     for my $ln (keys %{$list->{$ns}}) {
439     unless ($self->{minuses}->{$ns}->{$ln}) {
440     $self->{minuses}->{$ns}->{$ln} = 1;
441     $r->{$ns}->{$ln} = 1;
442     }
443     }
444     }
445     }
446 wakaba 1.4 return {type => 'plus', list => $r};
447 wakaba 1.2 } # _add_minuses
448    
449 wakaba 1.50 sub _add_pluses ($@) {
450     my $self = shift;
451     my $r = {};
452     for my $list (@_) {
453     for my $ns (keys %$list) {
454     for my $ln (keys %{$list->{$ns}}) {
455     unless ($self->{pluses}->{$ns}->{$ln}) {
456     $self->{pluses}->{$ns}->{$ln} = 1;
457     $r->{$ns}->{$ln} = 1;
458     }
459     }
460     }
461     }
462     return {type => 'minus', list => $r};
463     } # _add_pluses
464    
465 wakaba 1.2 sub _remove_minuses ($$) {
466 wakaba 1.4 my ($self, $todo) = @_;
467 wakaba 1.50 if ($todo->{type} eq 'minus') {
468     for my $ns (keys %{$todo->{list}}) {
469     for my $ln (keys %{$todo->{list}->{$ns}}) {
470     delete $self->{pluses}->{$ns}->{$ln} if $todo->{list}->{$ns}->{$ln};
471     }
472 wakaba 1.2 }
473 wakaba 1.50 } elsif ($todo->{type} eq 'plus') {
474     for my $ns (keys %{$todo->{list}}) {
475     for my $ln (keys %{$todo->{list}->{$ns}}) {
476     delete $self->{minuses}->{$ns}->{$ln} if $todo->{list}->{$ns}->{$ln};
477     }
478     }
479     } else {
480     die "$0: Unknown +- type: $todo->{type}";
481 wakaba 1.2 }
482     1;
483     } # _remove_minuses
484    
485 wakaba 1.50 ## NOTE: Priority for "minuses" and "pluses" are currently left
486     ## undefined and implemented inconsistently; it is not a problem for
487     ## now, since no element belongs to both lists.
488    
489 wakaba 1.30 sub _check_get_children ($$$) {
490     my ($self, $node, $parent_todo) = @_;
491 wakaba 1.4 my $new_todos = [];
492 wakaba 1.2 my $sib = [];
493     TP: {
494     my $node_ns = $node->namespace_uri;
495     $node_ns = '' unless defined $node_ns;
496     my $node_ln = $node->manakai_local_name;
497 wakaba 1.45 if ($HTMLTransparentElements->{$node_ns}->{$node_ln}) {
498     if ($node_ns eq $HTML_NS and $node_ln eq 'noscript') {
499     if ($parent_todo->{flag}->{in_head}) {
500     #
501     } else {
502     my $end = $self->_add_minuses ({$HTML_NS, {noscript => 1}});
503     push @$sib, $end;
504    
505     unshift @$sib, @{$node->child_nodes};
506     push @$new_todos, {type => 'element-attributes', node => $node};
507     last TP;
508     }
509     } else {
510     unshift @$sib, @{$node->child_nodes};
511     push @$new_todos, {type => 'element-attributes', node => $node};
512     last TP;
513 wakaba 1.2 }
514     }
515 wakaba 1.8 if ($node_ns eq $HTML_NS and ($node_ln eq 'video' or $node_ln eq 'audio')) {
516 wakaba 1.2 if ($node->has_attribute_ns (undef, 'src')) {
517     unshift @$sib, @{$node->child_nodes};
518 wakaba 1.9 push @$new_todos, {type => 'element-attributes', node => $node};
519 wakaba 1.2 last TP;
520     } else {
521     my @cn = @{$node->child_nodes};
522     CN: while (@cn) {
523     my $cn = shift @cn;
524     my $cnt = $cn->node_type;
525     if ($cnt == 1) {
526 wakaba 1.8 my $cn_nsuri = $cn->namespace_uri;
527     $cn_nsuri = '' unless defined $cn_nsuri;
528     if ($cn_nsuri eq $HTML_NS and $cn->manakai_local_name eq 'source') {
529 wakaba 1.2 #
530     } else {
531     last CN;
532     }
533     } elsif ($cnt == 3 or $cnt == 4) {
534     if ($cn->data =~ /[^\x09-\x0D\x20]/) {
535     last CN;
536     }
537     }
538     } # CN
539     unshift @$sib, @cn;
540     }
541     }
542 wakaba 1.4 push @$new_todos, {type => 'element', node => $node};
543 wakaba 1.2 } # TP
544 wakaba 1.30
545     for my $new_todo (@$new_todos) {
546     $new_todo->{flag} = {%{$parent_todo->{flag} or {}}};
547     }
548    
549 wakaba 1.4 return ($sib, $new_todos);
550 wakaba 1.2 } # _check_get_children
551    
552 wakaba 1.44 =head1 LICENSE
553    
554 wakaba 1.56 Copyright 2007-2008 Wakaba <w@suika.fam.cx>
555 wakaba 1.44
556     This library is free software; you can redistribute it
557     and/or modify it under the same terms as Perl itself.
558    
559     =cut
560    
561 wakaba 1.1 1;
562 wakaba 1.56 # $Date: 2008/02/09 11:58:16 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24