#!/usr/bin/perl --
use strict; use warnings;
use PPI;
use PPI::HTML;
use Term::ANSIColor::Markup;
use Win32::Console::ANSI;
exit print colorme( " use PPI;\n use PPI::HTML;\n \n # Load your Perl file\n my \$Document = PPI::Document->new( __FILE__ );\n \n # Create a reusable syntax highlighter\n my \$Highlight = PPI::HTML->new( line_numbers => 1 );\n \n # Spit out the HTML\n print \$Highlight->html( \$Document );\n ", );
#~ exit Pod::Perldoc::ToTermPPIHTML->new->parse_from_file ( __FILE__ );
exit print self_to_html();
sub self_to_html {
use PPI;
use PPI::HTML;
# Load your Perl file
my $Document = PPI::Document->new( __FILE__ );
# Create a reusable syntax highlighter
my $Highlight = PPI::HTML->new( line_numbers => 1 );
# Spit out the HTML
return join '', $Highlight->html( $Document );
}
sub colorme {
use PPI;
use PPI::HTML;
use Term::ANSIColor::Markup;
# Load your Perl file
my $Document = PPI::Document->new( \$_[0] );
# Create a reusable syntax highlighter
my $Highlight = PPI::HTML->new( line_numbers => 0 );
# Spit out the HTML
#~ return join '', $Highlight->html( $Document );
my $html = join '', $Highlight->html( $Document );
$html =~ s/
//g;
#~ $html =~ s{(.*?)}{<$1>$2$1>}gs;
our %color = (
####
# Standard token classes
pod => '#008080',
comment => '#008080',
operator => '#DD7700',
single => '#999999',
double => '#999999',
literal => '#999999',
interpolate => '#999999',
words => '#999999',
regex => '#9900FF',
match => '#9900FF',
substitute => '#9900FF',
transliterate => '#9900FF',
number => '#990000',
magic => '#0099FF',
cast => '#339999',
# Special classes
pragma => '#990000',
keyword => '#0000FF',
core => '#FF0000',
line_number => '#666666',
comment => 'green',
keyword => 'blue',
symbol => 'pink',
word => 'black',
structure => 'black',
operator => 'black',
);
sub yoCo {
my( $colo, $text ) = @_;
#~ $colo = $color{$colo}||$colo;
#~ $colo = $color{$colo} || do{ warn $colo; $colo; };
#~ $colo = $color{$colo} || 'black';
$colo = $color{$colo} ;
$colo or return $text;
return "<$colo>$text$colo>";
}
#~ $html =~ s{(.*?)}{<$color{$1}>$2$color{$1}>}gs;
$html =~ s{(.*?)}{yoCo($1,$2);}gse;
#~ return $html;
return Term::ANSIColor::Markup->colorize($html);
}
package Pod::Perldoc::ToTermPPIHTML;
use parent qw/ Pod::Perldoc::ToTerm /;
sub parse_from_file {
my $self = shift;
local *Pod::Text::cmd_verbatim = *my_cmd_verbatim; ## necessity ## typing
$self->SUPER::parse_from_file( @_ );
}
# Handle a verbatim paragraph. Just print it out, but indent it according to
# our margin.
sub my_cmd_verbatim {
my ($self, $attrs, $text) = @_;
$self->item if defined $$self{ITEM};
return if $text =~ /^\s*$/;
#~ ::dd( -verbatim , $text ); ## YAY
$text =~ s/^(\n*)([ \t]*\S+)/$1 . (' ' x $$self{MARGIN}) . $2/gme;
$text =~ s/\s*$/\n\n/;
$self->output ($text);
return '';
}
__END__
=pod
=head1 USE IT OR LOSE IT
I B C F to you!
use PPI;
use PPI::HTML;
# Load your Perl file
my $Document = PPI::Document->new( __FILE__ );
# Create a reusable syntax highlighter
my $Highlight = PPI::HTML->new( line_numbers => 1 );
# Spit out the HTML
print $Highlight->html( $Document );
=cut