/[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.103 - (hide annotations) (download)
Sat Dec 6 10:00:53 2008 UTC (15 years, 11 months ago) by wakaba
Branch: MAIN
Changes since 1.102: +4 -4 lines
++ whatpm/t/ChangeLog	6 Dec 2008 10:00:34 -0000
2008-12-06  Wakaba  <wakaba@suika.fam.cx>

	* content-checker.pl: Use new XML parser for parsing test data.
	Use NanoDOM instead of manakai DOM implementation.

++ whatpm/Whatpm/ChangeLog	6 Dec 2008 09:58:56 -0000
2008-12-06  Wakaba  <wakaba@suika.fam.cx>

	* NanoDOM.pm (document_uri): New attribute.

	* ContentChecker.pm: Don't use methods not implemented by NanoDOM.

++ whatpm/Whatpm/ContentChecker/ChangeLog	6 Dec 2008 09:59:53 -0000
2008-12-06  Wakaba  <wakaba@suika.fam.cx>

	* HTML.pm: Use |Message::URL| for relative URL resolution.  Don't
	use attributes not supported by NanoDOM.

1 wakaba 1.1 package Whatpm::ContentChecker;
2     use strict;
3 wakaba 1.103 our $VERSION=do{my @r=(q$Revision: 1.102 $=~/\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.70 ## Stability
13 wakaba 1.67 sub FEATURE_STATUS_REC () { 0b1 } ## Interoperable standard
14     sub FEATURE_STATUS_CR () { 0b10 } ## Call for implementation
15     sub FEATURE_STATUS_LC () { 0b100 } ## Last call for comments
16     sub FEATURE_STATUS_WD () { 0b1000 } ## Working or editor's draft
17    
18 wakaba 1.70 ## Deprecated
19     sub FEATURE_DEPRECATED_SHOULD () { 0b100000 } ## SHOULD-level
20     sub FEATURE_DEPRECATED_INFO () { 0b1000000 } ## Does not affect conformance
21    
22     ## Conformance
23     sub FEATURE_ALLOWED () { 0b10000 }
24    
25 wakaba 1.42 my $HTML_NS = q<http://www.w3.org/1999/xhtml>;
26 wakaba 1.9 my $XML_NS = q<http://www.w3.org/XML/1998/namespace>;
27     my $XMLNS_NS = q<http://www.w3.org/2000/xmlns/>;
28    
29 wakaba 1.42 my $Namespace = {
30 wakaba 1.79 '' => {loaded => 1},
31 wakaba 1.43 q<http://www.w3.org/2005/Atom> => {module => 'Whatpm::ContentChecker::Atom'},
32 wakaba 1.72 q<http://purl.org/syndication/history/1.0>
33     => {module => 'Whatpm::ContentChecker::Atom'},
34     q<http://purl.org/syndication/threading/1.0>
35     => {module => 'Whatpm::ContentChecker::Atom'},
36 wakaba 1.42 $HTML_NS => {module => 'Whatpm::ContentChecker::HTML'},
37     $XML_NS => {loaded => 1},
38     $XMLNS_NS => {loaded => 1},
39 wakaba 1.73 q<http://www.w3.org/1999/02/22-rdf-syntax-ns#> => {loaded => 1},
40 wakaba 1.42 };
41    
42 wakaba 1.79 sub load_ns_module ($) {
43     my $nsuri = shift; # namespace URI or ''
44     unless ($Namespace->{$nsuri}->{loaded}) {
45     if ($Namespace->{$nsuri}->{module}) {
46     eval qq{ require $Namespace->{$nsuri}->{module} } or die $@;
47     } else {
48     $Namespace->{$nsuri}->{loaded} = 1;
49     }
50     }
51     } # load_ns_module
52    
53 wakaba 1.42 our $AttrChecker = {
54 wakaba 1.9 $XML_NS => {
55 wakaba 1.13 space => sub {
56     my ($self, $attr) = @_;
57     my $value = $attr->value;
58     if ($value eq 'default' or $value eq 'preserve') {
59     #
60     } else {
61     ## NOTE: An XML "error"
62 wakaba 1.83 $self->{onerror}->(node => $attr, level => $self->{level}->{xml_error},
63 wakaba 1.33 type => 'invalid attribute value');
64 wakaba 1.13 }
65     },
66     lang => sub {
67 wakaba 1.35 my ($self, $attr) = @_;
68 wakaba 1.47 my $value = $attr->value;
69     if ($value eq '') {
70     #
71     } else {
72     require Whatpm::LangTag;
73     Whatpm::LangTag->check_rfc3066_language_tag ($value, sub {
74 wakaba 1.83 $self->{onerror}->(@_, node => $attr);
75 wakaba 1.85 }, $self->{level});
76 wakaba 1.47 }
77    
78 wakaba 1.13 ## NOTE: "The values of the attribute are language identifiers
79     ## as defined by [IETF RFC 3066], Tags for the Identification
80     ## of Languages, or its successor; in addition, the empty string
81     ## may be specified." ("may" in lower case)
82 wakaba 1.94 ## NOTE: Is an RFC 3066-valid (but RFC 4646-invalid) language tag
83 wakaba 1.47 ## allowed today?
84    
85     ## TODO: test data
86    
87 wakaba 1.89 my $nsuri = $attr->owner_element->namespace_uri;
88     if (defined $nsuri and $nsuri eq $HTML_NS) {
89     my $lang_attr = $attr->owner_element->get_attribute_node_ns
90     (undef, 'lang');
91     if ($lang_attr) {
92     my $lang_attr_value = $lang_attr->value;
93     $lang_attr_value =~ tr/A-Z/a-z/; ## ASCII case-insensitive
94     my $value = $value;
95     $value =~ tr/A-Z/a-z/; ## ASCII case-insensitive
96     if ($lang_attr_value ne $value) {
97     ## NOTE: HTML5 Section "The |lang| and |xml:lang| attributes"
98     $self->{onerror}->(node => $attr,
99     type => 'xml:lang ne lang',
100     level => $self->{level}->{must});
101     }
102     }
103     }
104    
105 wakaba 1.35 if ($attr->owner_document->manakai_is_html) { # MUST NOT
106 wakaba 1.83 $self->{onerror}->(node => $attr, type => 'in HTML:xml:lang',
107     level => $self->{level}->{must});
108 wakaba 1.35 ## TODO: Test data...
109     }
110 wakaba 1.13 },
111     base => sub {
112     my ($self, $attr) = @_;
113     my $value = $attr->value;
114     if ($value =~ /[^\x{0000}-\x{10FFFF}]/) { ## ISSUE: Should we disallow noncharacters?
115     $self->{onerror}->(node => $attr,
116 wakaba 1.83 type => 'invalid attribute value',
117     level => $self->{level}->{fact}, ## TODO: correct?
118     );
119 wakaba 1.13 }
120 wakaba 1.18 ## NOTE: Conformance to URI standard is not checked since there is
121     ## no author requirement on conformance in the XML Base specification.
122 wakaba 1.13 },
123     id => sub {
124 wakaba 1.98 my ($self, $attr, $item, $element_state) = @_;
125 wakaba 1.13 my $value = $attr->value;
126     $value =~ s/[\x09\x0A\x0D\x20]+/ /g;
127     $value =~ s/^\x20//;
128     $value =~ s/\x20$//;
129     ## TODO: NCName in XML 1.0 or 1.1
130     ## TODO: declared type is ID?
131 wakaba 1.83 if ($self->{id}->{$value}) {
132     $self->{onerror}->(node => $attr,
133     type => 'duplicate ID',
134     level => $self->{level}->{xml_id_error});
135 wakaba 1.37 push @{$self->{id}->{$value}}, $attr;
136 wakaba 1.13 } else {
137 wakaba 1.37 $self->{id}->{$value} = [$attr];
138 wakaba 1.98 $self->{id_type}->{$value} = $element_state->{id_type} || '';
139 wakaba 1.13 }
140     },
141 wakaba 1.9 },
142     $XMLNS_NS => {
143 wakaba 1.13 '' => sub {
144     my ($self, $attr) = @_;
145     my $ln = $attr->manakai_local_name;
146     my $value = $attr->value;
147     if ($value eq $XML_NS and $ln ne 'xml') {
148     $self->{onerror}
149 wakaba 1.83 ->(node => $attr,
150     type => 'Reserved Prefixes and Namespace Names:Name',
151     text => $value,
152     level => $self->{level}->{nc});
153 wakaba 1.13 } elsif ($value eq $XMLNS_NS) {
154     $self->{onerror}
155 wakaba 1.83 ->(node => $attr,
156     type => 'Reserved Prefixes and Namespace Names:Name',
157     text => $value,
158     level => $self->{level}->{nc});
159 wakaba 1.13 }
160     if ($ln eq 'xml' and $value ne $XML_NS) {
161     $self->{onerror}
162 wakaba 1.83 ->(node => $attr,
163     type => 'Reserved Prefixes and Namespace Names:Prefix',
164     text => $ln,
165     level => $self->{level}->{nc});
166 wakaba 1.13 } elsif ($ln eq 'xmlns') {
167     $self->{onerror}
168 wakaba 1.83 ->(node => $attr,
169     type => 'Reserved Prefixes and Namespace Names:Prefix',
170     text => $ln,
171     level => $self->{level}->{nc});
172 wakaba 1.13 }
173     ## TODO: If XML 1.0 and empty
174     },
175     xmlns => sub {
176     my ($self, $attr) = @_;
177     ## TODO: In XML 1.0, URI reference [RFC 3986] or an empty string
178     ## TODO: In XML 1.1, IRI reference [RFC 3987] or an empty string
179 wakaba 1.18 ## TODO: relative references are deprecated
180 wakaba 1.13 my $value = $attr->value;
181     if ($value eq $XML_NS) {
182     $self->{onerror}
183 wakaba 1.83 ->(node => $attr,
184     type => 'Reserved Prefixes and Namespace Names:Name',
185     text => $value,
186     level => $self->{level}->{nc});
187 wakaba 1.13 } elsif ($value eq $XMLNS_NS) {
188     $self->{onerror}
189 wakaba 1.83 ->(node => $attr,
190     type => 'Reserved Prefixes and Namespace Names:Name',
191     text => $value,
192     level => $self->{level}->{nc});
193 wakaba 1.13 }
194     },
195 wakaba 1.9 },
196     };
197    
198 wakaba 1.14 ## ISSUE: Should we really allow these attributes?
199 wakaba 1.13 $AttrChecker->{''}->{'xml:space'} = $AttrChecker->{$XML_NS}->{space};
200     $AttrChecker->{''}->{'xml:lang'} = $AttrChecker->{$XML_NS}->{lang};
201 wakaba 1.89 ## NOTE: Checker for (null, "xml:lang") attribute is shadowed for
202     ## HTML elements in Whatpm::ContentChecker::HTML.
203 wakaba 1.13 $AttrChecker->{''}->{'xml:base'} = $AttrChecker->{$XML_NS}->{base};
204     $AttrChecker->{''}->{'xml:id'} = $AttrChecker->{$XML_NS}->{id};
205    
206 wakaba 1.79 our $AttrStatus;
207    
208     for (qw/space lang base id/) {
209     $AttrStatus->{$XML_NS}->{$_} = FEATURE_STATUS_REC | FEATURE_ALLOWED;
210     $AttrStatus->{''}->{"xml:$_"} = FEATURE_STATUS_REC | FEATURE_ALLOWED;
211     ## XML 1.0: FEATURE_STATUS_CR
212     ## XML 1.1: FEATURE_STATUS_REC
213     ## XML Namespaces 1.0: FEATURE_STATUS_CR
214     ## XML Namespaces 1.1: FEATURE_STATUS_REC
215     ## XML Base: FEATURE_STATUS_REC
216     ## xml:id: FEATURE_STATUS_REC
217     }
218    
219     $AttrStatus->{$XMLNS_NS}->{''} = FEATURE_STATUS_REC | FEATURE_ALLOWED;
220    
221     ## TODO: xsi:schemaLocation for XHTML2 support (very, very low priority)
222    
223 wakaba 1.60 our %AnyChecker = (
224 wakaba 1.99 ## NOTE: |check_start| is invoked before anything on the element's
225     ## attributes and contents is checked.
226 wakaba 1.60 check_start => sub { },
227 wakaba 1.99 ## NOTE: |check_attrs| is invoked after |check_start| and before
228     ## anything on the element's contents is checked.
229 wakaba 1.60 check_attrs => sub {
230     my ($self, $item, $element_state) = @_;
231     for my $attr (@{$item->{node}->attributes}) {
232 wakaba 1.9 my $attr_ns = $attr->namespace_uri;
233 wakaba 1.92 if (defined $attr_ns) {
234     load_ns_module ($attr_ns);
235     } else {
236     $attr_ns = '';
237     }
238 wakaba 1.9 my $attr_ln = $attr->manakai_local_name;
239 wakaba 1.79
240 wakaba 1.9 my $checker = $AttrChecker->{$attr_ns}->{$attr_ln}
241 wakaba 1.60 || $AttrChecker->{$attr_ns}->{''};
242 wakaba 1.79 my $status = $AttrStatus->{$attr_ns}->{$attr_ln}
243     || $AttrStatus->{$attr_ns}->{''};
244     if (not defined $status) {
245     $status = FEATURE_ALLOWED;
246     ## NOTE: FEATURE_ALLOWED for all attributes, since the element
247     ## is not supported and therefore "attribute not defined" error
248     ## should not raised (too verbose) and global attributes should be
249     ## allowed anyway (if a global attribute has its specified creteria
250     ## for where it may be specified, then it should be checked in it's
251     ## checker function).
252     }
253 wakaba 1.9 if ($checker) {
254     $checker->($self, $attr);
255 wakaba 1.17 } else {
256 wakaba 1.83 $self->{onerror}->(node => $attr,
257     type => 'unknown attribute',
258     level => $self->{level}->{uncertain});
259 wakaba 1.9 }
260 wakaba 1.79 $self->_attr_status_info ($attr, $status);
261 wakaba 1.9 }
262     },
263 wakaba 1.99 ## NOTE: |check_child_element| is invoked for each occurence of
264     ## child elements. It is invoked after |check_attrs| and before
265     ## |check_end|. |check_child_element| and |check_child_text| are
266     ## invoked for each child elements and text nodes in tree order.
267 wakaba 1.60 check_child_element => sub {
268     my ($self, $item, $child_el, $child_nsuri, $child_ln,
269     $child_is_transparent, $element_state) = @_;
270     if ($self->{minus_elements}->{$child_nsuri}->{$child_ln}) {
271     $self->{onerror}->(node => $child_el,
272     type => 'element not allowed:minus',
273 wakaba 1.83 level => $self->{level}->{must});
274 wakaba 1.60 } elsif ($self->{plus_elements}->{$child_nsuri}->{$child_ln}) {
275     #
276     } else {
277     #
278     }
279     },
280 wakaba 1.99 ## NOTE: |check_child_text| is invoked for each occurence of child
281     ## text nodes. It is invoked after |check_attrs| and before
282     ## |check_end|. |check_child_element| and |check_child_text| are
283     ## invoked for each child elements and text nodes in tree order.
284 wakaba 1.60 check_child_text => sub { },
285 wakaba 1.99 ## NOTE: |check_end| is invoked after everything on the element's
286     ## attributes and contents are checked.
287 wakaba 1.60 check_end => sub {
288     my ($self, $item, $element_state) = @_;
289 wakaba 1.82 ## NOTE: There is a modified copy of the code below for |html:ruby|.
290 wakaba 1.60 if ($element_state->{has_significant}) {
291 wakaba 1.66 $item->{real_parent_state}->{has_significant} = 1;
292 wakaba 1.60 }
293     },
294     );
295    
296     our $ElementDefault = {
297     %AnyChecker,
298 wakaba 1.70 status => FEATURE_ALLOWED,
299     ## NOTE: No "element not defined" error - it is not supported anyway.
300 wakaba 1.60 check_start => sub {
301     my ($self, $item, $element_state) = @_;
302 wakaba 1.83 $self->{onerror}->(node => $item->{node},
303     type => 'unknown element',
304     level => $self->{level}->{uncertain});
305 wakaba 1.60 },
306 wakaba 1.1 };
307    
308 wakaba 1.60 our $HTMLEmbeddedContent = {
309     ## NOTE: All embedded content is also phrasing content.
310     $HTML_NS => {
311     img => 1, iframe => 1, embed => 1, object => 1, video => 1, audio => 1,
312     canvas => 1,
313     },
314     q<http://www.w3.org/1998/Math/MathML> => {math => 1},
315     q<http://www.w3.org/2000/svg> => {svg => 1},
316     ## NOTE: Foreign elements with content (but no metadata) are
317     ## embedded content.
318     };
319    
320 wakaba 1.95 our $IsInHTMLInteractiveContent = sub {
321     my ($el, $nsuri, $ln) = @_;
322    
323     ## NOTE: This CODE returns whether an element that is conditionally
324     ## categorizzed as an interactive content is currently in that
325     ## condition or not. See $HTMLInteractiveContent list defined in
326     ## Whatpm::ContentChecler::HTML for the list of all (conditionally
327     ## or permanently) interactive content.
328    
329     if ($nsuri eq $HTML_NS and ($ln eq 'video' or $ln eq 'audio')) {
330 wakaba 1.103 return $el->has_attribute_ns (undef, 'controls');
331 wakaba 1.95 } elsif ($nsuri eq $HTML_NS and $ln eq 'menu') {
332 wakaba 1.103 my $value = $el->get_attribute_ns (undef, 'type');
333 wakaba 1.95 $value =~ tr/A-Z/a-z/; # ASCII case-insensitive
334     return ($value eq 'toolbar');
335     } else {
336     return 1;
337     }
338     }; # $IsInHTMLInteractiveContent
339    
340 wakaba 1.7 my $HTMLTransparentElements = {
341 wakaba 1.90 $HTML_NS => {qw/ins 1 del 1 font 1 noscript 1 canvas 1 a 1/},
342 wakaba 1.29 ## NOTE: |html:noscript| is transparent if scripting is disabled
343     ## and not in |head|.
344 wakaba 1.7 };
345    
346 wakaba 1.61 my $HTMLSemiTransparentElements = {
347     $HTML_NS => {object => 1, video => 1, audio => 1},
348     };
349 wakaba 1.57
350 wakaba 1.42 our $Element = {};
351 wakaba 1.7
352 wakaba 1.73 $Element->{q<http://www.w3.org/1999/02/22-rdf-syntax-ns#>}->{RDF} = {
353     %AnyChecker,
354     status => FEATURE_STATUS_REC | FEATURE_ALLOWED,
355     is_root => 1, ## ISSUE: Not explicitly allowed for non application/rdf+xml
356     check_start => sub {
357     my ($self, $item, $element_state) = @_;
358     my $triple = [];
359     push @{$self->{return}->{rdf}}, [$item->{node}, $triple];
360     require Whatpm::RDFXML;
361     my $rdf = Whatpm::RDFXML->new;
362 wakaba 1.75 ## TODO: Should we make bnodeid unique in a document?
363 wakaba 1.73 $rdf->{onerror} = $self->{onerror};
364 wakaba 1.84 $rdf->{level} = $self->{level};
365 wakaba 1.73 $rdf->{ontriple} = sub {
366     my %opt = @_;
367     push @$triple,
368     [$opt{node}, $opt{subject}, $opt{predicate}, $opt{object}];
369 wakaba 1.74 if (defined $opt{id}) {
370     push @$triple,
371     [$opt{node},
372     $opt{id},
373     {uri => q<http://www.w3.org/1999/02/22-rdf-syntax-ns#subject>},
374     $opt{subject}];
375     push @$triple,
376     [$opt{node},
377     $opt{id},
378     {uri => q<http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate>},
379     $opt{predicate}];
380     push @$triple,
381     [$opt{node},
382     $opt{id},
383     {uri => q<http://www.w3.org/1999/02/22-rdf-syntax-ns#object>},
384     $opt{object}];
385     push @$triple,
386     [$opt{node},
387     $opt{id},
388     {uri => q<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>},
389     {uri => q<http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement>}];
390     }
391 wakaba 1.73 };
392     $rdf->convert_rdf_element ($item->{node});
393     },
394     };
395    
396 wakaba 1.83 my $default_error_level = {
397     must => 'm',
398     should => 's',
399     warn => 'w',
400     good => 'w',
401 wakaba 1.93 undefined => 'w',
402 wakaba 1.83 info => 'i',
403 wakaba 1.85
404 wakaba 1.83 uncertain => 'u',
405    
406 wakaba 1.84 html4_fact => 'm',
407 wakaba 1.89 html5_no_may => 'm',
408 wakaba 1.101 html5_fact => 'm',
409 wakaba 1.89
410 wakaba 1.83 xml_error => 'm', ## TODO: correct?
411 wakaba 1.88 xml_id_error => 'm', ## TODO: ?
412 wakaba 1.83 nc => 'm', ## XML Namespace Constraints ## TODO: correct?
413 wakaba 1.84
414 wakaba 1.91 ## |Whatpm::URIChecker|
415 wakaba 1.85 uri_syntax => 'm',
416     uri_fact => 'm',
417     uri_lc_must => 'm',
418     uri_lc_should => 'w',
419    
420 wakaba 1.91 ## |Whatpm::IMTChecker|
421 wakaba 1.87 mime_must => 'm', # lowercase "must"
422     mime_fact => 'm',
423     mime_strongly_discouraged => 'w',
424     mime_discouraged => 'w',
425    
426 wakaba 1.91 ## |Whatpm::LangTag|
427 wakaba 1.85 langtag_fact => 'm',
428    
429 wakaba 1.91 ## |Whatpm::RDFXML|
430 wakaba 1.84 rdf_fact => 'm',
431     rdf_grammer => 'm',
432     rdf_lc_must => 'm',
433 wakaba 1.91
434     ## |Message::Charset::Info| and |Whatpm::Charset::DecodeHandle|
435     charset_variant => 'm',
436     ## An error caused by use of a variant charset that is not conforming
437     ## to the original charset (e.g. use of 0x80 in an ISO-8859-1 document
438     ## which is interpreted as a Windows-1252 document instead).
439     charset_fact => 'm',
440     iso_shall => 'm',
441 wakaba 1.83 };
442    
443 wakaba 1.56 sub check_document ($$$;$) {
444     my ($self, $doc, $onerror, $onsubdoc) = @_;
445 wakaba 1.42 $self = bless {}, $self unless ref $self;
446     $self->{onerror} = $onerror;
447 wakaba 1.56 $self->{onsubdoc} = $onsubdoc || sub {
448     warn "A subdocument is not conformance-checked";
449     };
450 wakaba 1.1
451 wakaba 1.83 $self->{level} ||= $default_error_level;
452 wakaba 1.48
453 wakaba 1.73 ## TODO: If application/rdf+xml, RDF/XML mode should be invoked.
454    
455 wakaba 1.42 my $docel = $doc->document_element;
456     unless (defined $docel) {
457     ## ISSUE: Should we check content of Document node?
458 wakaba 1.83 $onerror->(node => $doc, type => 'no document element',
459     level => $self->{level}->{must});
460 wakaba 1.42 ## ISSUE: Is this non-conforming (to what spec)? Or just a warning?
461     return {
462     class => {},
463     id => {}, table => [], term => {},
464     };
465 wakaba 1.1 }
466    
467 wakaba 1.42 ## ISSUE: Unexpanded entity references and HTML5 conformance
468 wakaba 1.1
469 wakaba 1.42 my $docel_nsuri = $docel->namespace_uri;
470 wakaba 1.92 if (defined $docel_nsuri) {
471     load_ns_module ($docel_nsuri);
472     } else {
473     $docel_nsuri = '';
474     }
475 wakaba 1.42 my $docel_def = $Element->{$docel_nsuri}->{$docel->manakai_local_name} ||
476     $Element->{$docel_nsuri}->{''} ||
477     $ElementDefault;
478     if ($docel_def->{is_root}) {
479     #
480 wakaba 1.50 } elsif ($docel_def->{is_xml_root}) {
481     unless ($doc->manakai_is_html) {
482     #
483     } else {
484 wakaba 1.83 $onerror->(node => $docel, type => 'element not allowed:root:xml',
485     level => $self->{level}->{must});
486 wakaba 1.50 }
487 wakaba 1.42 } else {
488 wakaba 1.83 $onerror->(node => $docel, type => 'element not allowed:root',
489     level => $self->{level}->{must});
490 wakaba 1.1 }
491    
492 wakaba 1.42 ## TODO: Check for other items other than document element
493     ## (second (errorous) element, text nodes, PI nodes, doctype nodes)
494 wakaba 1.2
495 wakaba 1.56 my $return = $self->check_element ($docel, $onerror, $onsubdoc);
496 wakaba 1.51
497 wakaba 1.52 ## TODO: Test for these checks are necessary.
498 wakaba 1.51 my $charset_name = $doc->input_encoding;
499     if (defined $charset_name) {
500     require Message::Charset::Info;
501     my $charset = $Message::Charset::Info::IANACharset->{$charset_name};
502    
503 wakaba 1.71 if ($doc->manakai_is_html) {
504     if (not $doc->manakai_has_bom and
505     not defined $doc->manakai_charset) {
506 wakaba 1.102 unless ($charset->{category}
507     & Message::Charset::Info::CHARSET_CATEGORY_ASCII_COMPAT ()) {
508 wakaba 1.86 $onerror->(node => $doc,
509     level => $self->{level}->{must},
510 wakaba 1.83 type => 'non ascii superset',
511     text => $charset_name);
512 wakaba 1.71 }
513    
514     if (not $self->{has_charset} and ## TODO: This does not work now.
515     not $charset->{iana_names}->{'us-ascii'}) {
516 wakaba 1.86 $onerror->(node => $doc,
517     level => $self->{level}->{must},
518 wakaba 1.83 type => 'no character encoding declaration',
519     text => $charset_name);
520 wakaba 1.71 }
521 wakaba 1.51 }
522 wakaba 1.71
523     if ($charset->{iana_names}->{'utf-8'}) {
524     #
525     } elsif ($charset->{iana_names}->{'jis_x0212-1990'} or
526     $charset->{iana_names}->{'x-jis0208'} or
527     $charset->{iana_names}->{'utf-32'} or ## ISSUE: UTF-32BE? UTF-32LE?
528 wakaba 1.91 ($charset->{category} & Message::Charset::Info::CHARSET_CATEGORY_EBCDIC ())) {
529 wakaba 1.71 $onerror->(node => $doc,
530 wakaba 1.83 type => 'bad character encoding',
531     text => $charset_name,
532     level => $self->{level}->{should},
533     layer => 'encode');
534 wakaba 1.71 } elsif ($charset->{iana_names}->{'cesu-8'} or
535 wakaba 1.102 $charset->{iana_names}->{'utf-7'} or ## ISSUE: UNICODE-1-1-UTF-7?
536 wakaba 1.71 $charset->{iana_names}->{'bocu-1'} or
537     $charset->{iana_names}->{'scsu'}) {
538     $onerror->(node => $doc,
539 wakaba 1.83 type => 'disallowed character encoding',
540     text => $charset_name,
541     level => $self->{level}->{must},
542     layer => 'encode');
543 wakaba 1.71 } else {
544     $onerror->(node => $doc,
545 wakaba 1.83 type => 'non-utf-8 character encoding',
546     text => $charset_name,
547     level => $self->{level}->{good},
548     layer => 'encode');
549 wakaba 1.51 }
550     }
551 wakaba 1.52 } elsif ($doc->manakai_is_html) {
552     ## NOTE: MUST and SHOULD requirements above cannot be tested,
553     ## since the document has no input charset encoding information.
554     $onerror->(node => $doc,
555 wakaba 1.83 type => 'character encoding unchecked',
556     level => $self->{level}->{info},
557     layer => 'encode');
558 wakaba 1.51 }
559    
560     return $return;
561 wakaba 1.42 } # check_document
562 wakaba 1.1
563 wakaba 1.81 ## Check an element. The element is checked as if it is an orphan node (i.e.
564     ## an element without a parent node).
565 wakaba 1.56 sub check_element ($$$;$) {
566     my ($self, $el, $onerror, $onsubdoc) = @_;
567 wakaba 1.42 $self = bless {}, $self unless ref $self;
568     $self->{onerror} = $onerror;
569 wakaba 1.56 $self->{onsubdoc} = $onsubdoc || sub {
570     warn "A subdocument is not conformance-checked";
571     };
572 wakaba 1.2
573 wakaba 1.83 $self->{level} ||= $default_error_level;
574 wakaba 1.48
575 wakaba 1.61 $self->{plus_elements} = {};
576     $self->{minus_elements} = {};
577 wakaba 1.42 $self->{id} = {};
578 wakaba 1.99 $self->{id_type} = {}; # 'form' / 'labelable' / 'menu'
579     $self->{form} = {}; # form/@name
580 wakaba 1.100 $self->{idref} = []; # @form, @for, @contextmenu
581 wakaba 1.42 $self->{term} = {};
582     $self->{usemap} = [];
583 wakaba 1.78 $self->{ref} = []; # datetemplate data references
584     $self->{template} = []; # datatemplate template references
585 wakaba 1.42 $self->{map} = {};
586     $self->{has_link_type} = {};
587 wakaba 1.60 $self->{flag} = {};
588 wakaba 1.46 #$self->{has_uri_attr};
589     #$self->{has_hyperlink_element};
590 wakaba 1.51 #$self->{has_charset};
591 wakaba 1.57 #$self->{has_base};
592 wakaba 1.42 $self->{return} = {
593     class => {},
594 wakaba 1.80 id => $self->{id},
595     table => [], # table objects returned by Whatpm::HTMLTable
596     term => $self->{term},
597 wakaba 1.76 uri => {}, # URIs other than those in RDF triples
598     ## TODO: xmlns="", SYSTEM "", atom:* src="", xml:base=""
599 wakaba 1.73 rdf => [],
600 wakaba 1.42 };
601 wakaba 1.4
602 wakaba 1.60 my @item = ({type => 'element', node => $el, parent_state => {}});
603 wakaba 1.66 $item[-1]->{real_parent_state} = $item[-1]->{parent_state};
604 wakaba 1.60 while (@item) {
605     my $item = shift @item;
606     if (ref $item eq 'ARRAY') {
607     my $code = shift @$item;
608     next unless $code;## TODO: temp.
609     $code->(@$item);
610     } elsif ($item->{type} eq 'element') {
611     my $el_nsuri = $item->{node}->namespace_uri;
612 wakaba 1.92 if (defined $el_nsuri) {
613     load_ns_module ($el_nsuri);
614     } else {
615     $el_nsuri = '';
616     }
617 wakaba 1.60 my $el_ln = $item->{node}->manakai_local_name;
618 wakaba 1.92
619 wakaba 1.63 my $element_state = {};
620 wakaba 1.60 my $eldef = $Element->{$el_nsuri}->{$el_ln} ||
621     $Element->{$el_nsuri}->{''} ||
622 wakaba 1.42 $ElementDefault;
623 wakaba 1.61 my $content_def = $item->{transparent}
624     ? $item->{parent_def} || $eldef : $eldef;
625 wakaba 1.63 my $content_state = $item->{transparent}
626 wakaba 1.65 ? $item->{parent_def}
627     ? $item->{parent_state} || $element_state : $element_state
628     : $element_state;
629 wakaba 1.60
630 wakaba 1.67 unless ($eldef->{status} & FEATURE_STATUS_REC) {
631     my $status = $eldef->{status} & FEATURE_STATUS_CR ? 'cr' :
632     $eldef->{status} & FEATURE_STATUS_LC ? 'lc' :
633     $eldef->{status} & FEATURE_STATUS_WD ? 'wd' : 'non-standard';
634     $self->{onerror}->(node => $item->{node},
635     type => 'status:'.$status.':element',
636 wakaba 1.83 level => $self->{level}->{info});
637 wakaba 1.67 }
638 wakaba 1.70 if (not ($eldef->{status} & FEATURE_ALLOWED)) {
639     $self->{onerror}->(node => $item->{node},
640     type => 'element not defined',
641 wakaba 1.83 level => $self->{level}->{must});
642 wakaba 1.70 } elsif ($eldef->{status} & FEATURE_DEPRECATED_SHOULD) {
643     $self->{onerror}->(node => $item->{node},
644     type => 'deprecated:element',
645 wakaba 1.83 level => $self->{level}->{should});
646 wakaba 1.70 } elsif ($eldef->{status} & FEATURE_DEPRECATED_INFO) {
647     $self->{onerror}->(node => $item->{node},
648     type => 'deprecated:element',
649 wakaba 1.83 level => $self->{level}->{info});
650 wakaba 1.70 }
651 wakaba 1.67
652 wakaba 1.60 my @new_item;
653     push @new_item, [$eldef->{check_start}, $self, $item, $element_state];
654     push @new_item, [$eldef->{check_attrs}, $self, $item, $element_state];
655 wakaba 1.61
656 wakaba 1.60 my @child = @{$item->{node}->child_nodes};
657     while (@child) {
658     my $child = shift @child;
659     my $child_nt = $child->node_type;
660     if ($child_nt == 1) { # ELEMENT_NODE
661     my $child_nsuri = $child->namespace_uri;
662     $child_nsuri = '' unless defined $child_nsuri;
663     my $child_ln = $child->manakai_local_name;
664     if ($HTMLTransparentElements->{$child_nsuri}->{$child_ln} and
665     not (($self->{flag}->{in_head} or
666 wakaba 1.61 ($el_nsuri eq $HTML_NS and $el_ln eq 'head')) and
667     $child_nsuri eq $HTML_NS and $child_ln eq 'noscript')) {
668 wakaba 1.60 push @new_item, [$content_def->{check_child_element},
669     $self, $item, $child,
670 wakaba 1.66 $child_nsuri, $child_ln, 1,
671     $content_state, $element_state];
672 wakaba 1.60 push @new_item, {type => 'element', node => $child,
673 wakaba 1.65 parent_state => $content_state,
674 wakaba 1.61 parent_def => $content_def,
675 wakaba 1.66 real_parent_state => $element_state,
676 wakaba 1.60 transparent => 1};
677     } else {
678 wakaba 1.65 if ($item->{parent_def} and # has parent
679     $el_nsuri eq $HTML_NS) { ## $HTMLSemiTransparentElements
680 wakaba 1.61 if ($el_ln eq 'object') {
681     if ($self->{plus_elements}->{$child_nsuri}->{$child_ln}) {
682     #
683     } elsif ($child_nsuri eq $HTML_NS and $child_ln eq 'param') {
684     #
685     } else {
686 wakaba 1.62 $content_def = $item->{parent_def} || $content_def;
687 wakaba 1.63 $content_state = $item->{parent_state} || $content_state;
688 wakaba 1.62 }
689     } elsif ($el_ln eq 'video' or $el_ln eq 'audio') {
690     if ($self->{plus_elements}->{$child_nsuri}->{$child_ln}) {
691     #
692     } elsif ($child_nsuri eq $HTML_NS and $child_ln eq 'source') {
693     $element_state->{has_source} = 1;
694     } else {
695     $content_def = $item->{parent_def} || $content_def;
696 wakaba 1.63 $content_state = $item->{parent_state} || $content_state;
697 wakaba 1.61 }
698     }
699     }
700    
701 wakaba 1.60 push @new_item, [$content_def->{check_child_element},
702     $self, $item, $child,
703 wakaba 1.64 $child_nsuri, $child_ln,
704     $HTMLSemiTransparentElements
705     ->{$child_nsuri}->{$child_ln},
706 wakaba 1.66 $content_state, $element_state];
707 wakaba 1.60 push @new_item, {type => 'element', node => $child,
708 wakaba 1.65 parent_def => $content_def,
709 wakaba 1.66 real_parent_state => $element_state,
710 wakaba 1.65 parent_state => $content_state};
711 wakaba 1.60 }
712    
713     if ($HTMLEmbeddedContent->{$child_nsuri}->{$child_ln}) {
714     $element_state->{has_significant} = 1;
715     }
716     } elsif ($child_nt == 3 or # TEXT_NODE
717     $child_nt == 4) { # CDATA_SECTION_NODE
718 wakaba 1.96 my $has_significant = ($child->data =~ /[^\x09\x0A\x0C\x0D\x20]/);
719 wakaba 1.60 push @new_item, [$content_def->{check_child_text},
720     $self, $item, $child, $has_significant,
721 wakaba 1.66 $content_state, $element_state];
722     $element_state->{has_significant} ||= $has_significant;
723 wakaba 1.61 if ($has_significant and
724     $HTMLSemiTransparentElements->{$el_nsuri}->{$el_ln}) {
725     $content_def = $item->{parent_def} || $content_def;
726     }
727 wakaba 1.60 } elsif ($child_nt == 5) { # ENTITY_REFERENCE_NODE
728     push @child, @{$child->child_nodes};
729 wakaba 1.1 }
730 wakaba 1.60 ## TODO: PI_NODE
731     ## TODO: Unknown node type
732 wakaba 1.1 }
733 wakaba 1.60
734     push @new_item, [$eldef->{check_end}, $self, $item, $element_state];
735    
736     unshift @item, @new_item;
737 wakaba 1.30 } else {
738 wakaba 1.60 die "$0: Internal error: Unsupported checking action type |$item->{type}|";
739 wakaba 1.4 }
740 wakaba 1.1 }
741 wakaba 1.17
742 wakaba 1.78 for (@{$self->{template}}) {
743     ## TODO: If the document is an XML document, ...
744     ## NOTE: If the document is an HTML document:
745     ## ISSUE: We need to percent-decode?
746     F: {
747     if ($self->{id}->{$_->[0]}) {
748     my $el = $self->{id}->{$_->[0]}->[0]->owner_element;
749     if ($el->node_type == 1 and # ELEMENT_NODE
750     $el->manakai_local_name eq 'datatemplate') {
751     my $nsuri = $el->namespace_uri;
752     if (defined $nsuri and $nsuri eq $HTML_NS) {
753     if ($el eq $_->[1]->owner_element) {
754     $self->{onerror}->(node => $_->[1],
755     type => 'fragment points itself',
756 wakaba 1.83 level => $self->{level}->{must});
757 wakaba 1.78 }
758    
759     last F;
760     }
761     }
762     }
763     ## TODO: Should we raise a "fragment points nothing" error instead
764     ## if the fragment identifier identifies no element?
765    
766     $self->{onerror}->(node => $_->[1], type => 'template:not template',
767 wakaba 1.83 level => $self->{level}->{must});
768 wakaba 1.78 } # F
769     }
770    
771     for (@{$self->{ref}}) {
772     ## TOOD: If XML
773     ## NOTE: If it is an HTML document:
774     if ($_->[0] eq '') {
775     ## NOTE: It points the top of the document.
776     } elsif ($self->{id}->{$_->[0]}) {
777     if ($self->{id}->{$_->[0]}->[0]->owner_element
778     eq $_->[1]->owner_element) {
779     $self->{onerror}->(node => $_->[1], type => 'fragment points itself',
780 wakaba 1.83 level => $self->{level}->{must});
781 wakaba 1.78 }
782     } else {
783     $self->{onerror}->(node => $_->[1], type => 'fragment points nothing',
784 wakaba 1.83 level => $self->{level}->{must});
785 wakaba 1.78 }
786     }
787    
788     ## TODO: Maybe we should have $document->manakai_get_by_fragment or something
789    
790 wakaba 1.17 for (@{$self->{usemap}}) {
791     unless ($self->{map}->{$_->[0]}) {
792 wakaba 1.83 $self->{onerror}->(node => $_->[1], type => 'no referenced map',
793     level => $self->{level}->{must});
794 wakaba 1.17 }
795     }
796    
797 wakaba 1.100 for (@{$self->{idref}}) {
798     if ($self->{id}->{$_->[1]} and
799     $self->{id_type}->{$_->[1]} eq $_->[0]) {
800 wakaba 1.99 #
801     } else {
802 wakaba 1.100 $self->{onerror}->(node => $_->[2],
803     type => {
804     form => 'no referenced form',
805     labelable => 'no referenced control',
806     menu => 'no referenced menu',
807     }->{$_->[0]},
808 wakaba 1.83 level => $self->{level}->{must});
809 wakaba 1.32 }
810     }
811    
812 wakaba 1.61 delete $self->{plus_elements};
813     delete $self->{minus_elements};
814 wakaba 1.17 delete $self->{onerror};
815     delete $self->{id};
816 wakaba 1.98 delete $self->{id_type};
817 wakaba 1.97 delete $self->{form};
818 wakaba 1.100 delete $self->{idref};
819 wakaba 1.17 delete $self->{usemap};
820 wakaba 1.78 delete $self->{ref};
821     delete $self->{template};
822 wakaba 1.17 delete $self->{map};
823 wakaba 1.33 return $self->{return};
824 wakaba 1.1 } # check_element
825    
826 wakaba 1.60 sub _add_minus_elements ($$@) {
827     my $self = shift;
828     my $element_state = shift;
829     for my $elements (@_) {
830     for my $nsuri (keys %$elements) {
831     for my $ln (keys %{$elements->{$nsuri}}) {
832     unless ($self->{minus_elements}->{$nsuri}->{$ln}) {
833     $element_state->{minus_elements_original}->{$nsuri}->{$ln} = 0;
834     $self->{minus_elements}->{$nsuri}->{$ln} = 1;
835     }
836     }
837     }
838     }
839     } # _add_minus_elements
840    
841     sub _remove_minus_elements ($$) {
842     my $self = shift;
843     my $element_state = shift;
844     for my $nsuri (keys %{$element_state->{minus_elements_original}}) {
845     for my $ln (keys %{$element_state->{minus_elements_original}->{$nsuri}}) {
846     delete $self->{minus_elements}->{$nsuri}->{$ln};
847     }
848     }
849     } # _remove_minus_elements
850    
851     sub _add_plus_elements ($$@) {
852     my $self = shift;
853     my $element_state = shift;
854     for my $elements (@_) {
855     for my $nsuri (keys %$elements) {
856     for my $ln (keys %{$elements->{$nsuri}}) {
857     unless ($self->{plus_elements}->{$nsuri}->{$ln}) {
858     $element_state->{plus_elements_original}->{$nsuri}->{$ln} = 0;
859     $self->{plus_elements}->{$nsuri}->{$ln} = 1;
860     }
861     }
862     }
863     }
864     } # _add_plus_elements
865    
866     sub _remove_plus_elements ($$) {
867     my $self = shift;
868     my $element_state = shift;
869     for my $nsuri (keys %{$element_state->{plus_elements_original}}) {
870     for my $ln (keys %{$element_state->{plus_elements_original}->{$nsuri}}) {
871     delete $self->{plus_elements}->{$nsuri}->{$ln};
872     }
873     }
874     } # _remove_plus_elements
875    
876 wakaba 1.68 sub _attr_status_info ($$$) {
877     my ($self, $attr, $status_code) = @_;
878 wakaba 1.70
879     if (not ($status_code & FEATURE_ALLOWED)) {
880     $self->{onerror}->(node => $attr,
881     type => 'attribute not defined',
882 wakaba 1.83 level => $self->{level}->{must});
883 wakaba 1.70 } elsif ($status_code & FEATURE_DEPRECATED_SHOULD) {
884     $self->{onerror}->(node => $attr,
885     type => 'deprecated:attr',
886 wakaba 1.83 level => $self->{level}->{should});
887 wakaba 1.70 } elsif ($status_code & FEATURE_DEPRECATED_INFO) {
888     $self->{onerror}->(node => $attr,
889     type => 'deprecated:attr',
890 wakaba 1.83 level => $self->{level}->{info});
891 wakaba 1.70 }
892    
893 wakaba 1.68 my $status;
894     if ($status_code & FEATURE_STATUS_REC) {
895     return;
896     } elsif ($status_code & FEATURE_STATUS_CR) {
897     $status = 'cr';
898     } elsif ($status_code & FEATURE_STATUS_LC) {
899     $status = 'lc';
900     } elsif ($status_code & FEATURE_STATUS_WD) {
901     $status = 'wd';
902     } else {
903     $status = 'non-standard';
904     }
905     $self->{onerror}->(node => $attr,
906     type => 'status:'.$status.':attr',
907 wakaba 1.83 level => $self->{level}->{info});
908 wakaba 1.68 } # _attr_status_info
909    
910 wakaba 1.2 sub _add_minuses ($@) {
911     my $self = shift;
912     my $r = {};
913     for my $list (@_) {
914     for my $ns (keys %$list) {
915     for my $ln (keys %{$list->{$ns}}) {
916     unless ($self->{minuses}->{$ns}->{$ln}) {
917     $self->{minuses}->{$ns}->{$ln} = 1;
918     $r->{$ns}->{$ln} = 1;
919     }
920     }
921     }
922     }
923 wakaba 1.4 return {type => 'plus', list => $r};
924 wakaba 1.2 } # _add_minuses
925    
926 wakaba 1.50 sub _add_pluses ($@) {
927     my $self = shift;
928     my $r = {};
929     for my $list (@_) {
930     for my $ns (keys %$list) {
931     for my $ln (keys %{$list->{$ns}}) {
932     unless ($self->{pluses}->{$ns}->{$ln}) {
933     $self->{pluses}->{$ns}->{$ln} = 1;
934     $r->{$ns}->{$ln} = 1;
935     }
936     }
937     }
938     }
939     return {type => 'minus', list => $r};
940     } # _add_pluses
941    
942 wakaba 1.2 sub _remove_minuses ($$) {
943 wakaba 1.4 my ($self, $todo) = @_;
944 wakaba 1.50 if ($todo->{type} eq 'minus') {
945     for my $ns (keys %{$todo->{list}}) {
946     for my $ln (keys %{$todo->{list}->{$ns}}) {
947     delete $self->{pluses}->{$ns}->{$ln} if $todo->{list}->{$ns}->{$ln};
948     }
949 wakaba 1.2 }
950 wakaba 1.50 } elsif ($todo->{type} eq 'plus') {
951     for my $ns (keys %{$todo->{list}}) {
952     for my $ln (keys %{$todo->{list}->{$ns}}) {
953     delete $self->{minuses}->{$ns}->{$ln} if $todo->{list}->{$ns}->{$ln};
954     }
955     }
956     } else {
957     die "$0: Unknown +- type: $todo->{type}";
958 wakaba 1.2 }
959     1;
960     } # _remove_minuses
961    
962 wakaba 1.50 ## NOTE: Priority for "minuses" and "pluses" are currently left
963     ## undefined and implemented inconsistently; it is not a problem for
964     ## now, since no element belongs to both lists.
965    
966 wakaba 1.30 sub _check_get_children ($$$) {
967     my ($self, $node, $parent_todo) = @_;
968 wakaba 1.4 my $new_todos = [];
969 wakaba 1.2 my $sib = [];
970     TP: {
971     my $node_ns = $node->namespace_uri;
972     $node_ns = '' unless defined $node_ns;
973     my $node_ln = $node->manakai_local_name;
974 wakaba 1.45 if ($HTMLTransparentElements->{$node_ns}->{$node_ln}) {
975     if ($node_ns eq $HTML_NS and $node_ln eq 'noscript') {
976     if ($parent_todo->{flag}->{in_head}) {
977     #
978     } else {
979     my $end = $self->_add_minuses ({$HTML_NS, {noscript => 1}});
980     push @$sib, $end;
981    
982     unshift @$sib, @{$node->child_nodes};
983     push @$new_todos, {type => 'element-attributes', node => $node};
984     last TP;
985     }
986 wakaba 1.58 } elsif ($node_ns eq $HTML_NS and $node_ln eq 'del') {
987     my $sig_flag = $parent_todo->{flag}->{has_descendant}->{significant};
988     unshift @$sib, @{$node->child_nodes};
989     push @$new_todos, {type => 'element-attributes', node => $node};
990     push @$new_todos,
991     {type => 'code',
992     code => sub {
993     $parent_todo->{flag}->{has_descendant}->{significant} = 0
994     if not $sig_flag;
995     }};
996     last TP;
997 wakaba 1.45 } else {
998     unshift @$sib, @{$node->child_nodes};
999     push @$new_todos, {type => 'element-attributes', node => $node};
1000     last TP;
1001 wakaba 1.2 }
1002     }
1003 wakaba 1.8 if ($node_ns eq $HTML_NS and ($node_ln eq 'video' or $node_ln eq 'audio')) {
1004 wakaba 1.2 if ($node->has_attribute_ns (undef, 'src')) {
1005     unshift @$sib, @{$node->child_nodes};
1006 wakaba 1.9 push @$new_todos, {type => 'element-attributes', node => $node};
1007 wakaba 1.2 last TP;
1008     } else {
1009     my @cn = @{$node->child_nodes};
1010     CN: while (@cn) {
1011     my $cn = shift @cn;
1012     my $cnt = $cn->node_type;
1013     if ($cnt == 1) {
1014 wakaba 1.8 my $cn_nsuri = $cn->namespace_uri;
1015     $cn_nsuri = '' unless defined $cn_nsuri;
1016     if ($cn_nsuri eq $HTML_NS and $cn->manakai_local_name eq 'source') {
1017 wakaba 1.2 #
1018     } else {
1019     last CN;
1020     }
1021     } elsif ($cnt == 3 or $cnt == 4) {
1022 wakaba 1.96 if ($cn->data =~ /[^\x09\x0A\x0C\x0D\x20]/) {
1023 wakaba 1.2 last CN;
1024     }
1025     }
1026     } # CN
1027     unshift @$sib, @cn;
1028     }
1029 wakaba 1.57 } elsif ($node_ns eq $HTML_NS and $node_ln eq 'object') {
1030     my @cn = @{$node->child_nodes};
1031     CN: while (@cn) {
1032     my $cn = shift @cn;
1033     my $cnt = $cn->node_type;
1034     if ($cnt == 1) {
1035     my $cn_nsuri = $cn->namespace_uri;
1036     $cn_nsuri = '' unless defined $cn_nsuri;
1037     if ($cn_nsuri eq $HTML_NS and $cn->manakai_local_name eq 'param') {
1038     #
1039     } else {
1040     last CN;
1041     }
1042     } elsif ($cnt == 3 or $cnt == 4) {
1043 wakaba 1.96 if ($cn->data =~ /[^\x09\x0A\x0C\x0D\x20]/) {
1044 wakaba 1.57 last CN;
1045     }
1046     }
1047     } # CN
1048     unshift @$sib, @cn;
1049 wakaba 1.2 }
1050 wakaba 1.4 push @$new_todos, {type => 'element', node => $node};
1051 wakaba 1.2 } # TP
1052 wakaba 1.30
1053     for my $new_todo (@$new_todos) {
1054     $new_todo->{flag} = {%{$parent_todo->{flag} or {}}};
1055     }
1056    
1057 wakaba 1.4 return ($sib, $new_todos);
1058 wakaba 1.2 } # _check_get_children
1059    
1060 wakaba 1.44 =head1 LICENSE
1061    
1062 wakaba 1.56 Copyright 2007-2008 Wakaba <w@suika.fam.cx>
1063 wakaba 1.44
1064     This library is free software; you can redistribute it
1065     and/or modify it under the same terms as Perl itself.
1066    
1067     =cut
1068    
1069 wakaba 1.1 1;
1070 wakaba 1.103 # $Date: 2008/10/27 05:44:47 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24