]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/mdwn.pm
* Deal with CPAN installing Markdown as Text::Markdown, while it's
[ikiwiki.git] / IkiWiki / Plugin / mdwn.pm
1 #!/usr/bin/perl
2 # Markdown markup language
3 package IkiWiki::Plugin::mdwn;
4
5 use warnings;
6 use strict;
7 use IkiWiki;
8
9 sub import { #{{{
10         hook(type => "htmlize", id => "mdwn", call => \&htmlize);
11 } # }}}
12
13 my $markdown_loaded=0;
14 sub htmlize (@) { #{{{
15         my %params=@_;
16         my $content = $params{content};
17
18         if (! $markdown_loaded) {
19                 # Note: This hack to make markdown run as a proper perl
20                 # module. A proper perl module is available in Debian
21                 # for markdown, but not upstream yet.
22                 no warnings 'once';
23                 $blosxom::version="is a proper perl module too much to ask?";
24                 use warnings 'all';
25
26                 eval q{use Markdown};
27                 if ($@) {
28                         eval q{use Text::Markdown};
29                         if ($@) {
30                                 do "/usr/bin/markdown" ||
31                                         error("failed to load Markdown.pm perl module ($@) or /usr/bin/markdown ($!)");
32                         }
33                 }
34                 $markdown_loaded=1;
35                 require Encode;
36         }
37         
38         # Workaround for perl bug (#376329)
39         $content=Encode::encode_utf8($content);
40         $content=Encode::encode_utf8($content);
41         $content=Markdown::Markdown($content);
42         $content=Encode::decode_utf8($content);
43         $content=Encode::decode_utf8($content);
44
45         return $content;
46 } # }}}
47
48 1