restructure configure so pkg-config derived SSL flags get used
[rofl0r-ixchat.git] / plugins / perl / syntax_highlight
blob96d570036c3e80ee88fa697e64380b12d7f073f0
1 #!/usr/bin/env perl
2 use 5.010;
3 use strict;
4 use warnings;
5 use Text::VimColor;
6 use HTML::TokeParser::Simple;
7 use HTML::Entities qw(decode_entities);
8 use Path::Class;
10 my $html_file = shift;
11 my $reader = file( $html_file )->openr;
12 unlink $html_file;
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/ )
23 ) {
24 my $start_tag = $token;
25 $start_tag->set_attr( class => $class_name . " synNormal" );
26 my @content;
27 my $end_tag;
29 EXAMPLE:
30 while( $token = $parser->get_token ) {
31 if( $token->is_end_tag( "div" ) ) {
32 $end_tag = $token;
33 last EXAMPLE;
36 if( $token->is_text ) {
37 push @content, decode_entities( $token->as_is );
41 my $code = join "", @content;
42 # say $code;
43 my $vim = Text::VimColor->new(
44 string => $code,
45 filetype => "perl",
46 vim_options => [qw( -RXZ -i NONE -u NONE -N -n)],
48 my $html = $vim->html;
49 $html =~ s/^\s+//;
50 $html =~ s/\s+$//;
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>";
60 say $writer "</div>";
62 print $writer "<div class='content'><pre>";
63 say $writer $html;
64 say $writer "</pre></div>";
65 print $writer $end_tag->as_is;
66 } else {
67 print $writer $token->as_is;