/[pub]/test/html-webhacc/cc.cgi
Suika

Diff of /test/html-webhacc/cc.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.33 by wakaba, Sun Feb 10 02:42:01 2008 UTC revision 1.37 by wakaba, Sun Feb 24 02:17:51 2008 UTC
# Line 20  sub htescape ($) { Line 20  sub htescape ($) {
20    return $s;    return $s;
21  } # htescape  } # htescape
22    
23      my @nav;
24      my %time;
25      require Message::DOM::DOMImplementation;
26      my $dom = Message::DOM::DOMImplementation->new;
27    {
28    use Message::CGI::HTTP;    use Message::CGI::HTTP;
29    my $http = Message::CGI::HTTP->new;    my $http = Message::CGI::HTTP->new;
30    
# Line 31  sub htescape ($) { Line 36  sub htescape ($) {
36    binmode STDOUT, ':utf8';    binmode STDOUT, ':utf8';
37    $| = 1;    $| = 1;
38    
   require Message::DOM::DOMImplementation;  
   my $dom = Message::DOM::DOMImplementation->new;  
   
39    load_text_catalog ('en'); ## TODO: conneg    load_text_catalog ('en'); ## TODO: conneg
40    
   my @nav;  
41    print STDOUT qq[Content-Type: text/html; charset=utf-8    print STDOUT qq[Content-Type: text/html; charset=utf-8
42    
43  <!DOCTYPE html>  <!DOCTYPE html>
# Line 53  sub htescape ($) { Line 54  sub htescape ($) {
54    $| = 0;    $| = 0;
55    my $input = get_input_document ($http, $dom);    my $input = get_input_document ($http, $dom);
56    my $char_length = 0;    my $char_length = 0;
   my %time;  
57    
58    print qq[    print qq[
59  <div id="document-info" class="section">  <div id="document-info" class="section">
# Line 88  if (defined $input->{s}) { Line 88  if (defined $input->{s}) {
88  </div>  </div>
89  ];  ];
90    
91      $input->{id_prefix} = '';
92      #$input->{nested} = 0;
93    my $result = {conforming_min => 1, conforming_max => 1};    my $result = {conforming_min => 1, conforming_max => 1};
94    check_and_print ($input => $result);    check_and_print ($input => $result);
95    print_result_section ($result);    print_result_section ($result);
# Line 116  if (defined $input->{s}) { Line 118  if (defined $input->{s}) {
118    }    }
119    
120  exit;  exit;
121    }
122    
123  sub add_error ($$$) {  sub add_error ($$$) {
124    my ($layer, $err, $result) = @_;    my ($layer, $err, $result) = @_;
# Line 129  sub add_error ($$$) { Line 132  sub add_error ($$$) {
132      } elsif ($err->{level} eq 'u' or $err->{level} eq 'unsupported') {      } elsif ($err->{level} eq 'u' or $err->{level} eq 'unsupported') {
133        $result->{$layer}->{unsupported}++;        $result->{$layer}->{unsupported}++;
134        $result->{unsupported} = 1;        $result->{unsupported} = 1;
135        } elsif ($err->{level} eq 'i') {
136          #
137      } else {      } else {
138        $result->{$layer}->{must}++;        $result->{$layer}->{must}++;
139        $result->{$layer}->{score_max} -= 2;        $result->{$layer}->{score_max} -= 2;
# Line 147  sub add_error ($$$) { Line 152  sub add_error ($$$) {
152    
153  sub check_and_print ($$) {  sub check_and_print ($$) {
154    my ($input, $result) = @_;    my ($input, $result) = @_;
   $input->{id_prefix} = '';  
   #$input->{nested} = 1/0;  
155    
156    print_http_header_section ($input, $result);    print_http_header_section ($input, $result);
157    
158    my $doc;    my $doc;
159    my $el;    my $el;
160      my $cssom;
161    my $manifest;    my $manifest;
162      my @subdoc;
163    
164    if ($input->{media_type} eq 'text/html') {    if ($input->{media_type} eq 'text/html') {
165      ($doc, $el) = print_syntax_error_html_section ($input, $result);      ($doc, $el) = print_syntax_error_html_section ($input, $result);
166      print_source_string_section      print_source_string_section
167          (\($input->{s}), $input->{charset} || $doc->input_encoding);          ($input,
168             \($input->{s}),
169             $input->{charset} || $doc->input_encoding);
170    } elsif ({    } elsif ({
171              'text/xml' => 1,              'text/xml' => 1,
172              'application/atom+xml' => 1,              'application/atom+xml' => 1,
# Line 169  sub check_and_print ($$) { Line 176  sub check_and_print ($$) {
176              'application/xml' => 1,              'application/xml' => 1,
177             }->{$input->{media_type}}) {             }->{$input->{media_type}}) {
178      ($doc, $el) = print_syntax_error_xml_section ($input, $result);      ($doc, $el) = print_syntax_error_xml_section ($input, $result);
179      print_source_string_section (\($input->{s}), $doc->input_encoding);      print_source_string_section ($input,
180                                     \($input->{s}),
181                                     $doc->input_encoding);
182      } elsif ($input->{media_type} eq 'text/css') {
183        $cssom = print_syntax_error_css_section ($input, $result);
184        print_source_string_section
185            ($input, \($input->{s}),
186             $cssom->manakai_input_encoding);
187    } elsif ($input->{media_type} eq 'text/cache-manifest') {    } elsif ($input->{media_type} eq 'text/cache-manifest') {
188  ## TODO: MUST be text/cache-manifest  ## TODO: MUST be text/cache-manifest
189      $manifest = print_syntax_error_manifest_section ($input, $result);      $manifest = print_syntax_error_manifest_section ($input, $result);
190      print_source_string_section (\($input->{s}), 'utf-8');      print_source_string_section ($input, \($input->{s}),
191                                     'utf-8');
192    } else {    } else {
193      ## TODO: Change HTTP status code??      ## TODO: Change HTTP status code??
194      print_result_unknown_type_section ($input, $result);      print_result_unknown_type_section ($input, $result);
195    }    }
196    
197    if (defined $doc or defined $el) {    if (defined $doc or defined $el) {
198        $doc->document_uri ($input->{uri});
199        $doc->manakai_entity_base_uri ($input->{base_uri});
200      print_structure_dump_dom_section ($input, $doc, $el);      print_structure_dump_dom_section ($input, $doc, $el);
201      my $elements = print_structure_error_dom_section      my $elements = print_structure_error_dom_section
202          ($input, $doc, $el, $result);          ($input, $doc, $el, $result, sub {
203              push @subdoc, shift;
204            });
205      print_table_section ($input, $elements->{table}) if @{$elements->{table}};      print_table_section ($input, $elements->{table}) if @{$elements->{table}};
206      print_listing_section ({      print_listing_section ({
207        id => 'identifiers', label => 'IDs', heading => 'Identifiers',        id => 'identifiers', label => 'IDs', heading => 'Identifiers',
# Line 193  sub check_and_print ($$) { Line 212  sub check_and_print ($$) {
212      print_listing_section ({      print_listing_section ({
213        id => 'classes', label => 'Classes', heading => 'Classes',        id => 'classes', label => 'Classes', heading => 'Classes',
214      }, $input, $elements->{class}) if keys %{$elements->{class}};      }, $input, $elements->{class}) if keys %{$elements->{class}};
215      } elsif (defined $cssom) {
216        print_structure_dump_cssom_section ($input, $cssom);
217        ## TODO: CSSOM validation
218        add_error ('structure', {level => 'u'} => $result);
219    } elsif (defined $manifest) {    } elsif (defined $manifest) {
220      print_structure_dump_manifest_section ($input, $manifest);      print_structure_dump_manifest_section ($input, $manifest);
221      print_structure_error_manifest_section ($input, $manifest, $result);      print_structure_error_manifest_section ($input, $manifest, $result);
222    }    }
223    
224      my $id_prefix = 0;
225      for my $subinput (@subdoc) {
226        $subinput->{id_prefix} = 'subdoc-' . ++$id_prefix;
227        $subinput->{nested} = 1;
228        $subinput->{base_uri} = $subinput->{container_node}->base_uri
229            unless defined $subinput->{base_uri};
230        my $ebaseuri = htescape ($subinput->{base_uri});
231        push @nav, ['#' . $subinput->{id_prefix} => 'Sub #' . $id_prefix];
232        print STDOUT qq[<div id="$subinput->{id_prefix}" class=section>
233          <h2>Subdocument #$id_prefix</h2>
234    
235          <dl>
236          <dt>Internet Media Type</dt>
237            <dd><code class="MIME" lang="en">@{[htescape $subinput->{media_type}]}</code>
238          <dt>Container Node</dt>
239            <dd>@{[get_node_link ($input, $subinput->{container_node})]}</dd>
240          <dt>Base <abbr title="Uniform Resource Identifiers">URI</abbr></dt>
241            <dd><code class=URI>&lt;<a href="$ebaseuri">$ebaseuri</a>></code></dd>
242          </dl>];              
243    
244        $subinput->{id_prefix} .= '-';
245        check_and_print ($subinput => $result);
246    
247        print STDOUT qq[</div>];
248      }
249  } # check_and_print  } # check_and_print
250    
251  sub print_http_header_section ($$) {  sub print_http_header_section ($$) {
252    my ($input, $result) = @_;    my ($input, $result) = @_;
253    return unless defined $input->{header_status_code} or    return unless defined $input->{header_status_code} or
254        defined $input->{header_status_text} or        defined $input->{header_status_text} or
255        @{$input->{header_field}};        @{$input->{header_field} or []};
256        
257    push @nav, ['#source-header' => 'HTTP Header'] unless $input->{nested};    push @nav, ['#source-header' => 'HTTP Header'] unless $input->{nested};
258    print STDOUT qq[<div id="$input->{id_prefix}source-header" class="section">    print STDOUT qq[<div id="$input->{id_prefix}source-header" class="section">
# Line 250  sub print_syntax_error_html_section ($$) Line 299  sub print_syntax_error_html_section ($$)
299      my (%opt) = @_;      my (%opt) = @_;
300      my ($type, $cls, $msg) = get_text ($opt{type}, $opt{level});      my ($type, $cls, $msg) = get_text ($opt{type}, $opt{level});
301      if ($opt{column} > 0) {      if ($opt{column} > 0) {
302        print STDOUT qq[<dt class="$cls"><a href="#line-$opt{line}">Line $opt{line}</a> column $opt{column}</dt>\n];        print STDOUT qq[<dt class="$cls"><a href="#$input->{id_prefix}line-$opt{line}">Line $opt{line}</a> column $opt{column}</dt>\n];
303      } else {      } else {
304        $opt{line} = $opt{line} - 1 || 1;        $opt{line} = $opt{line} - 1 || 1;
305        print STDOUT qq[<dt class="$cls"><a href="#line-$opt{line}">Line $opt{line}</a></dt>\n];        print STDOUT qq[<dt class="$cls"><a href="#$input->{id_prefix}line-$opt{line}">Line $opt{line}</a></dt>\n];
306      }      }
307      $type =~ tr/ /-/;      $type =~ tr/ /-/;
308      $type =~ s/\|/%7C/g;      $type =~ s/\|/%7C/g;
# Line 266  sub print_syntax_error_html_section ($$) Line 315  sub print_syntax_error_html_section ($$)
315    
316    my $doc = $dom->create_document;    my $doc = $dom->create_document;
317    my $el;    my $el;
318    my $inner_html_element = $http->get_parameter ('e');    my $inner_html_element = $input->{inner_html_element};
319    if (defined $inner_html_element and length $inner_html_element) {    if (defined $inner_html_element and length $inner_html_element) {
320      $input->{charset} ||= 'windows-1252'; ## TODO: for now.      $input->{charset} ||= 'windows-1252'; ## TODO: for now.
321      my $time1 = time;      my $time1 = time;
# Line 307  sub print_syntax_error_xml_section ($$) Line 356  sub print_syntax_error_xml_section ($$)
356    my $onerror = sub {    my $onerror = sub {
357      my $err = shift;      my $err = shift;
358      my $line = $err->location->line_number;      my $line = $err->location->line_number;
359      print STDOUT qq[<dt><a href="#line-$line">Line $line</a> column ];      print STDOUT qq[<dt><a href="#$input->{id_prefix}line-$line">Line $line</a> column ];
360      print STDOUT $err->location->column_number, "</dt><dd>";      print STDOUT $err->location->column_number, "</dt><dd>";
361      print STDOUT htescape $err->text, "</dd>\n";      print STDOUT htescape $err->text, "</dd>\n";
362    
# Line 334  sub print_syntax_error_xml_section ($$) Line 383  sub print_syntax_error_xml_section ($$)
383    return ($doc, undef);    return ($doc, undef);
384  } # print_syntax_error_xml_section  } # print_syntax_error_xml_section
385    
386    sub get_css_parser () {
387      our $CSSParser;
388      return $CSSParser if $CSSParser;
389    
390      require Whatpm::CSS::Parser;
391      my $p = Whatpm::CSS::Parser->new;
392    
393      $p->{prop}->{$_} = 1 for qw/
394        alignment-baseline
395        background background-attachment background-color background-image
396        background-position background-position-x background-position-y
397        background-repeat border border-bottom border-bottom-color
398        border-bottom-style border-bottom-width border-collapse border-color
399        border-left border-left-color
400        border-left-style border-left-width border-right border-right-color
401        border-right-style border-right-width
402        border-spacing -manakai-border-spacing-x -manakai-border-spacing-y
403        border-style border-top border-top-color border-top-style border-top-width
404        border-width bottom
405        caption-side clear clip color content counter-increment counter-reset
406        cursor direction display dominant-baseline empty-cells float font
407        font-family font-size font-size-adjust font-stretch
408        font-style font-variant font-weight height left
409        letter-spacing line-height
410        list-style list-style-image list-style-position list-style-type
411        margin margin-bottom margin-left margin-right margin-top marker-offset
412        marks max-height max-width min-height min-width opacity -moz-opacity
413        orphans outline outline-color outline-style outline-width overflow
414        overflow-x overflow-y
415        padding padding-bottom padding-left padding-right padding-top
416        page page-break-after page-break-before page-break-inside
417        position quotes right size table-layout
418        text-align text-anchor text-decoration text-indent text-transform
419        top unicode-bidi vertical-align visibility white-space width widows
420        word-spacing writing-mode z-index
421      /;
422      $p->{prop_value}->{display}->{$_} = 1 for qw/
423        block clip inline inline-block inline-table list-item none
424        table table-caption table-cell table-column table-column-group
425        table-header-group table-footer-group table-row table-row-group
426        compact marker
427      /;
428      $p->{prop_value}->{position}->{$_} = 1 for qw/
429        absolute fixed relative static
430      /;
431      $p->{prop_value}->{float}->{$_} = 1 for qw/
432        left right none
433      /;
434      $p->{prop_value}->{clear}->{$_} = 1 for qw/
435        left right none both
436      /;
437      $p->{prop_value}->{direction}->{ltr} = 1;
438      $p->{prop_value}->{direction}->{rtl} = 1;
439      $p->{prop_value}->{marks}->{crop} = 1;
440      $p->{prop_value}->{marks}->{cross} = 1;
441      $p->{prop_value}->{'unicode-bidi'}->{$_} = 1 for qw/
442        normal bidi-override embed
443      /;
444      for my $prop_name (qw/overflow overflow-x overflow-y/) {
445        $p->{prop_value}->{$prop_name}->{$_} = 1 for qw/
446          visible hidden scroll auto -webkit-marquee -moz-hidden-unscrollable
447        /;
448      }
449      $p->{prop_value}->{visibility}->{$_} = 1 for qw/
450        visible hidden collapse
451      /;
452      $p->{prop_value}->{'list-style-type'}->{$_} = 1 for qw/
453        disc circle square decimal decimal-leading-zero
454        lower-roman upper-roman lower-greek lower-latin
455        upper-latin armenian georgian lower-alpha upper-alpha none
456        hebrew cjk-ideographic hiragana katakana hiragana-iroha
457        katakana-iroha
458      /;
459      $p->{prop_value}->{'list-style-position'}->{outside} = 1;
460      $p->{prop_value}->{'list-style-position'}->{inside} = 1;
461      $p->{prop_value}->{'page-break-before'}->{$_} = 1 for qw/
462        auto always avoid left right
463      /;
464      $p->{prop_value}->{'page-break-after'}->{$_} = 1 for qw/
465        auto always avoid left right
466      /;
467      $p->{prop_value}->{'page-break-inside'}->{auto} = 1;
468      $p->{prop_value}->{'page-break-inside'}->{avoid} = 1;
469      $p->{prop_value}->{'background-repeat'}->{$_} = 1 for qw/
470        repeat repeat-x repeat-y no-repeat
471      /;
472      $p->{prop_value}->{'background-attachment'}->{scroll} = 1;
473      $p->{prop_value}->{'background-attachment'}->{fixed} = 1;
474      $p->{prop_value}->{'font-size'}->{$_} = 1 for qw/
475        xx-small x-small small medium large x-large xx-large
476        -manakai-xxx-large -webkit-xxx-large
477        larger smaller
478      /;
479      $p->{prop_value}->{'font-style'}->{normal} = 1;
480      $p->{prop_value}->{'font-style'}->{italic} = 1;
481      $p->{prop_value}->{'font-style'}->{oblique} = 1;
482      $p->{prop_value}->{'font-variant'}->{normal} = 1;
483      $p->{prop_value}->{'font-variant'}->{'small-caps'} = 1;
484      $p->{prop_value}->{'font-stretch'}->{$_} = 1 for
485          qw/normal wider narrower ultra-condensed extra-condensed
486            condensed semi-condensed semi-expanded expanded
487            extra-expanded ultra-expanded/;
488      $p->{prop_value}->{'text-align'}->{$_} = 1 for qw/
489        left right center justify begin end
490      /;
491      $p->{prop_value}->{'text-transform'}->{$_} = 1 for qw/
492        capitalize uppercase lowercase none
493      /;
494      $p->{prop_value}->{'white-space'}->{$_} = 1 for qw/
495        normal pre nowrap pre-line pre-wrap -moz-pre-wrap
496      /;
497      $p->{prop_value}->{'writing-mode'}->{$_} = 1 for qw/
498        lr rl tb lr-tb rl-tb tb-rl
499      /;
500      $p->{prop_value}->{'text-anchor'}->{$_} = 1 for qw/
501        start middle end
502      /;
503      $p->{prop_value}->{'dominant-baseline'}->{$_} = 1 for qw/
504        auto use-script no-change reset-size ideographic alphabetic
505        hanging mathematical central middle text-after-edge text-before-edge
506      /;
507      $p->{prop_value}->{'alignment-baseline'}->{$_} = 1 for qw/
508        auto baseline before-edge text-before-edge middle central
509        after-edge text-after-edge ideographic alphabetic hanging
510        mathematical
511      /;
512      $p->{prop_value}->{'text-decoration'}->{$_} = 1 for qw/
513        none blink underline overline line-through
514      /;
515      $p->{prop_value}->{'caption-side'}->{$_} = 1 for qw/
516        top bottom left right
517      /;
518      $p->{prop_value}->{'table-layout'}->{auto} = 1;
519      $p->{prop_value}->{'table-layout'}->{fixed} = 1;
520      $p->{prop_value}->{'border-collapse'}->{collapse} = 1;
521      $p->{prop_value}->{'border-collapse'}->{separate} = 1;
522      $p->{prop_value}->{'empty-cells'}->{show} = 1;
523      $p->{prop_value}->{'empty-cells'}->{hide} = 1;
524      $p->{prop_value}->{cursor}->{$_} = 1 for qw/
525        auto crosshair default pointer move e-resize ne-resize nw-resize n-resize
526        se-resize sw-resize s-resize w-resize text wait help progress
527      /;
528      for my $prop (qw/border-top-style border-left-style
529                       border-bottom-style border-right-style outline-style/) {
530        $p->{prop_value}->{$prop}->{$_} = 1 for qw/
531          none hidden dotted dashed solid double groove ridge inset outset
532        /;
533      }
534      for my $prop (qw/color background-color
535                       border-bottom-color border-left-color border-right-color
536                       border-top-color border-color/) {
537        $p->{prop_value}->{$prop}->{transparent} = 1;
538        $p->{prop_value}->{$prop}->{flavor} = 1;
539        $p->{prop_value}->{$prop}->{'-manakai-default'} = 1;
540      }
541      $p->{prop_value}->{'outline-color'}->{invert} = 1;
542      $p->{prop_value}->{'outline-color'}->{'-manakai-invert-or-currentcolor'} = 1;
543      $p->{pseudo_class}->{$_} = 1 for qw/
544        active checked disabled empty enabled first-child first-of-type
545        focus hover indeterminate last-child last-of-type link only-child
546        only-of-type root target visited
547        lang nth-child nth-last-child nth-of-type nth-last-of-type not
548        -manakai-contains -manakai-current
549      /;
550      $p->{pseudo_element}->{$_} = 1 for qw/
551        after before first-letter first-line
552      /;
553    
554      return $CSSParser = $p;
555    } # get_css_parser
556    
557    sub print_syntax_error_css_section ($$) {
558      my ($input, $result) = @_;
559    
560      print STDOUT qq[
561    <div id="$input->{id_prefix}parse-errors" class="section">
562    <h2>Parse Errors</h2>
563    
564    <dl>];
565      push @nav, ['#parse-errors' => 'Parse Error'] unless $input->{nested};
566    
567      my $p = get_css_parser ();
568      $p->init;
569      $p->{onerror} = sub {
570        my (%opt) = @_;
571        my ($type, $cls, $msg) = get_text ($opt{type}, $opt{level});
572        if ($opt{token}) {
573          print STDOUT qq[<dt class="$cls"><a href="#$input->{id_prefix}line-$opt{token}->{line}">Line $opt{token}->{line}</a> column $opt{token}->{column}];
574        } else {
575          print STDOUT qq[<dt class="$cls">Unknown location];
576        }
577        if (defined $opt{value}) {
578          print STDOUT qq[ (<code>@{[htescape ($opt{value})]}</code>)];
579        } elsif (defined $opt{token}) {
580          print STDOUT qq[ (<code>@{[htescape (Whatpm::CSS::Tokenizer->serialize_token ($opt{token}))]}</code>)];
581        }
582        $type =~ tr/ /-/;
583        $type =~ s/\|/%7C/g;
584        $msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]];
585        print STDOUT qq[<dd class="$cls">], get_error_level_label (\%opt);
586        print STDOUT qq[$msg</dd>\n];
587    
588        add_error ('syntax', \%opt => $result);
589      };
590      $p->{href} = $input->{uri};
591      $p->{base_uri} = $input->{base_uri};
592    
593    #  if ($parse_mode eq 'q') {
594    #    $p->{unitless_px} = 1;
595    #    $p->{hashless_color} = 1;
596    #  }
597    
598    ## TODO: Make $input->{s} a ref.
599    
600      my $s = \$input->{s};
601      my $charset;
602      unless ($input->{is_char_string}) {
603        require Encode;
604        if (defined $input->{charset}) {## TODO: IANA->Perl
605          $charset = $input->{charset};
606          $s = \(Encode::decode ($input->{charset}, $$s));
607        } else {
608          ## TODO: charset detection
609          $s = \(Encode::decode ($charset = 'utf-8', $$s));
610        }
611      }
612      
613      my $cssom = $p->parse_char_string ($$s);
614      $cssom->manakai_input_encoding ($charset) if defined $charset;
615    
616      print STDOUT qq[</dl></div>];
617    
618      return $cssom;
619    } # print_syntax_error_css_section
620    
621  sub print_syntax_error_manifest_section ($$) {  sub print_syntax_error_manifest_section ($$) {
622    my ($input, $result) = @_;    my ($input, $result) = @_;
623    
# Line 370  sub print_syntax_error_manifest_section Line 654  sub print_syntax_error_manifest_section
654    return $manifest;    return $manifest;
655  } # print_syntax_error_manifest_section  } # print_syntax_error_manifest_section
656    
657  sub print_source_string_section ($$) {  sub print_source_string_section ($$$) {
658    require Encode;    my $input = shift;
659    my $enc = Encode::find_encoding ($_[1]); ## TODO: charset name -> Perl name    my $s;
660    return unless $enc;    unless ($input->{is_char_string}) {
661        require Encode;
662        my $enc = Encode::find_encoding ($_[1]); ## TODO: charset name -> Perl name
663        return unless $enc;
664    
665        $s = \($enc->decode (${$_[0]}));
666      } else {
667        $s = $_[0];
668      }
669    
   my $s = \($enc->decode (${$_[0]}));  
670    my $i = 1;                                my $i = 1;                            
671    push @nav, ['#source-string' => 'Source'] unless $input->{nested};    push @nav, ['#source-string' => 'Source'] unless $input->{nested};
672    print STDOUT qq[<div id="$input->{id_prefix}source-string" class="section">    print STDOUT qq[<div id="$input->{id_prefix}source-string" class="section">
# Line 397  sub print_source_string_section ($$) { Line 688  sub print_source_string_section ($$) {
688    print STDOUT "</ol></div>";    print STDOUT "</ol></div>";
689  } # print_input_string_section  } # print_input_string_section
690    
691  sub print_document_tree ($) {  sub print_document_tree ($$) {
692    my $node = shift;    my ($input, $node) = @_;
693    
694    my $r = '<ol class="xoxo">';    my $r = '<ol class="xoxo">';
695    
696    my @node = ($node);    my @node = ($node);
# Line 496  sub print_structure_dump_dom_section ($$ Line 788  sub print_structure_dump_dom_section ($$
788  <div id="$input->{id_prefix}document-tree" class="section">  <div id="$input->{id_prefix}document-tree" class="section">
789  <h2>Document Tree</h2>  <h2>Document Tree</h2>
790  ];  ];
791    push @nav, ['#document-tree' => 'Tree'] unless $input->{nested};    push @nav, [qq[#$input->{id_prefix}document-tree] => 'Tree']
792          unless $input->{nested};
793    
794    print_document_tree ($el || $doc);    print_document_tree ($input, $el || $doc);
795    
796    print STDOUT qq[</div>];    print STDOUT qq[</div>];
797  } # print_structure_dump_dom_section  } # print_structure_dump_dom_section
798    
799    sub print_structure_dump_cssom_section ($$) {
800      my ($input, $cssom) = @_;
801    
802      print STDOUT qq[
803    <div id="$input->{id_prefix}document-tree" class="section">
804    <h2>Document Tree</h2>
805    ];
806      push @nav, [qq[#$input->{id_prefix}document-tree] => 'Tree']
807          unless $input->{nested};
808    
809      ## TODO:
810      print STDOUT "<pre>".htescape ($cssom->css_text)."</pre>";
811    
812      print STDOUT qq[</div>];
813    } # print_structure_dump_cssom_section
814    
815  sub print_structure_dump_manifest_section ($$) {  sub print_structure_dump_manifest_section ($$) {
816    my ($input, $manifest) = @_;    my ($input, $manifest) = @_;
817    
# Line 510  sub print_structure_dump_manifest_sectio Line 819  sub print_structure_dump_manifest_sectio
819  <div id="$input->{id_prefix}dump-manifest" class="section">  <div id="$input->{id_prefix}dump-manifest" class="section">
820  <h2>Cache Manifest</h2>  <h2>Cache Manifest</h2>
821  ];  ];
822    push @nav, ['#dump-manifest' => 'Caceh Manifest'] unless $input->{nested};    push @nav, [qq[#$input->{id_prefix}dump-manifest] => 'Cache Manifest']
823          unless $input->{nested};
824    
825    print STDOUT qq[<dl><dt>Explicit entries</dt>];    print STDOUT qq[<dl><dt>Explicit entries</dt>];
826      my $i = 0;
827    for my $uri (@{$manifest->[0]}) {    for my $uri (@{$manifest->[0]}) {
828      my $euri = htescape ($uri);      my $euri = htescape ($uri);
829      print STDOUT qq[<dd><code class=uri>&lt;<a href="$euri">$euri</a>></code></dd>];      print STDOUT qq[<dd id="$input->{id_prefix}index-@{[$i++]}"><code class=uri>&lt;<a href="$euri">$euri</a>></code></dd>];
830    }    }
831    
832    print STDOUT qq[<dt>Fallback entries</dt><dd>    print STDOUT qq[<dt>Fallback entries</dt><dd>
# Line 524  sub print_structure_dump_manifest_sectio Line 835  sub print_structure_dump_manifest_sectio
835    for my $uri (sort {$a cmp $b} keys %{$manifest->[1]}) {    for my $uri (sort {$a cmp $b} keys %{$manifest->[1]}) {
836      my $euri = htescape ($uri);      my $euri = htescape ($uri);
837      my $euri2 = htescape ($manifest->[1]->{$uri});      my $euri2 = htescape ($manifest->[1]->{$uri});
838      print STDOUT qq[<tr><td><code class=uri>&lt;<a href="$euri">$euri</a>></code></td>      print STDOUT qq[<tr><td id="$input->{id_prefix}index-@{[$i++]}"><code class=uri>&lt;<a href="$euri">$euri</a>></code></td>
839          <td><code class=uri>&lt;<a href="$euri2">$euri2</a>></code></td>];          <td id="$input->{id_prefix}index-@{[$i++]}"><code class=uri>&lt;<a href="$euri2">$euri2</a>></code></td>];
840    }    }
841    
842    print STDOUT qq[</table><dt>Online whitelist</dt>];    print STDOUT qq[</table><dt>Online whitelist</dt>];
843    for my $uri (@{$manifest->[2]}) {    for my $uri (@{$manifest->[2]}) {
844      my $euri = htescape ($uri);      my $euri = htescape ($uri);
845      print STDOUT qq[<dd><code class=uri>&lt;<a href="$euri">$euri</a>></code></dd>];      print STDOUT qq[<dd id="$input->{id_prefix}index-@{[$i++]}"><code class=uri>&lt;<a href="$euri">$euri</a>></code></dd>];
846    }    }
847    
848    print STDOUT qq[</dl></div>];    print STDOUT qq[</dl></div>];
849  } # print_structure_dump_manifest_section  } # print_structure_dump_manifest_section
850    
851  sub print_structure_error_dom_section ($$$$) {  sub print_structure_error_dom_section ($$$$$) {
852    my ($input, $doc, $el, $result) = @_;    my ($input, $doc, $el, $result, $onsubdoc) = @_;
853    
854    print STDOUT qq[<div id="$input->{id_prefix}document-errors" class="section">    print STDOUT qq[<div id="$input->{id_prefix}document-errors" class="section">
855  <h2>Document Errors</h2>  <h2>Document Errors</h2>
856    
857  <dl>];  <dl>];
858    push @nav, ['#document-errors' => 'Document Error'] unless $input->{nested};    push @nav, [qq[#$input->{id_prefix}document-errors] => 'Document Error']
859          unless $input->{nested};
860    
861    require Whatpm::ContentChecker;    require Whatpm::ContentChecker;
862    my $onerror = sub {    my $onerror = sub {
# Line 562  sub print_structure_error_dom_section ($ Line 874  sub print_structure_error_dom_section ($
874    my $elements;    my $elements;
875    my $time1 = time;    my $time1 = time;
876    if ($el) {    if ($el) {
877      $elements = Whatpm::ContentChecker->check_element ($el, $onerror);      $elements = Whatpm::ContentChecker->check_element
878            ($el, $onerror, $onsubdoc);
879    } else {    } else {
880      $elements = Whatpm::ContentChecker->check_document ($doc, $onerror);      $elements = Whatpm::ContentChecker->check_document
881            ($doc, $onerror, $onsubdoc);
882    }    }
883    $time{check} = time - $time1;    $time{check} = time - $time1;
884    
# Line 580  sub print_structure_error_manifest_secti Line 894  sub print_structure_error_manifest_secti
894  <h2>Document Errors</h2>  <h2>Document Errors</h2>
895    
896  <dl>];  <dl>];
897    push @nav, ['#document-errors' => 'Document Error'] unless $input->{nested};    push @nav, [qq[#$input->{id_prefix}document-errors] => 'Document Error']
898          unless $input->{nested};
899    
900    require Whatpm::CacheManifest;    require Whatpm::CacheManifest;
901    Whatpm::CacheManifest->check_manifest ($manifest, sub {    Whatpm::CacheManifest->check_manifest ($manifest, sub {
# Line 600  sub print_structure_error_manifest_secti Line 915  sub print_structure_error_manifest_secti
915  sub print_table_section ($$) {  sub print_table_section ($$) {
916    my ($input, $tables) = @_;    my ($input, $tables) = @_;
917        
918    push @nav, ['#tables' => 'Tables'] unless $input->{nested};    push @nav, [qq[#$input->{id_prefix}tables] => 'Tables']
919          unless $input->{nested};
920    print STDOUT qq[    print STDOUT qq[
921  <div id="$input->{id_prefix}tables" class="section">  <div id="$input->{id_prefix}tables" class="section">
922  <h2>Tables</h2>  <h2>Tables</h2>
# Line 660  sub print_table_section ($$) { Line 976  sub print_table_section ($$) {
976  sub print_listing_section ($$$) {  sub print_listing_section ($$$) {
977    my ($opt, $input, $ids) = @_;    my ($opt, $input, $ids) = @_;
978        
979    push @nav, ['#' . $opt->{id} => $opt->{label}] unless $input->{nested};    push @nav, ['#' . $input->{id_prefix} . $opt->{id} => $opt->{label}]
980          unless $input->{nested};
981    print STDOUT qq[    print STDOUT qq[
982  <div id="$input->{id_prefix}$opt->{id}" class="section">  <div id="$input->{id_prefix}$opt->{id}" class="section">
983  <h2>$opt->{heading}</h2>  <h2>$opt->{heading}</h2>
# Line 772  sub print_result_unknown_type_section ($ Line 1089  sub print_result_unknown_type_section ($
1089    
1090    my $euri = htescape ($input->{uri});    my $euri = htescape ($input->{uri});
1091    print STDOUT qq[    print STDOUT qq[
1092  <div id="parse-errors" class="section">  <div id="$input->{id_prefix}parse-errors" class="section">
1093  <h2>Errors</h2>  <h2>Errors</h2>
1094    
1095  <dl>  <dl>
# Line 785  sub print_result_unknown_type_section ($ Line 1102  sub print_result_unknown_type_section ($
1102  </dl>  </dl>
1103  </div>  </div>
1104  ];  ];
1105    push @nav, ['#parse-errors' => 'Errors'];    push @nav, [qq[#$input->{id_prefix}parse-errors] => 'Errors']
1106          unless $input->{nested};
1107    add_error (char => {level => 'u'} => $result);    add_error (char => {level => 'u'} => $result);
1108    add_error (syntax => {level => 'u'} => $result);    add_error (syntax => {level => 'u'} => $result);
1109    add_error (structure => {level => 'u'} => $result);    add_error (structure => {level => 'u'} => $result);
# Line 806  sub get_error_label ($$) { Line 1124  sub get_error_label ($$) {
1124    
1125    if (defined $err->{line}) {    if (defined $err->{line}) {
1126      if ($err->{column} > 0) {      if ($err->{column} > 0) {
1127        $r = qq[<a href="#line-$err->{line}">Line $err->{line}</a> column $err->{column}];        $r = qq[<a href="#$input->{id_prefix}line-$err->{line}">Line $err->{line}</a> column $err->{column}];
1128      } else {      } else {
1129        $err->{line} = $err->{line} - 1 || 1;        $err->{line} = $err->{line} - 1 || 1;
1130        $r = qq[<a href="#line-$err->{line}">Line $err->{line}</a>];        $r = qq[<a href="#$input->{id_prefix}line-$err->{line}">Line $err->{line}</a>];
1131      }      }
1132    }    }
1133    
# Line 819  sub get_error_label ($$) { Line 1137  sub get_error_label ($$) {
1137    }    }
1138    
1139    if (defined $err->{index}) {    if (defined $err->{index}) {
1140      $r .= ' ' if length $r;      if (length $r) {
1141      $r .= 'Index ' . (0+$err->{index});        $r .= ', Index ' . (0+$err->{index});
1142        } else {
1143          $r .= "<a href='#$input->{id_prefix}index-@{[0+$err->{index}]}'>Index "
1144              . (0+$err->{index}) . '</a>';
1145        }
1146    }    }
1147    
1148    if (defined $err->{value}) {    if (defined $err->{value}) {
# Line 848  sub get_error_level_label ($) { Line 1170  sub get_error_level_label ($) {
1170    } elsif ($err->{level} eq 'u' or $err->{level} eq 'unsupported') {    } elsif ($err->{level} eq 'u' or $err->{level} eq 'unsupported') {
1171      $r = qq[<strong><a href="../error-description#level-u">Not      $r = qq[<strong><a href="../error-description#level-u">Not
1172          supported</a></strong>: ];          supported</a></strong>: ];
1173      } elsif ($err->{level} eq 'i') {
1174        $r = qq[<strong><a href="../error-description#level-i">Information</a></strong>: ];
1175    } else {    } else {
1176      my $elevel = htescape ($err->{level});      my $elevel = htescape ($err->{level});
1177      $r = qq[<strong><a href="../error-description#level-$elevel">$elevel</a></strong>:      $r = qq[<strong><a href="../error-description#level-$elevel">$elevel</a></strong>:
# Line 1092  EOH Line 1416  EOH
1416      return $r;      return $r;
1417    }    }
1418    
1419      $r->{inner_html_element} = $http->get_parameter ('e');
1420    
1421    return $r;    return $r;
1422  } # get_input_document  } # get_input_document
1423    
# Line 1124  Wakaba <w@suika.fam.cx>. Line 1450  Wakaba <w@suika.fam.cx>.
1450    
1451  =head1 LICENSE  =head1 LICENSE
1452    
1453  Copyright 2007 Wakaba <w@suika.fam.cx>  Copyright 2007-2008 Wakaba <w@suika.fam.cx>
1454    
1455  This library is free software; you can redistribute it  This library is free software; you can redistribute it
1456  and/or modify it under the same terms as Perl itself.  and/or modify it under the same terms as Perl itself.

Legend:
Removed from v.1.33  
changed lines
  Added in v.1.37

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24