OddMuse Syntax Highlight

I needed a simple syntax highlighter for OddMuse - here is my first attempt:

use Syntax::Highlight::Engine::Kate;

push(@MyRules, \&PreRule);
$RuleOrder{\&PreRule} = -20;

my $syntax_hl = new Syntax::Highlight::Engine::Kate(
        language => 'Perl',
        substitutions => {
                # Not required - already done by Oddmuse
                "<" => "&lt;",
                ">" => "&gt;",
                "&" => "&amp;",
                # Not required - using pre format text !
                #" " => "&nbsp;",
                #"\t" => "&nbsp;&nbsp;&nbsp;",
                #"\n" => "<br/>\n",
        },
        format_table => {
                Alert => ["<font color=\"#0000ff\">", "</font>"],
                BaseN => ["<font color=\"#007f00\">", "</font>"],
                BString => ["<font color=\"#c9a7ff\">", "</font>"],
                Char => ["<font color=\"#ff00ff\">", "</font>"],
                Comment => ["<font color=\"#7f7f7f\"><i>", "</i></font>"],
                DataType => ["<font color=\"#0000ff\">", "</font>"],
                DecVal => ["<font color=\"#00007f\">", "</font>"],
                Error => ["<font color=\"#ff0000\"><b><i>", "</i></b></font>"],
                Float => ["<font color=\"#00007f\">", "</font>"],
                Function => ["<font color=\"#007f00\">", "</font>"],
                IString => ["<font color=\"#ff0000\">", "<//font>"],
                Keyword => ["<b>", "</b>"],
                Normal => ["", ""],
                Operator => ["<font color=\"#ffa500\">", "</font>"],
                Others => ["<font color=\"#b03060\">", "</font>"],
                RegionMarker => ["<font color=\"#96b9ff\"><i>", "</i></font>"],
                Reserved => ["<font color=\"#9b30ff\"><b>", "</b></font>"],
                String => ["<font color=\"#ff0000\">", "</font>"],
                Variable => ["<font color=\"#0000ff\"><b>", "</b></font>"],
                Warning => ["<font color=\"#0000ff\"><b><i>", "</b></i></font>"],
        },
);

sub PreRule {
        if (m/\G\{\{\{#!([A-Za-z]+)\n?(.*?\n)\}\}\}[ \t]*\n?/cgs) {
                my $lang = $1;
                my $content = $2;

                if ($syntax_hl->languagePlug($lang)) {
                        $syntax_hl->language($lang);
                        $content =~ s/gt;/>/g;          # XXX Is this right?
                        $content =~ s/lt;/</g;
                        $content =~ s/&amp;/&/g;
                        return '<pre class="real">'
                                . $syntax_hl->highlightText($content)
                                . '</pre>';
                }
                else {
                        return '<pre class="real">'
                                . $content
                                . '</pre>';
                }
        }
        return undef;
}

See also