/[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.105 - (hide annotations) (download)
Fri Dec 12 11:50:47 2008 UTC (15 years, 10 months ago) by wakaba
Branch: MAIN
Changes since 1.104: +8 -4 lines
++ whatpm/t/dom-conformance/ChangeLog	12 Dec 2008 11:50:40 -0000
	* html-datatemplate.dat, html-form-datalist.dat: Updated test
	results related to |optgroup| elements.

	* html-form-textarea.dat: Added new test data.

	* html-forms-1.dat: Moved some test data to
	|html-form-textarea.dat|.  Updated test results related to
	|optgroup| elements.

2008-12-12  Wakaba  <wakaba@suika.fam.cx>

++ whatpm/Whatpm/ChangeLog	12 Dec 2008 11:48:16 -0000
	* ContentChecker.pm: Introduced |check_attrs2| method for the ease
	of defining codes for checking required attribute and as such.

2008-12-12  Wakaba  <wakaba@suika.fam.cx>

++ whatpm/Whatpm/ContentChecker/ChangeLog	12 Dec 2008 11:48:45 -0000
	* HTML.pm: Updated definitions for |datalist|, |optgroup|,
	|option|, and |textarea| elements.

2008-12-12  Wakaba  <wakaba@suika.fam.cx>

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24