Parent Directory
|
Revision Log
++ ChangeLog 10 Feb 2008 04:07:28 -0000 * cc.cgi: |text/css| support. |id_prefix| support was partially broken. 2008-02-10 Wakaba <wakaba@suika.fam.cx>
| 1 | wakaba | 1.1 | #!/usr/bin/perl |
| 2 | use strict; | ||
| 3 | wakaba | 1.23 | use utf8; |
| 4 | wakaba | 1.1 | |
| 5 | use lib qw[/home/httpd/html/www/markup/html/whatpm | ||
| 6 | wakaba | 1.16 | /home/wakaba/work/manakai2/lib]; |
| 7 | wakaba | 1.1 | use CGI::Carp qw[fatalsToBrowser]; |
| 8 | wakaba | 1.2 | use Scalar::Util qw[refaddr]; |
| 9 | wakaba | 1.16 | use Time::HiRes qw/time/; |
| 10 | wakaba | 1.1 | |
| 11 | wakaba | 1.2 | sub htescape ($) { |
| 12 | my $s = $_[0]; | ||
| 13 | $s =~ s/&/&/g; | ||
| 14 | $s =~ s/</</g; | ||
| 15 | $s =~ s/>/>/g; | ||
| 16 | $s =~ s/"/"/g; | ||
| 17 | wakaba | 1.12 | $s =~ s{([\x00-\x09\x0B-\x1F\x7F-\xA0\x{FEFF}\x{FFFC}-\x{FFFF}])}{ |
| 18 | sprintf '<var>U+%04X</var>', ord $1; | ||
| 19 | }ge; | ||
| 20 | wakaba | 1.2 | return $s; |
| 21 | } # htescape | ||
| 22 | |||
| 23 | wakaba | 1.35 | my @nav; |
| 24 | my %time; | ||
| 25 | require Message::DOM::DOMImplementation; | ||
| 26 | my $dom = Message::DOM::DOMImplementation->new; | ||
| 27 | { | ||
| 28 | wakaba | 1.16 | use Message::CGI::HTTP; |
| 29 | my $http = Message::CGI::HTTP->new; | ||
| 30 | wakaba | 1.1 | |
| 31 | wakaba | 1.16 | if ($http->get_meta_variable ('PATH_INFO') ne '/') { |
| 32 | wakaba | 1.8 | print STDOUT "Status: 404 Not Found\nContent-Type: text/plain; charset=us-ascii\n\n400"; |
| 33 | exit; | ||
| 34 | } | ||
| 35 | |||
| 36 | wakaba | 1.12 | binmode STDOUT, ':utf8'; |
| 37 | wakaba | 1.14 | $| = 1; |
| 38 | wakaba | 1.12 | |
| 39 | wakaba | 1.7 | load_text_catalog ('en'); ## TODO: conneg |
| 40 | |||
| 41 | wakaba | 1.2 | print STDOUT qq[Content-Type: text/html; charset=utf-8 |
| 42 | |||
| 43 | <!DOCTYPE html> | ||
| 44 | <html lang="en"> | ||
| 45 | <head> | ||
| 46 | <title>Web Document Conformance Checker (BETA)</title> | ||
| 47 | wakaba | 1.3 | <link rel="stylesheet" href="../cc-style.css" type="text/css"> |
| 48 | wakaba | 1.2 | </head> |
| 49 | <body> | ||
| 50 | wakaba | 1.13 | <h1><a href="../cc-interface">Web Document Conformance Checker</a> |
| 51 | (<em>beta</em>)</h1> | ||
| 52 | wakaba | 1.14 | ]; |
| 53 | wakaba | 1.2 | |
| 54 | wakaba | 1.14 | $| = 0; |
| 55 | my $input = get_input_document ($http, $dom); | ||
| 56 | wakaba | 1.16 | my $char_length = 0; |
| 57 | wakaba | 1.14 | |
| 58 | print qq[ | ||
| 59 | wakaba | 1.4 | <div id="document-info" class="section"> |
| 60 | wakaba | 1.2 | <dl> |
| 61 | wakaba | 1.9 | <dt>Request URI</dt> |
| 62 | <dd><code class="URI" lang=""><<a href="@{[htescape $input->{request_uri}]}">@{[htescape $input->{request_uri}]}</a>></code></dd> | ||
| 63 | wakaba | 1.2 | <dt>Document URI</dt> |
| 64 | wakaba | 1.25 | <dd><code class="URI" lang=""><<a href="@{[htescape $input->{uri}]}" id=anchor-document-uri>@{[htescape $input->{uri}]}</a>></code> |
| 65 | <script> | ||
| 66 | document.title = '<' | ||
| 67 | + document.getElementById ('anchor-document-uri').href + '> \\u2014 ' | ||
| 68 | + document.title; | ||
| 69 | </script></dd> | ||
| 70 | wakaba | 1.2 | ]; # no </dl> yet |
| 71 | wakaba | 1.3 | push @nav, ['#document-info' => 'Information']; |
| 72 | wakaba | 1.1 | |
| 73 | wakaba | 1.9 | if (defined $input->{s}) { |
| 74 | wakaba | 1.16 | $char_length = length $input->{s}; |
| 75 | wakaba | 1.9 | |
| 76 | print STDOUT qq[ | ||
| 77 | <dt>Base URI</dt> | ||
| 78 | <dd><code class="URI" lang=""><<a href="@{[htescape $input->{base_uri}]}">@{[htescape $input->{base_uri}]}</a>></code></dd> | ||
| 79 | <dt>Internet Media Type</dt> | ||
| 80 | <dd><code class="MIME" lang="en">@{[htescape $input->{media_type}]}</code> | ||
| 81 | wakaba | 1.25 | @{[$input->{media_type_overridden} ? '<em>(overridden)</em>' : defined $input->{official_type} ? $input->{media_type} eq $input->{official_type} ? '' : '<em>(sniffed; official type is: <code class=MIME lang=en>'.htescape ($input->{official_type}).'</code>)' : '<em>(sniffed)</em>']}</dd> |
| 82 | wakaba | 1.9 | <dt>Character Encoding</dt> |
| 83 | <dd>@{[defined $input->{charset} ? '<code class="charset" lang="en">'.htescape ($input->{charset}).'</code>' : '(none)']} | ||
| 84 | @{[$input->{charset_overridden} ? '<em>(overridden)</em>' : '']}</dd> | ||
| 85 | wakaba | 1.16 | <dt>Length</dt> |
| 86 | <dd>$char_length byte@{[$char_length == 1 ? '' : 's']}</dd> | ||
| 87 | wakaba | 1.9 | </dl> |
| 88 | </div> | ||
| 89 | ]; | ||
| 90 | |||
| 91 | wakaba | 1.35 | $input->{id_prefix} = ''; |
| 92 | #$input->{nested} = 0; | ||
| 93 | wakaba | 1.20 | my $result = {conforming_min => 1, conforming_max => 1}; |
| 94 | wakaba | 1.31 | check_and_print ($input => $result); |
| 95 | wakaba | 1.19 | print_result_section ($result); |
| 96 | wakaba | 1.9 | } else { |
| 97 | wakaba | 1.18 | print STDOUT qq[</dl></div>]; |
| 98 | print_result_input_error_section ($input); | ||
| 99 | wakaba | 1.9 | } |
| 100 | wakaba | 1.3 | |
| 101 | wakaba | 1.2 | print STDOUT qq[ |
| 102 | wakaba | 1.3 | <ul class="navigation" id="nav-items"> |
| 103 | ]; | ||
| 104 | for (@nav) { | ||
| 105 | print STDOUT qq[<li><a href="$_->[0]">$_->[1]</a></li>]; | ||
| 106 | } | ||
| 107 | print STDOUT qq[ | ||
| 108 | </ul> | ||
| 109 | wakaba | 1.2 | </body> |
| 110 | </html> | ||
| 111 | ]; | ||
| 112 | wakaba | 1.1 | |
| 113 | wakaba | 1.24 | for (qw/decode parse parse_html parse_xml parse_manifest |
| 114 | check check_manifest/) { | ||
| 115 | wakaba | 1.16 | next unless defined $time{$_}; |
| 116 | open my $file, '>>', ".cc-$_.txt" or die ".cc-$_.txt: $!"; | ||
| 117 | print $file $char_length, "\t", $time{$_}, "\n"; | ||
| 118 | } | ||
| 119 | |||
| 120 | wakaba | 1.1 | exit; |
| 121 | wakaba | 1.35 | } |
| 122 | wakaba | 1.1 | |
| 123 | wakaba | 1.19 | sub add_error ($$$) { |
| 124 | my ($layer, $err, $result) = @_; | ||
| 125 | if (defined $err->{level}) { | ||
| 126 | if ($err->{level} eq 's') { | ||
| 127 | $result->{$layer}->{should}++; | ||
| 128 | $result->{$layer}->{score_min} -= 2; | ||
| 129 | $result->{conforming_min} = 0; | ||
| 130 | } elsif ($err->{level} eq 'w' or $err->{level} eq 'g') { | ||
| 131 | $result->{$layer}->{warning}++; | ||
| 132 | wakaba | 1.30 | } elsif ($err->{level} eq 'u' or $err->{level} eq 'unsupported') { |
| 133 | wakaba | 1.19 | $result->{$layer}->{unsupported}++; |
| 134 | $result->{unsupported} = 1; | ||
| 135 | } else { | ||
| 136 | $result->{$layer}->{must}++; | ||
| 137 | $result->{$layer}->{score_max} -= 2; | ||
| 138 | $result->{$layer}->{score_min} -= 2; | ||
| 139 | $result->{conforming_min} = 0; | ||
| 140 | $result->{conforming_max} = 0; | ||
| 141 | } | ||
| 142 | } else { | ||
| 143 | $result->{$layer}->{must}++; | ||
| 144 | $result->{$layer}->{score_max} -= 2; | ||
| 145 | $result->{$layer}->{score_min} -= 2; | ||
| 146 | $result->{conforming_min} = 0; | ||
| 147 | $result->{conforming_max} = 0; | ||
| 148 | } | ||
| 149 | } # add_error | ||
| 150 | |||
| 151 | wakaba | 1.31 | sub check_and_print ($$) { |
| 152 | my ($input, $result) = @_; | ||
| 153 | |||
| 154 | print_http_header_section ($input, $result); | ||
| 155 | |||
| 156 | my $doc; | ||
| 157 | my $el; | ||
| 158 | wakaba | 1.35 | my $cssom; |
| 159 | wakaba | 1.31 | my $manifest; |
| 160 | wakaba | 1.34 | my @subdoc; |
| 161 | wakaba | 1.31 | |
| 162 | if ($input->{media_type} eq 'text/html') { | ||
| 163 | ($doc, $el) = print_syntax_error_html_section ($input, $result); | ||
| 164 | print_source_string_section | ||
| 165 | wakaba | 1.35 | ($input, |
| 166 | \($input->{s}), | ||
| 167 | $input->{charset} || $doc->input_encoding); | ||
| 168 | wakaba | 1.31 | } elsif ({ |
| 169 | 'text/xml' => 1, | ||
| 170 | 'application/atom+xml' => 1, | ||
| 171 | 'application/rss+xml' => 1, | ||
| 172 | 'application/svg+xml' => 1, | ||
| 173 | 'application/xhtml+xml' => 1, | ||
| 174 | 'application/xml' => 1, | ||
| 175 | }->{$input->{media_type}}) { | ||
| 176 | ($doc, $el) = print_syntax_error_xml_section ($input, $result); | ||
| 177 | wakaba | 1.35 | print_source_string_section ($input, |
| 178 | \($input->{s}), | ||
| 179 | $doc->input_encoding); | ||
| 180 | } elsif ($input->{media_type} eq 'text/css') { | ||
| 181 | $cssom = print_syntax_error_css_section ($input, $result); | ||
| 182 | print_source_string_section | ||
| 183 | ($input, \($input->{s}), | ||
| 184 | $cssom->manakai_input_encoding); | ||
| 185 | wakaba | 1.31 | } elsif ($input->{media_type} eq 'text/cache-manifest') { |
| 186 | ## TODO: MUST be text/cache-manifest | ||
| 187 | $manifest = print_syntax_error_manifest_section ($input, $result); | ||
| 188 | wakaba | 1.35 | print_source_string_section ($input, \($input->{s}), |
| 189 | 'utf-8'); | ||
| 190 | wakaba | 1.31 | } else { |
| 191 | ## TODO: Change HTTP status code?? | ||
| 192 | print_result_unknown_type_section ($input, $result); | ||
| 193 | } | ||
| 194 | |||
| 195 | if (defined $doc or defined $el) { | ||
| 196 | wakaba | 1.34 | $doc->document_uri ($input->{uri}); |
| 197 | $doc->manakai_entity_base_uri ($input->{base_uri}); | ||
| 198 | wakaba | 1.32 | print_structure_dump_dom_section ($input, $doc, $el); |
| 199 | my $elements = print_structure_error_dom_section | ||
| 200 | wakaba | 1.34 | ($input, $doc, $el, $result, sub { |
| 201 | push @subdoc, shift; | ||
| 202 | }); | ||
| 203 | wakaba | 1.32 | print_table_section ($input, $elements->{table}) if @{$elements->{table}}; |
| 204 | wakaba | 1.33 | print_listing_section ({ |
| 205 | id => 'identifiers', label => 'IDs', heading => 'Identifiers', | ||
| 206 | }, $input, $elements->{id}) if keys %{$elements->{id}}; | ||
| 207 | print_listing_section ({ | ||
| 208 | id => 'terms', label => 'Terms', heading => 'Terms', | ||
| 209 | }, $input, $elements->{term}) if keys %{$elements->{term}}; | ||
| 210 | print_listing_section ({ | ||
| 211 | id => 'classes', label => 'Classes', heading => 'Classes', | ||
| 212 | }, $input, $elements->{class}) if keys %{$elements->{class}}; | ||
| 213 | wakaba | 1.35 | } elsif (defined $cssom) { |
| 214 | print_structure_dump_cssom_section ($input, $cssom); | ||
| 215 | ## TODO: CSSOM validation | ||
| 216 | wakaba | 1.31 | } elsif (defined $manifest) { |
| 217 | wakaba | 1.32 | print_structure_dump_manifest_section ($input, $manifest); |
| 218 | print_structure_error_manifest_section ($input, $manifest, $result); | ||
| 219 | wakaba | 1.31 | } |
| 220 | wakaba | 1.34 | |
| 221 | my $id_prefix = 0; | ||
| 222 | for my $subinput (@subdoc) { | ||
| 223 | $subinput->{id_prefix} = 'subdoc-' . ++$id_prefix; | ||
| 224 | $subinput->{nested} = 1; | ||
| 225 | $subinput->{base_uri} = $subinput->{container_node}->base_uri | ||
| 226 | unless defined $subinput->{base_uri}; | ||
| 227 | my $ebaseuri = htescape ($subinput->{base_uri}); | ||
| 228 | push @nav, ['#' . $subinput->{id_prefix} => 'Sub #' . $id_prefix]; | ||
| 229 | print STDOUT qq[<div id="$subinput->{id_prefix}" class=section> | ||
| 230 | <h2>Subdocument #$id_prefix</h2> | ||
| 231 | |||
| 232 | <dl> | ||
| 233 | <dt>Internet Media Type</dt> | ||
| 234 | <dd><code class="MIME" lang="en">@{[htescape $subinput->{media_type}]}</code> | ||
| 235 | <dt>Container Node</dt> | ||
| 236 | <dd>@{[get_node_link ($input, $subinput->{container_node})]}</dd> | ||
| 237 | <dt>Base <abbr title="Uniform Resource Identifiers">URI</abbr></dt> | ||
| 238 | <dd><code class=URI><<a href="$ebaseuri">$ebaseuri</a>></code></dd> | ||
| 239 | </dl>]; | ||
| 240 | |||
| 241 | wakaba | 1.35 | $subinput->{id_prefix} .= '-'; |
| 242 | wakaba | 1.34 | check_and_print ($subinput => $result); |
| 243 | |||
| 244 | print STDOUT qq[</div>]; | ||
| 245 | } | ||
| 246 | wakaba | 1.31 | } # check_and_print |
| 247 | |||
| 248 | wakaba | 1.19 | sub print_http_header_section ($$) { |
| 249 | my ($input, $result) = @_; | ||
| 250 | wakaba | 1.9 | return unless defined $input->{header_status_code} or |
| 251 | defined $input->{header_status_text} or | ||
| 252 | wakaba | 1.34 | @{$input->{header_field} or []}; |
| 253 | wakaba | 1.9 | |
| 254 | wakaba | 1.32 | push @nav, ['#source-header' => 'HTTP Header'] unless $input->{nested}; |
| 255 | print STDOUT qq[<div id="$input->{id_prefix}source-header" class="section"> | ||
| 256 | wakaba | 1.9 | <h2>HTTP Header</h2> |
| 257 | |||
| 258 | <p><strong>Note</strong>: Due to the limitation of the | ||
| 259 | network library in use, the content of this section might | ||
| 260 | not be the real header.</p> | ||
| 261 | |||
| 262 | <table><tbody> | ||
| 263 | ]; | ||
| 264 | |||
| 265 | if (defined $input->{header_status_code}) { | ||
| 266 | print STDOUT qq[<tr><th scope="row">Status code</th>]; | ||
| 267 | print STDOUT qq[<td><code>@{[htescape ($input->{header_status_code})]}</code></td></tr>]; | ||
| 268 | } | ||
| 269 | if (defined $input->{header_status_text}) { | ||
| 270 | print STDOUT qq[<tr><th scope="row">Status text</th>]; | ||
| 271 | print STDOUT qq[<td><code>@{[htescape ($input->{header_status_text})]}</code></td></tr>]; | ||
| 272 | } | ||
| 273 | |||
| 274 | for (@{$input->{header_field}}) { | ||
| 275 | print STDOUT qq[<tr><th scope="row"><code>@{[htescape ($_->[0])]}</code></th>]; | ||
| 276 | print STDOUT qq[<td><code>@{[htescape ($_->[1])]}</code></td></tr>]; | ||
| 277 | } | ||
| 278 | |||
| 279 | print STDOUT qq[</tbody></table></div>]; | ||
| 280 | } # print_http_header_section | ||
| 281 | |||
| 282 | wakaba | 1.19 | sub print_syntax_error_html_section ($$) { |
| 283 | my ($input, $result) = @_; | ||
| 284 | wakaba | 1.18 | |
| 285 | require Encode; | ||
| 286 | require Whatpm::HTML; | ||
| 287 | |||
| 288 | print STDOUT qq[ | ||
| 289 | wakaba | 1.32 | <div id="$input->{id_prefix}parse-errors" class="section"> |
| 290 | wakaba | 1.18 | <h2>Parse Errors</h2> |
| 291 | |||
| 292 | <dl>]; | ||
| 293 | wakaba | 1.32 | push @nav, ['#parse-errors' => 'Parse Error'] unless $input->{nested}; |
| 294 | wakaba | 1.18 | |
| 295 | my $onerror = sub { | ||
| 296 | my (%opt) = @_; | ||
| 297 | my ($type, $cls, $msg) = get_text ($opt{type}, $opt{level}); | ||
| 298 | if ($opt{column} > 0) { | ||
| 299 | wakaba | 1.35 | print STDOUT qq[<dt class="$cls"><a href="#$input->{id_prefix}line-$opt{line}">Line $opt{line}</a> column $opt{column}</dt>\n]; |
| 300 | wakaba | 1.18 | } else { |
| 301 | $opt{line} = $opt{line} - 1 || 1; | ||
| 302 | wakaba | 1.35 | print STDOUT qq[<dt class="$cls"><a href="#$input->{id_prefix}line-$opt{line}">Line $opt{line}</a></dt>\n]; |
| 303 | wakaba | 1.18 | } |
| 304 | $type =~ tr/ /-/; | ||
| 305 | $type =~ s/\|/%7C/g; | ||
| 306 | $msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]]; | ||
| 307 | wakaba | 1.23 | print STDOUT qq[<dd class="$cls">], get_error_level_label (\%opt); |
| 308 | print STDOUT qq[$msg</dd>\n]; | ||
| 309 | wakaba | 1.19 | |
| 310 | add_error ('syntax', \%opt => $result); | ||
| 311 | wakaba | 1.18 | }; |
| 312 | |||
| 313 | my $doc = $dom->create_document; | ||
| 314 | my $el; | ||
| 315 | wakaba | 1.35 | my $inner_html_element = $input->{inner_html_element}; |
| 316 | wakaba | 1.18 | if (defined $inner_html_element and length $inner_html_element) { |
| 317 | wakaba | 1.26 | $input->{charset} ||= 'windows-1252'; ## TODO: for now. |
| 318 | wakaba | 1.24 | my $time1 = time; |
| 319 | my $t = Encode::decode ($input->{charset}, $input->{s}); | ||
| 320 | $time{decode} = time - $time1; | ||
| 321 | |||
| 322 | wakaba | 1.18 | $el = $doc->create_element_ns |
| 323 | ('http://www.w3.org/1999/xhtml', [undef, $inner_html_element]); | ||
| 324 | wakaba | 1.24 | $time1 = time; |
| 325 | wakaba | 1.18 | Whatpm::HTML->set_inner_html ($el, $t, $onerror); |
| 326 | wakaba | 1.24 | $time{parse} = time - $time1; |
| 327 | wakaba | 1.18 | } else { |
| 328 | wakaba | 1.24 | my $time1 = time; |
| 329 | Whatpm::HTML->parse_byte_string | ||
| 330 | ($input->{charset}, $input->{s} => $doc, $onerror); | ||
| 331 | $time{parse_html} = time - $time1; | ||
| 332 | wakaba | 1.18 | } |
| 333 | wakaba | 1.26 | $doc->manakai_charset ($input->{official_charset}) |
| 334 | if defined $input->{official_charset}; | ||
| 335 | wakaba | 1.24 | |
| 336 | wakaba | 1.18 | print STDOUT qq[</dl></div>]; |
| 337 | |||
| 338 | return ($doc, $el); | ||
| 339 | } # print_syntax_error_html_section | ||
| 340 | |||
| 341 | wakaba | 1.19 | sub print_syntax_error_xml_section ($$) { |
| 342 | my ($input, $result) = @_; | ||
| 343 | wakaba | 1.18 | |
| 344 | require Message::DOM::XMLParserTemp; | ||
| 345 | |||
| 346 | print STDOUT qq[ | ||
| 347 | wakaba | 1.32 | <div id="$input->{id_prefix}parse-errors" class="section"> |
| 348 | wakaba | 1.18 | <h2>Parse Errors</h2> |
| 349 | |||
| 350 | <dl>]; | ||
| 351 | wakaba | 1.32 | push @nav, ['#parse-errors' => 'Parse Error'] unless $input->{prefix}; |
| 352 | wakaba | 1.18 | |
| 353 | my $onerror = sub { | ||
| 354 | my $err = shift; | ||
| 355 | my $line = $err->location->line_number; | ||
| 356 | wakaba | 1.35 | print STDOUT qq[<dt><a href="#$input->{id_prefix}line-$line">Line $line</a> column ]; |
| 357 | wakaba | 1.18 | print STDOUT $err->location->column_number, "</dt><dd>"; |
| 358 | print STDOUT htescape $err->text, "</dd>\n"; | ||
| 359 | wakaba | 1.19 | |
| 360 | add_error ('syntax', {type => $err->text, | ||
| 361 | level => [ | ||
| 362 | $err->SEVERITY_FATAL_ERROR => 'm', | ||
| 363 | $err->SEVERITY_ERROR => 'm', | ||
| 364 | $err->SEVERITY_WARNING => 's', | ||
| 365 | ]->[$err->severity]} => $result); | ||
| 366 | |||
| 367 | wakaba | 1.18 | return 1; |
| 368 | }; | ||
| 369 | |||
| 370 | my $time1 = time; | ||
| 371 | open my $fh, '<', \($input->{s}); | ||
| 372 | my $doc = Message::DOM::XMLParserTemp->parse_byte_stream | ||
| 373 | ($fh => $dom, $onerror, charset => $input->{charset}); | ||
| 374 | $time{parse_xml} = time - $time1; | ||
| 375 | wakaba | 1.26 | $doc->manakai_charset ($input->{official_charset}) |
| 376 | if defined $input->{official_charset}; | ||
| 377 | wakaba | 1.18 | |
| 378 | print STDOUT qq[</dl></div>]; | ||
| 379 | |||
| 380 | return ($doc, undef); | ||
| 381 | } # print_syntax_error_xml_section | ||
| 382 | |||
| 383 | wakaba | 1.35 | sub get_css_parser () { |
| 384 | our $CSSParser; | ||
| 385 | return $CSSParser if $CSSParser; | ||
| 386 | |||
| 387 | require Whatpm::CSS::Parser; | ||
| 388 | my $p = Whatpm::CSS::Parser->new; | ||
| 389 | |||
| 390 | # if ($parse_mode eq 'q') { | ||
| 391 | # $p->{unitless_px} = 1; | ||
| 392 | # $p->{hashless_color} = 1; | ||
| 393 | # } | ||
| 394 | |||
| 395 | $p->{prop}->{$_} = 1 for qw/ | ||
| 396 | background background-attachment background-color background-image | ||
| 397 | background-position background-position-x background-position-y | ||
| 398 | background-repeat border border-bottom border-bottom-color | ||
| 399 | border-bottom-style border-bottom-width border-collapse border-color | ||
| 400 | border-left border-left-color | ||
| 401 | border-left-style border-left-width border-right border-right-color | ||
| 402 | border-right-style border-right-width | ||
| 403 | border-spacing -manakai-border-spacing-x -manakai-border-spacing-y | ||
| 404 | border-style border-top border-top-color border-top-style border-top-width | ||
| 405 | border-width bottom | ||
| 406 | caption-side clear clip color content counter-increment counter-reset | ||
| 407 | cursor direction display empty-cells float font | ||
| 408 | font-family font-size font-size-adjust font-stretch | ||
| 409 | font-style font-variant font-weight height left | ||
| 410 | letter-spacing line-height | ||
| 411 | list-style list-style-image list-style-position list-style-type | ||
| 412 | margin margin-bottom margin-left margin-right margin-top marker-offset | ||
| 413 | marks max-height max-width min-height min-width opacity -moz-opacity | ||
| 414 | orphans outline outline-color outline-style outline-width overflow | ||
| 415 | overflow-x overflow-y | ||
| 416 | padding padding-bottom padding-left padding-right padding-top | ||
| 417 | page page-break-after page-break-before page-break-inside | ||
| 418 | position quotes right size table-layout | ||
| 419 | text-align text-decoration text-indent text-transform | ||
| 420 | top unicode-bidi vertical-align visibility white-space width widows | ||
| 421 | word-spacing z-index | ||
| 422 | /; | ||
| 423 | $p->{prop_value}->{display}->{$_} = 1 for qw/ | ||
| 424 | block clip inline inline-block inline-table list-item none | ||
| 425 | table table-caption table-cell table-column table-column-group | ||
| 426 | table-header-group table-footer-group table-row table-row-group | ||
| 427 | compact marker | ||
| 428 | /; | ||
| 429 | $p->{prop_value}->{position}->{$_} = 1 for qw/ | ||
| 430 | absolute fixed relative static | ||
| 431 | /; | ||
| 432 | $p->{prop_value}->{float}->{$_} = 1 for qw/ | ||
| 433 | left right none | ||
| 434 | /; | ||
| 435 | $p->{prop_value}->{clear}->{$_} = 1 for qw/ | ||
| 436 | left right none both | ||
| 437 | /; | ||
| 438 | $p->{prop_value}->{direction}->{ltr} = 1; | ||
| 439 | $p->{prop_value}->{direction}->{rtl} = 1; | ||
| 440 | $p->{prop_value}->{marks}->{crop} = 1; | ||
| 441 | $p->{prop_value}->{marks}->{cross} = 1; | ||
| 442 | $p->{prop_value}->{'unicode-bidi'}->{$_} = 1 for qw/ | ||
| 443 | normal bidi-override embed | ||
| 444 | /; | ||
| 445 | for my $prop_name (qw/overflow overflow-x overflow-y/) { | ||
| 446 | $p->{prop_value}->{$prop_name}->{$_} = 1 for qw/ | ||
| 447 | visible hidden scroll auto -webkit-marquee -moz-hidden-unscrollable | ||
| 448 | /; | ||
| 449 | } | ||
| 450 | $p->{prop_value}->{visibility}->{$_} = 1 for qw/ | ||
| 451 | visible hidden collapse | ||
| 452 | /; | ||
| 453 | $p->{prop_value}->{'list-style-type'}->{$_} = 1 for qw/ | ||
| 454 | disc circle square decimal decimal-leading-zero | ||
| 455 | lower-roman upper-roman lower-greek lower-latin | ||
| 456 | upper-latin armenian georgian lower-alpha upper-alpha none | ||
| 457 | hebrew cjk-ideographic hiragana katakana hiragana-iroha | ||
| 458 | katakana-iroha | ||
| 459 | /; | ||
| 460 | $p->{prop_value}->{'list-style-position'}->{outside} = 1; | ||
| 461 | $p->{prop_value}->{'list-style-position'}->{inside} = 1; | ||
| 462 | $p->{prop_value}->{'page-break-before'}->{$_} = 1 for qw/ | ||
| 463 | auto always avoid left right | ||
| 464 | /; | ||
| 465 | $p->{prop_value}->{'page-break-after'}->{$_} = 1 for qw/ | ||
| 466 | auto always avoid left right | ||
| 467 | /; | ||
| 468 | $p->{prop_value}->{'page-break-inside'}->{auto} = 1; | ||
| 469 | $p->{prop_value}->{'page-break-inside'}->{avoid} = 1; | ||
| 470 | $p->{prop_value}->{'background-repeat'}->{$_} = 1 for qw/ | ||
| 471 | repeat repeat-x repeat-y no-repeat | ||
| 472 | /; | ||
| 473 | $p->{prop_value}->{'background-attachment'}->{scroll} = 1; | ||
| 474 | $p->{prop_value}->{'background-attachment'}->{fixed} = 1; | ||
| 475 | $p->{prop_value}->{'font-size'}->{$_} = 1 for qw/ | ||
| 476 | xx-small x-small small medium large x-large xx-large | ||
| 477 | -manakai-xxx-large -webkit-xxx-large | ||
| 478 | larger smaller | ||
| 479 | /; | ||
| 480 | $p->{prop_value}->{'font-style'}->{normal} = 1; | ||
| 481 | $p->{prop_value}->{'font-style'}->{italic} = 1; | ||
| 482 | $p->{prop_value}->{'font-style'}->{oblique} = 1; | ||
| 483 | $p->{prop_value}->{'font-variant'}->{normal} = 1; | ||
| 484 | $p->{prop_value}->{'font-variant'}->{'small-caps'} = 1; | ||
| 485 | $p->{prop_value}->{'font-stretch'}->{$_} = 1 for | ||
| 486 | qw/normal wider narrower ultra-condensed extra-condensed | ||
| 487 | condensed semi-condensed semi-expanded expanded | ||
| 488 | extra-expanded ultra-expanded/; | ||
| 489 | $p->{prop_value}->{'text-align'}->{$_} = 1 for qw/ | ||
| 490 | left right center justify begin end | ||
| 491 | /; | ||
| 492 | $p->{prop_value}->{'text-transform'}->{$_} = 1 for qw/ | ||
| 493 | capitalize uppercase lowercase none | ||
| 494 | /; | ||
| 495 | $p->{prop_value}->{'white-space'}->{$_} = 1 for qw/ | ||
| 496 | normal pre nowrap pre-line pre-wrap | ||
| 497 | /; | ||
| 498 | $p->{prop_value}->{'text-decoration'}->{$_} = 1 for qw/ | ||
| 499 | none blink underline overline line-through | ||
| 500 | /; | ||
| 501 | $p->{prop_value}->{'caption-side'}->{$_} = 1 for qw/ | ||
| 502 | top bottom left right | ||
| 503 | /; | ||
| 504 | $p->{prop_value}->{'table-layout'}->{auto} = 1; | ||
| 505 | $p->{prop_value}->{'table-layout'}->{fixed} = 1; | ||
| 506 | $p->{prop_value}->{'border-collapse'}->{collapase} = 1; | ||
| 507 | $p->{prop_value}->{'border-collapse'}->{separate} = 1; | ||
| 508 | $p->{prop_value}->{'empty-cells'}->{show} = 1; | ||
| 509 | $p->{prop_value}->{'empty-cells'}->{hide} = 1; | ||
| 510 | $p->{prop_value}->{cursor}->{$_} = 1 for qw/ | ||
| 511 | auto crosshair default pointer move e-resize ne-resize nw-resize n-resize | ||
| 512 | se-resize sw-resize s-resize w-resize text wait help progress | ||
| 513 | /; | ||
| 514 | for my $prop (qw/border-top-style border-left-style | ||
| 515 | border-bottom-style border-right-style outline-style/) { | ||
| 516 | $p->{prop_value}->{$prop}->{$_} = 1 for qw/ | ||
| 517 | none hidden dotted dashed solid double groove ridge inset outset | ||
| 518 | /; | ||
| 519 | } | ||
| 520 | for my $prop (qw/color background-color | ||
| 521 | border-bottom-color border-left-color border-right-color | ||
| 522 | border-top-color border-color/) { | ||
| 523 | $p->{prop_value}->{$prop}->{transparent} = 1; | ||
| 524 | $p->{prop_value}->{$prop}->{flavor} = 1; | ||
| 525 | $p->{prop_value}->{$prop}->{'-manakai-default'} = 1; | ||
| 526 | } | ||
| 527 | $p->{prop_value}->{'outline-color'}->{invert} = 1; | ||
| 528 | $p->{prop_value}->{'outline-color'}->{'-manakai-invert-or-currentcolor'} = 1; | ||
| 529 | $p->{pseudo_class}->{$_} = 1 for qw/ | ||
| 530 | active checked disabled empty enabled first-child first-of-type | ||
| 531 | focus hover indeterminate last-child last-of-type link only-child | ||
| 532 | only-of-type root target visited | ||
| 533 | lang nth-child nth-last-child nth-of-type nth-last-of-type not | ||
| 534 | -manakai-contains -manakai-current | ||
| 535 | /; | ||
| 536 | $p->{pseudo_element}->{$_} = 1 for qw/ | ||
| 537 | after before first-letter first-line | ||
| 538 | /; | ||
| 539 | |||
| 540 | return $CSSParser = $p; | ||
| 541 | } # get_css_parser | ||
| 542 | |||
| 543 | sub print_syntax_error_css_section ($$) { | ||
| 544 | my ($input, $result) = @_; | ||
| 545 | |||
| 546 | print STDOUT qq[ | ||
| 547 | <div id="$input->{id_prefix}parse-errors" class="section"> | ||
| 548 | <h2>Parse Errors</h2> | ||
| 549 | |||
| 550 | <dl>]; | ||
| 551 | push @nav, ['#parse-errors' => 'Parse Error'] unless $input->{nested}; | ||
| 552 | |||
| 553 | my $p = get_css_parser (); | ||
| 554 | $p->{onerror} = sub { | ||
| 555 | my (%opt) = @_; | ||
| 556 | my ($type, $cls, $msg) = get_text ($opt{type}, $opt{level}); | ||
| 557 | if ($opt{token}) { | ||
| 558 | print STDOUT qq[<dt class="$cls"><a href="#$input->{id_prefix}line-$opt{token}->{line}">Line $opt{token}->{line}</a> column $opt{token}->{column}]; | ||
| 559 | } else { | ||
| 560 | print STDOUT qq[<dt class="$cls">Unknown location]; | ||
| 561 | } | ||
| 562 | if (defined $opt{value}) { | ||
| 563 | print STDOUT qq[ (<code>@{[htescape ($opt{value})]}</code>)]; | ||
| 564 | } elsif (defined $opt{token}) { | ||
| 565 | print STDOUT qq[ (<code>@{[htescape (Whatpm::CSS::Tokenizer->serialize_token ($opt{token}))]}</code>)]; | ||
| 566 | } | ||
| 567 | $type =~ tr/ /-/; | ||
| 568 | $type =~ s/\|/%7C/g; | ||
| 569 | $msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]]; | ||
| 570 | print STDOUT qq[<dd class="$cls">], get_error_level_label (\%opt); | ||
| 571 | print STDOUT qq[$msg</dd>\n]; | ||
| 572 | |||
| 573 | add_error ('syntax', \%opt => $result); | ||
| 574 | }; | ||
| 575 | $p->{href} = $input->{uri}; | ||
| 576 | $p->{base_uri} = $input->{base_uri}; | ||
| 577 | |||
| 578 | my $s = \$input->{s}; | ||
| 579 | my $charset; | ||
| 580 | unless ($input->{is_char_string}) { | ||
| 581 | require Encode; | ||
| 582 | if (defined $input->{charset}) {## TODO: IANA->Perl | ||
| 583 | $charset = $input->{charset}; | ||
| 584 | $s = \(Encode::decode ($input->{charset}, $$s)); | ||
| 585 | } else { | ||
| 586 | ## TODO: charset detection | ||
| 587 | $s = \(Encode::decode ($charset = 'utf-8', $$s)); | ||
| 588 | } | ||
| 589 | } | ||
| 590 | |||
| 591 | my $cssom = $p->parse_char_string ($$s); | ||
| 592 | $cssom->manakai_input_encoding ($charset) if defined $charset; | ||
| 593 | |||
| 594 | print STDOUT qq[</dl></div>]; | ||
| 595 | |||
| 596 | return $cssom; | ||
| 597 | } # print_syntax_error_css_section | ||
| 598 | |||
| 599 | wakaba | 1.22 | sub print_syntax_error_manifest_section ($$) { |
| 600 | my ($input, $result) = @_; | ||
| 601 | |||
| 602 | require Whatpm::CacheManifest; | ||
| 603 | |||
| 604 | print STDOUT qq[ | ||
| 605 | wakaba | 1.32 | <div id="$input->{id_prefix}parse-errors" class="section"> |
| 606 | wakaba | 1.22 | <h2>Parse Errors</h2> |
| 607 | |||
| 608 | <dl>]; | ||
| 609 | wakaba |