| 1 | #$Id:$ | ||
| 2 | package Template::Plugin::VimColor; | ||
| 3 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 2 | ▶ | use base qw (Template::Plugin::Filter); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 0 | ▶ | use Text::VimColor; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 8 | |||
| 9 | our $VERSION = 0.01; | ||
| 10 | |||
| 11 | sub init { | ||
| 12 | my $self = shift; | ||
| 13 | $self->{_DYNAMIC} = 1; | ||
| 14 | $self->install_filter($self->{_ARGS}->[0] || 'vimcolor'); | ||
| 15 | $self; | ||
| 16 | } | ||
| 17 | |||
| 18 | sub filter { | ||
| 19 | my ($self, $text, $args, $config) = @_; | ||
| 20 | my $filetype = delete $config->{filetype} || 'perl'; | ||
| 21 | my $syntax = Text::VimColor->new( | ||
| 22 | string => \$text, | ||
| 23 | filetype => $filetype, | ||
| 24 | %$config, | ||
| 25 | ); | ||
| 26 | |||
| 27 | my $output = $syntax->html; | ||
| 28 | $output = _numbered(\$output) if $config->{set_number}; | ||
| 29 | return $output; | ||
| 30 | } | ||
| 31 | |||
| 32 | sub _numbered { | ||
| 33 | my $textref = shift; | ||
| 34 | my $ret = ''; | ||
| 35 | my $cur_line = 0; | ||
| 36 | $ret .= sprintf qq{<span class="synLinenum">%5d</span> %s\n}, ++$cur_line, $_ | ||
| 37 | for split /(?:\r\n|\r|\n)/, $$textref; | ||
| 38 | $ret; | ||
| 39 | } | ||
| 40 | |||
| 41 | 1; | ||
| 42 | __END__ | ||