とりあえず Text-Hatena-0.20 をスーパーpre記法(+シンタックス・ハイライト)に対応させる

追記:reedomさんが更に改良したパッチを公開されています.ご指摘ありがとう.

こんなパッチでどうか.

--- lib/Text/Hatena.pm.orig	2007-02-28 05:03:52.000000000 +0900
+++ lib/Text/Hatena.pm	2007-06-18 13:03:50.000000000 +0900
@@ -6,8 +6,10 @@
 use vars qw($VERSION);
 use Parse::RecDescent;
 use Text::Hatena::AutoLink;
+use HTML::Entities ();
+use Text::VimColor;
 
-$VERSION = '0.20';
+$VERSION = '0.20_1';
 
 my ($parser, $syntax);
 
@@ -39,7 +41,7 @@
     dl_item    : "\n:" inline[term => ':'](s) ':' inline(s)
     list       : list_item[level => $arg{level} || 1](s)
     list_item  : "\n" /[+-]{$arg{level}}/ inline(s) list[level => $arg{level} + 1](?)
-    super_pre  : /\n>\|(\w*)\|/o text_line(s) "\n||<" ..."\n"
+    super_pre  : "\n>|" /\w*/ "|" text_line(s) "\n||<" ..."\n"
     text_line  : ...!"\n||<\n" "\n" /[^\n]*/o
     pre        : "\n>|" pre_line(s) "\n|<" ..."\n"
     pre_line   : ...!"\n|<" "\n" inline(s?)
@@ -209,9 +211,11 @@
 sub super_pre {
     my $class = shift;
     my $items = shift->{items};
-    my $filter = $1 || ''; # todo
-    my $texts = $class->expand($items->[1]);
-    return "<pre>\n$texts</pre>\n";
+    my $texts = $class->expand($items->[3]);
+    if (my $filter = $items->[1]) {
+        $texts = Text::VimColor->new(string => $texts, filetype => $filter)->html;
+    }
+    return qq!<pre class="hatena-super-pre">\n$texts</pre>\n!;
 }
 
 sub pre {
@@ -266,7 +270,7 @@
 
 sub text_line {
     my $class = shift;
-    my $text = shift->{items}->[2];
+    my $text = HTML::Entities::encode_entities(shift->{items}->[2], '<>&"');
     return "$text\n";
 }