#!/usr/bin/perl # # syntax_highlight -- A Perl-to-HTML conversion tool for web writers # # Copyright (c) 2005 Byrne Reese # package SyntaxHighlight; require 5.006_000; use strict; use warnings; use vars qw($VERSION); $VERSION = '1.0'; require MT; require MT::Template::Context; require MT::Plugin; import MT::Plugin; my $plugin = new MT::Plugin({ name => "Syntax Highlighter", version => $VERSION, description => "A code-to-HTML formatting plugin.", # doc_link => 'http://daringfireball.net/projects/markdown/' }); MT->add_plugin( $plugin ); MT->add_text_filter('syntaxhighlight' => { label => 'Syntax Highlighter', # docs => 'http://daringfireball.net/projects/markdown/', on_format => sub { my $text = shift; my $ctx = shift; # my $raw = 0; # if (defined $ctx) { # my $output = $ctx->stash('markdown_output'); # if (defined $output && $output =~ m/^html/i) { # $g_empty_element_suffix = ">"; # $ctx->stash('markdown_output', ''); # } # elsif (defined $output && $output eq 'raw') { # $raw = 1; # $ctx->stash('markdown_output', ''); # } # else { # $raw = 0; # $g_empty_element_suffix = " />"; # } # } # $text = $raw ? $text : Highlight($text); $text = Highlight($text); $text; }, }); sub Highlight { my ($text) = @_; require Beautifier::Core; require HFile::HFile_perl; require Output::HTML; my $highlighter = new Beautifier::Core(new HFile::HFile_perl, new Output::HTML); return $highlighter->highlight_text($text); }