4 # File ID: d7733f9c-7c0d-11df-aac0-90e6ba3022ac
10 use HTML
::TreeBuilder
;
13 @ARGV = "-" unless @ARGV;
15 my %SEEN = map { $_, 1 } qw(header comment :html);
16 my %KNOWN = map { $_, 1 } CGI
::expand_tags
(":html"); # CHEAT
19 my $h = HTML
::TreeBuilder
->new;
20 $h->parse_file(shift);
21 $h->traverse(\
&walker
);
23 print "use CGI ", S
("-no_debug", sort keys %SEEN), ";\nprint header,\n";
34 s/([^ !#%-?A-~])/sprintf "\\x%02x", ord $1/ge;
39 BEGIN { # scope for static local
49 ($put_buffer."", $put_buffer = "")[0];
54 my ($open, $hr, $close) = @_;
55 my @attrs = sort grep !/^_/, keys %$hr;
59 join(", ", map { S
($_)." => ".S
($hr->{$_}) } @attrs),
64 BEGIN { # scope for static local
68 my ($node, $start, $depth) = @_;
71 return 1 if $tag eq "html";
73 $head_attrs = get_attrs_from
($node);
76 $tag = ucfirst $tag if index(" select tr link delete ", " $tag ") >= 0;
81 dumpattrs
"(", $head_attrs, ")";
88 $SEEN{$tag}++ unless $KNOWN{$tag};
91 dumpattrs
"{", $node, "}, "; # CHEAT
93 if (not $start or $HTML::Element
::emptyElement
{lc $tag}) { # CHEAT
94 put S
(" ") if not $start and $node->is_empty;
98 put
" " x
$depth, S
($node), ", ";
101 return 1; # yes, recurse
108 for my $first (@
{$node->content}) {
109 next unless ref $first; # invalid content
110 my $tag = $first->tag;
111 if ($tag eq "title") {
112 $return{"-title"} = join " ", @
{$first->content};
115 warn "## unknown head tag: ".($first->as_HTML);
120 sub HTML
::TreeBuilder
::comment
{ # CHEAT
122 my $pos = $self->{'_pos'};
123 $pos = $self unless defined($pos);
124 my $ele = HTML
::Element
->new('comment');
125 $ele->push_content(shift);
126 $pos->push_content($ele);