]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/mdwn.pm
important robustness fix
[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         IkiWiki::hook(type => "htmlize", id => "mdwn", call => \&htmlize);
11 } # }}}
12
13 my $markdown_loaded=0;
14 sub htmlize ($) { #{{{
15         my $content = shift;
16
17         if (! $markdown_loaded) {
18                 # Note: This hack to make markdown run as a proper perl
19                 # module. A proper perl module is available in Debian
20                 # for markdown, but not upstream yet.
21                 no warnings 'once';
22                 $blosxom::version="is a proper perl module too much to ask?";
23                 use warnings 'all';
24
25                 eval q{use Markdown};
26                 if ($@) {
27                         do "/usr/bin/markdown" ||
28                                 IkiWiki::error("failed to load Markdown.pm perl module ($@) or /usr/bin/markdown ($!)");
29                 }
30                 $markdown_loaded=1;
31                 require Encode;
32         }
33         
34         # Workaround for perl bug (#376329)
35         $content=Encode::encode_utf8($content);
36         $content=Encode::encode_utf8($content);
37         $content=Markdown::Markdown($content);
38         $content=Encode::decode_utf8($content);
39         $content=Encode::decode_utf8($content);
40
41         return $content;
42 } # }}}
43
44 1