]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/mdwn.pm
fairly complete support for outputting html 4.01 instead of xhtml
[git.ikiwiki.info.git] / IkiWiki / Plugin / mdwn.pm
1 #!/usr/bin/perl
2 # Markdown markup language
3 package IkiWiki::Plugin::mdwn;
5 use warnings;
6 use strict;
7 use IkiWiki 2.00;
9 sub import { #{{{
10         hook(type => "htmlize", id => "mdwn", call => \&htmlize);
11 } # }}}
13 my $markdown_sub;
14 sub htmlize (@) { #{{{
15         my %params=@_;
16         my $content = $params{content};
18         if (! defined $markdown_sub) {
19                 # Markdown is forked and splintered upstream and can be
20                 # available in a variety of incompatible forms. Support
21                 # them all.
22                 no warnings 'once';
23                 $blosxom::version="is a proper perl module too much to ask?";
24                 use warnings 'all';
26                 eval q{use Markdown};
27                 if (! $@) {
28                         $markdown_sub=\&Markdown::Markdown;
29                         $Markdown::g_empty_element_suffix=">"; # HTML output
30                 }
31                 else {
32                         eval q{use Text::Markdown};
33                         if (! $@) {
34                                 $markdown_sub=\&Text::Markdown::Markdown;
35                                 $Text::Markdown::g_empty_element_suffix=">"; # HTML output
36                         }
37                         else {
38                                 do "/usr/bin/markdown" ||
39                                         error(sprintf(gettext("failed to load Markdown.pm perl module (%s) or /usr/bin/markdown (%s)"), $@, $!));
40                                 $markdown_sub=\&Markdown::Markdown;
41                                 $Markdown::g_empty_element_suffix=">"; # HTML output
42                         }
43                 }
44                 require Encode;
45         }
46         
47         # Workaround for perl bug (#376329)
48         $content=Encode::encode_utf8($content);
49         $content=Encode::encode_utf8($content);
50         $content=&$markdown_sub($content);
51         $content=Encode::decode_utf8($content);
52         $content=Encode::decode_utf8($content);
54         return $content;
55 } # }}}
57 1