/[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.107 - (hide annotations) (download)
Sat Dec 13 04:49:04 2008 UTC (15 years, 10 months ago) by wakaba
Branch: MAIN
Changes since 1.106: +4 -2 lines
++ whatpm/t/ChangeLog	13 Dec 2008 04:48:14 -0000
2008-12-13  Wakaba  <wakaba@suika.fam.cx>

	* content-model-7.dat: Added an example from HTML5 spec.

++ whatpm/t/dom-conformance/ChangeLog	13 Dec 2008 04:48:48 -0000
	* html-form-label.dat, html-forms-1.dat: Added test data for
	form="".

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

++ whatpm/Whatpm/ContentChecker/ChangeLog	13 Dec 2008 04:47:22 -0000
	* HTML.pm: Implemented <object form> and <legend form>.

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

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24