6 use HTML
::TokeParser
::Simple
;
7 use HTML
::Entities
qw(decode_entities);
10 my $html_file = shift;
11 my $reader = file
( $html_file )->openr;
13 my $writer = file
( $html_file )->openw;
15 my $parser = HTML
::TokeParser
::Simple
->new( $reader );
17 while( my $token = $parser->get_token ) {
19 my $class_name = $token->get_attr( "class" );
21 if( $token->is_start_tag( "div" )
22 && ( $class_name && $class_name =~ qr/\bexample\b/ )
24 my $start_tag = $token;
25 $start_tag->set_attr( class => $class_name . " synNormal" );
30 while( $token = $parser->get_token ) {
31 if( $token->is_end_tag( "div" ) ) {
36 if( $token->is_text ) {
37 push @content, decode_entities
( $token->as_is );
41 my $code = join "", @content;
43 my $vim = Text
::VimColor
->new(
46 vim_options
=> [qw( -RXZ -i NONE -u NONE -N -n)],
48 my $html = $vim->html;
52 print $writer $start_tag->as_is;
54 my $lines = $html =~ tr/\n/\n/;
56 say $writer "<div class='line_number'>";
57 for my $line ( 0 .. $lines ) {
58 say $writer "<div>",1 + $line,"</div>";
62 print $writer "<div class='content'><pre>";
64 say $writer "</pre></div>";
65 print $writer $end_tag->as_is;
67 print $writer $token->as_is;