/[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.57 - (hide annotations) (download)
Sun Feb 17 06:36:28 2008 UTC (16 years, 8 months ago) by wakaba
Branch: MAIN
Changes since 1.56: +26 -3 lines
++ whatpm/t/ChangeLog	17 Feb 2008 06:35:24 -0000
2008-02-17  Wakaba  <wakaba@suika.fam.cx>

	* content-model-1.dat, content-model-2.dat, content-model-5.dat:
	Test results are updated; new tests are added.

++ whatpm/Whatpm/ChangeLog	17 Feb 2008 06:34:11 -0000
2008-02-17  Wakaba  <wakaba@suika.fam.cx>

	* ContenteChecker.pm ($HTMLTransparentElements): More
	elements are added.
	(_get_children): HTML |object| elements are now semi-transparent.

	* NanoDOM.pm (manakai_html, manakai_head): New methods.

++ whatpm/Whatpm/ContentChecker/ChangeLog	17 Feb 2008 06:32:44 -0000
2008-02-17  Wakaba  <wakaba@suika.fam.cx>

	* HTML.pm: Most part of December 2007 Content Model is implemented.

1 wakaba 1.1 package Whatpm::ContentChecker;
2     use strict;
3 wakaba 1.57 our $VERSION=do{my @r=(q$Revision: 1.56 $=~/\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 wakaba 1.57 $HTML_NS => {qw/ins 1 del 1 font 1 noscript 1 canvas 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.57 ## Semi-transparent: html:video, html:audio, html:object
207    
208 wakaba 1.42 our $Element = {};
209 wakaba 1.7
210 wakaba 1.56 sub check_document ($$$;$) {
211     my ($self, $doc, $onerror, $onsubdoc) = @_;
212 wakaba 1.42 $self = bless {}, $self unless ref $self;
213     $self->{onerror} = $onerror;
214 wakaba 1.56 $self->{onsubdoc} = $onsubdoc || sub {
215     warn "A subdocument is not conformance-checked";
216     };
217 wakaba 1.1
218 wakaba 1.48 $self->{must_level} = 'm';
219     $self->{fact_level} = 'f';
220     $self->{should_level} = 's';
221 wakaba 1.51 $self->{good_level} = 'w';
222 wakaba 1.48
223 wakaba 1.42 my $docel = $doc->document_element;
224     unless (defined $docel) {
225     ## ISSUE: Should we check content of Document node?
226     $onerror->(node => $doc, type => 'no document element');
227     ## ISSUE: Is this non-conforming (to what spec)? Or just a warning?
228     return {
229     class => {},
230     id => {}, table => [], term => {},
231     };
232 wakaba 1.1 }
233    
234 wakaba 1.42 ## ISSUE: Unexpanded entity references and HTML5 conformance
235 wakaba 1.1
236 wakaba 1.42 my $docel_nsuri = $docel->namespace_uri;
237     $docel_nsuri = '' unless defined $docel_nsuri;
238 wakaba 1.43 unless ($Namespace->{$docel_nsuri}->{loaded}) {
239     if ($Namespace->{$docel_nsuri}->{module}) {
240     eval qq{ require $Namespace->{$docel_nsuri}->{module} } or die $@;
241     } else {
242     $Namespace->{$docel_nsuri}->{loaded} = 1;
243     }
244     }
245 wakaba 1.42 my $docel_def = $Element->{$docel_nsuri}->{$docel->manakai_local_name} ||
246     $Element->{$docel_nsuri}->{''} ||
247     $ElementDefault;
248     if ($docel_def->{is_root}) {
249     #
250 wakaba 1.50 } elsif ($docel_def->{is_xml_root}) {
251     unless ($doc->manakai_is_html) {
252     #
253     } else {
254     $onerror->(node => $docel, type => 'element not allowed:root:xml');
255     }
256 wakaba 1.42 } else {
257 wakaba 1.49 $onerror->(node => $docel, type => 'element not allowed:root');
258 wakaba 1.1 }
259    
260 wakaba 1.42 ## TODO: Check for other items other than document element
261     ## (second (errorous) element, text nodes, PI nodes, doctype nodes)
262 wakaba 1.2
263 wakaba 1.56 my $return = $self->check_element ($docel, $onerror, $onsubdoc);
264 wakaba 1.51
265 wakaba 1.52 ## TODO: Test for these checks are necessary.
266 wakaba 1.51 my $charset_name = $doc->input_encoding;
267     if (defined $charset_name) {
268     require Message::Charset::Info;
269     my $charset = $Message::Charset::Info::IANACharset->{$charset_name};
270    
271     if ($doc->manakai_is_html and
272     not $doc->manakai_has_bom and
273     not defined $doc->manakai_charset) {
274     unless ($charset->{is_html_ascii_superset}) {
275     $onerror->(node => $doc, level => $self->{must_level},
276     type => 'non ascii superset:'.$charset_name);
277     }
278    
279     if (not $self->{has_charset} and
280     not $charset->{iana_names}->{'us-ascii'}) {
281     $onerror->(node => $doc, level => $self->{must_level},
282     type => 'no character encoding declaration:'.$charset_name);
283     }
284     }
285    
286     if ($charset->{iana_names}->{'utf-8'}) {
287     #
288     } elsif ($charset->{iana_names}->{'jis_x0212-1990'} or
289     $charset->{iana_names}->{'x-jis0208'} or
290     $charset->{iana_names}->{'utf-32'} or ## ISSUE: UTF-32BE? UTF-32LE?
291     $charset->{is_ebcdic_based}) {
292     $onerror->(node => $doc,
293     type => 'character encoding:'.$charset_name,
294     level => $self->{should_level});
295     } elsif ($charset->{iana_names}->{'cesu-8'} or
296     $charset->{iana_names}->{'utf-8'} or ## ISSUE: UNICODE-1-1-UTF-7?
297     $charset->{iana_names}->{'bocu-1'} or
298     $charset->{iana_names}->{'scsu'}) {
299     $onerror->(node => $doc,
300     type => 'character encoding:'.$charset_name,
301     level => $self->{must_level});
302     } else {
303     $onerror->(node => $doc,
304     type => 'character encoding:'.$charset_name,
305     level => $self->{good_level});
306     }
307 wakaba 1.52 } elsif ($doc->manakai_is_html) {
308     ## NOTE: MUST and SHOULD requirements above cannot be tested,
309     ## since the document has no input charset encoding information.
310     $onerror->(node => $doc,
311     type => 'character encoding:',
312     level => 'unsupported');
313 wakaba 1.51 }
314    
315     return $return;
316 wakaba 1.42 } # check_document
317 wakaba 1.1
318 wakaba 1.56 sub check_element ($$$;$) {
319     my ($self, $el, $onerror, $onsubdoc) = @_;
320 wakaba 1.42 $self = bless {}, $self unless ref $self;
321     $self->{onerror} = $onerror;
322 wakaba 1.56 $self->{onsubdoc} = $onsubdoc || sub {
323     warn "A subdocument is not conformance-checked";
324     };
325 wakaba 1.2
326 wakaba 1.48 $self->{must_level} = 'm';
327     $self->{fact_level} = 'f';
328     $self->{should_level} = 's';
329 wakaba 1.51 $self->{good_level} = 'w';
330 wakaba 1.48
331 wakaba 1.50 $self->{pluses} = {};
332 wakaba 1.42 $self->{minuses} = {};
333     $self->{id} = {};
334     $self->{term} = {};
335     $self->{usemap} = [];
336     $self->{contextmenu} = [];
337     $self->{map} = {};
338     $self->{menu} = {};
339     $self->{has_link_type} = {};
340 wakaba 1.46 #$self->{has_uri_attr};
341     #$self->{has_hyperlink_element};
342 wakaba 1.51 #$self->{has_charset};
343 wakaba 1.57 #$self->{has_base};
344 wakaba 1.42 $self->{return} = {
345     class => {},
346     id => $self->{id}, table => [], term => $self->{term},
347     };
348 wakaba 1.4
349 wakaba 1.42 my @todo = ({type => 'element', node => $el});
350     while (@todo) {
351     my $todo = shift @todo;
352     if ($todo->{type} eq 'element') {
353     my $prefix = $todo->{node}->prefix;
354     if (defined $prefix and $prefix eq 'xmlns') {
355     $self->{onerror}
356     ->(node => $todo->{node}, level => 'NC',
357     type => 'Reserved Prefixes and Namespace Names:<xmlns:>');
358 wakaba 1.7 }
359 wakaba 1.42 my $nsuri = $todo->{node}->namespace_uri;
360     $nsuri = '' unless defined $nsuri;
361     unless ($Namespace->{$nsuri}->{loaded}) {
362     if ($Namespace->{$nsuri}->{module}) {
363     eval qq{ require $Namespace->{$nsuri}->{module} } or die $@;
364     } else {
365     $Namespace->{$nsuri}->{loaded} = 1;
366 wakaba 1.1 }
367     }
368 wakaba 1.42 my $ln = $todo->{node}->manakai_local_name;
369     my $eldef = $Element->{$nsuri}->{$ln} ||
370     $Element->{$nsuri}->{''} ||
371     $ElementDefault;
372     $eldef->{attrs_checker}->($self, $todo);
373     my ($new_todos) = $eldef->{checker}->($self, $todo);
374     unshift @todo, @$new_todos;
375     } elsif ($todo->{type} eq 'element-attributes') {
376     my $prefix = $todo->{node}->prefix;
377     if (defined $prefix and $prefix eq 'xmlns') {
378     $self->{onerror}
379     ->(node => $todo->{node}, level => 'NC',
380     type => 'Reserved Prefixes and Namespace Names:<xmlns:>');
381     }
382     my $nsuri = $todo->{node}->namespace_uri;
383     $nsuri = '' unless defined $nsuri;
384     unless ($Namespace->{$nsuri}->{loaded}) {
385     if ($Namespace->{$nsuri}->{module}) {
386     eval qq{ require $Namespace->{$nsuri}->{module} } or die $@;
387 wakaba 1.1 } else {
388 wakaba 1.42 $Namespace->{$nsuri}->{loaded} = 1;
389 wakaba 1.1 }
390     }
391 wakaba 1.9 my $ln = $todo->{node}->manakai_local_name;
392     my $eldef = $Element->{$nsuri}->{$ln} ||
393     $Element->{$nsuri}->{''} ||
394     $ElementDefault;
395     $eldef->{attrs_checker}->($self, $todo);
396 wakaba 1.53 } elsif ($todo->{type} eq 'descendant') {
397     for my $key (keys %{$todo->{errors}}) {
398     unless ($todo->{flag}->{has_descendant}->{$key}) {
399     $todo->{errors}->{$key}->($self, $todo);
400     }
401     for my $key (keys %{$todo->{old_values}}) {
402     $todo->{flag}->{has_descendant}->{$key}
403     ||= $todo->{old_values}->{$key};
404     }
405     }
406 wakaba 1.50 } elsif ($todo->{type} eq 'plus' or $todo->{type} eq 'minus') {
407 wakaba 1.4 $self->_remove_minuses ($todo);
408 wakaba 1.30 } elsif ($todo->{type} eq 'code') {
409     $todo->{code}->();
410     } else {
411     die "$0: Internal error: Unsupported checking action type |$todo->{type}|";
412 wakaba 1.4 }
413 wakaba 1.1 }
414 wakaba 1.17
415     for (@{$self->{usemap}}) {
416     unless ($self->{map}->{$_->[0]}) {
417     $self->{onerror}->(node => $_->[1], type => 'no referenced map');
418     }
419     }
420    
421 wakaba 1.32 for (@{$self->{contextmenu}}) {
422     unless ($self->{menu}->{$_->[0]}) {
423     $self->{onerror}->(node => $_->[1], type => 'no referenced menu');
424     }
425     }
426    
427 wakaba 1.50 delete $self->{pluses};
428 wakaba 1.17 delete $self->{minuses};
429     delete $self->{onerror};
430     delete $self->{id};
431     delete $self->{usemap};
432     delete $self->{map};
433 wakaba 1.33 return $self->{return};
434 wakaba 1.1 } # check_element
435    
436 wakaba 1.2 sub _add_minuses ($@) {
437     my $self = shift;
438     my $r = {};
439     for my $list (@_) {
440     for my $ns (keys %$list) {
441     for my $ln (keys %{$list->{$ns}}) {
442     unless ($self->{minuses}->{$ns}->{$ln}) {
443     $self->{minuses}->{$ns}->{$ln} = 1;
444     $r->{$ns}->{$ln} = 1;
445     }
446     }
447     }
448     }
449 wakaba 1.4 return {type => 'plus', list => $r};
450 wakaba 1.2 } # _add_minuses
451    
452 wakaba 1.50 sub _add_pluses ($@) {
453     my $self = shift;
454     my $r = {};
455     for my $list (@_) {
456     for my $ns (keys %$list) {
457     for my $ln (keys %{$list->{$ns}}) {
458     unless ($self->{pluses}->{$ns}->{$ln}) {
459     $self->{pluses}->{$ns}->{$ln} = 1;
460     $r->{$ns}->{$ln} = 1;
461     }
462     }
463     }
464     }
465     return {type => 'minus', list => $r};
466     } # _add_pluses
467    
468 wakaba 1.2 sub _remove_minuses ($$) {
469 wakaba 1.4 my ($self, $todo) = @_;
470 wakaba 1.50 if ($todo->{type} eq 'minus') {
471     for my $ns (keys %{$todo->{list}}) {
472     for my $ln (keys %{$todo->{list}->{$ns}}) {
473     delete $self->{pluses}->{$ns}->{$ln} if $todo->{list}->{$ns}->{$ln};
474     }
475 wakaba 1.2 }
476 wakaba 1.50 } elsif ($todo->{type} eq 'plus') {
477     for my $ns (keys %{$todo->{list}}) {
478     for my $ln (keys %{$todo->{list}->{$ns}}) {
479     delete $self->{minuses}->{$ns}->{$ln} if $todo->{list}->{$ns}->{$ln};
480     }
481     }
482     } else {
483     die "$0: Unknown +- type: $todo->{type}";
484 wakaba 1.2 }
485     1;
486     } # _remove_minuses
487    
488 wakaba 1.50 ## NOTE: Priority for "minuses" and "pluses" are currently left
489     ## undefined and implemented inconsistently; it is not a problem for
490     ## now, since no element belongs to both lists.
491    
492 wakaba 1.30 sub _check_get_children ($$$) {
493     my ($self, $node, $parent_todo) = @_;
494 wakaba 1.4 my $new_todos = [];
495 wakaba 1.2 my $sib = [];
496     TP: {
497     my $node_ns = $node->namespace_uri;
498     $node_ns = '' unless defined $node_ns;
499     my $node_ln = $node->manakai_local_name;
500 wakaba 1.45 if ($HTMLTransparentElements->{$node_ns}->{$node_ln}) {
501     if ($node_ns eq $HTML_NS and $node_ln eq 'noscript') {
502     if ($parent_todo->{flag}->{in_head}) {
503     #
504     } else {
505     my $end = $self->_add_minuses ({$HTML_NS, {noscript => 1}});
506     push @$sib, $end;
507    
508     unshift @$sib, @{$node->child_nodes};
509     push @$new_todos, {type => 'element-attributes', node => $node};
510     last TP;
511     }
512     } else {
513     unshift @$sib, @{$node->child_nodes};
514     push @$new_todos, {type => 'element-attributes', node => $node};
515     last TP;
516 wakaba 1.2 }
517     }
518 wakaba 1.8 if ($node_ns eq $HTML_NS and ($node_ln eq 'video' or $node_ln eq 'audio')) {
519 wakaba 1.2 if ($node->has_attribute_ns (undef, 'src')) {
520     unshift @$sib, @{$node->child_nodes};
521 wakaba 1.9 push @$new_todos, {type => 'element-attributes', node => $node};
522 wakaba 1.2 last TP;
523     } else {
524     my @cn = @{$node->child_nodes};
525     CN: while (@cn) {
526     my $cn = shift @cn;
527     my $cnt = $cn->node_type;
528     if ($cnt == 1) {
529 wakaba 1.8 my $cn_nsuri = $cn->namespace_uri;
530     $cn_nsuri = '' unless defined $cn_nsuri;
531     if ($cn_nsuri eq $HTML_NS and $cn->manakai_local_name eq 'source') {
532 wakaba 1.2 #
533     } else {
534     last CN;
535     }
536     } elsif ($cnt == 3 or $cnt == 4) {
537     if ($cn->data =~ /[^\x09-\x0D\x20]/) {
538     last CN;
539     }
540     }
541     } # CN
542     unshift @$sib, @cn;
543     }
544 wakaba 1.57 } elsif ($node_ns eq $HTML_NS and $node_ln eq 'object') {
545     my @cn = @{$node->child_nodes};
546     CN: while (@cn) {
547     my $cn = shift @cn;
548     my $cnt = $cn->node_type;
549     if ($cnt == 1) {
550     my $cn_nsuri = $cn->namespace_uri;
551     $cn_nsuri = '' unless defined $cn_nsuri;
552     if ($cn_nsuri eq $HTML_NS and $cn->manakai_local_name eq 'param') {
553     #
554     } else {
555     last CN;
556     }
557     } elsif ($cnt == 3 or $cnt == 4) {
558     if ($cn->data =~ /[^\x09-\x0D\x20]/) {
559     last CN;
560     }
561     }
562     } # CN
563     unshift @$sib, @cn;
564 wakaba 1.2 }
565 wakaba 1.4 push @$new_todos, {type => 'element', node => $node};
566 wakaba 1.2 } # TP
567 wakaba 1.30
568     for my $new_todo (@$new_todos) {
569     $new_todo->{flag} = {%{$parent_todo->{flag} or {}}};
570     }
571    
572 wakaba 1.4 return ($sib, $new_todos);
573 wakaba 1.2 } # _check_get_children
574    
575 wakaba 1.44 =head1 LICENSE
576    
577 wakaba 1.56 Copyright 2007-2008 Wakaba <w@suika.fam.cx>
578 wakaba 1.44
579     This library is free software; you can redistribute it
580     and/or modify it under the same terms as Perl itself.
581    
582     =cut
583    
584 wakaba 1.1 1;
585 wakaba 1.57 # $Date: 2008/02/10 04:09:57 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24