#$Id:$ package Template::Plugin::VimColor; use strict; use warnings; use base qw (Template::Plugin::Filter); use Text::VimColor; our $VERSION = 0.01; sub init { my $self = shift; $self->{_DYNAMIC} = 1; $self->install_filter($self->{_ARGS}->[0] || 'vimcolor'); $self; } sub filter { my ($self, $text, $args, $config) = @_; my $filetype = delete $config->{filetype} || 'perl'; my $syntax = Text::VimColor->new( string => \$text, filetype => $filetype, %$config, ); my $output = $syntax->html; $output = _numbered(\$output) if $config->{set_number}; return $output; } sub _numbered { my $textref = shift; my $ret = ''; my $cur_line = 0; $ret .= sprintf qq{%5d %s\n}, ++$cur_line, $_ for split /(?:\r\n|\r|\n)/, $$textref; $ret; } 1; __END__ =head1 NAME Template::Plugin::VimColor - TT plugin for Text::VimColor =head1 SYNOPSIS // in your template [% USE VimColor %]
[% FILTER vimcolor set_number => 1 -%] #!/usr/local/bin/perl use strict; use warnings; print "Hello, World!\n"; [% END -%]// for another language
[% FILTER vimcolor filetype => 'ruby' -%] #!/usr/local/bin/ruby puts "Hello, World"; [% END -%]=head1 DESCRIPTION This plugin allows you to mark up your code in your document with VimColor style. You probably need to define styles for marked strings like this, =head1 SEE ALSO L, L