--- mtcolorer.pl.orig 2006-03-10 18:48:32.000000000 -0600 +++ mtcolorer.pl 2006-03-10 18:46:19.000000000 -0600 @@ -1,5 +1,5 @@ # --------------------------------------------------------------------------- -# MT-Colorer +# MT-Colorer # A plugin for Movable Type # # Release 1.0.0 @@ -11,66 +11,70 @@ # You may use it for commercial or personal use. # If you distribute it, please keep this notice intact. # -# Copyright (c) 2006 -# --------------------------------------------------------------------------- +# Copyright (c) 2006 +# --------------------------------------------------------------------------- +# +# Additional Changes: +# +# 10-Mar-2006 - minor fixes/clean-up work Jordan Husney +# package MT::Plugin::Colorer; use Syntax::Highlight::Universal; use strict; use MT; -use MT::Entry; -use MT::Plugin; +use MT::Plugin; use MT::Template::Context; -use MT::WeblogPublisher; -my $highlighter = Syntax::Highlight::Universal->new(); -my $plugin = new MT::Plugin(); -$plugin->name("MT Colorer"); -$plugin->description('Source code hightlighter based on Colorer (http://colorer.sf.net)'); -$plugin->doc_link('http://klim.doslash.org/projects/mtcolorer'); -$plugin->author_name('Vladimir Klimontovich'); +my $highlighter = Syntax::Highlight::Universal->new(); +my $plugin = new MT::Plugin(); +$plugin->name("MT Colorer"); +$plugin->description('Source code hightlighter based on Colorer (http://colorer.sf.net)'); +$plugin->doc_link('http://klim.doslash.org/projects/mtcolorer'); +$plugin->author_name('Vladimir Klimontovich'); $plugin->author_link('http://klim.doslash.org/eng_index.shtml'); $plugin->plugin_link('http://klim.doslash.org/projects/mtcolorer'); -$plugin->version("0.2"); +$plugin->version("0.2-jrh"); +MT->add_plugin($plugin); MT->add_callback("BuildPage", 1, $plugin, \&hightlight_text); -MT->add_plugin($plugin); - -sub trim -{ - my($string)=@_; - for ($string) - { - s/^\s+//; - s/\s+$//; - } - return $string; +sub trim +{ + my($string)=@_; + for ($string) + { + s/^\s+//; + s/\s+$//; + } + return $string; } sub hightlight_block -{ - my ($lang, $source) = @_; - my $htext = $highlighter->highlight($lang, $source); +{ + my ($lang, $source) = @_; + my $htext = $highlighter->highlight($lang, $source); $htext = trim($htext); return "
".$htext."
"; -} +} sub hightlight_inline -{ - my ($lang, $source) = @_; - my $htext = $highlighter->highlight($lang, $source); +{ + my ($lang, $source) = @_; + my $htext = $highlighter->highlight($lang, $source); $htext = trim($htext); return "".$htext.""; -} - -sub hightlight_text -{ +} + +sub hightlight_text +{ my ($cb, %args) = @_; - use Data::Dumper; my $html = ${$args{'Content'}}; + $html =~ s/]*?)lang="([^"]+?)"([^>]*?)>(.*?)<\/mtc:block>/hightlight_block($2,$4)/ges; $html =~ s/]*?)lang="([^"]+?)"([^>]*?)>(.*?)<\/mtc:inline>/hightlight_inline($2,$4)/ges; - ${$args{'Content'}} = $html; - return 1; + ${$args{'Content'}} = $html; + + return 1; } +1;