2 # Markdown markup language
3 package IkiWiki::Plugin::mdwn;
10 hook(type => "getsetup", id => "mdwn", call => \&getsetup);
11 hook(type => "htmlize", id => "mdwn", call => \&htmlize);
18 rebuild => 1, # format plugin
23 description => "enable multimarkdown features?",
32 my $content = $params{content};
34 if (! defined $markdown_sub) {
35 # Markdown is forked and splintered upstream and can be
36 # available in a variety of forms. Support them all.
38 $blosxom::version="is a proper perl module too much to ask?";
41 if (exists $config{multimarkdown} && $config{multimarkdown}) {
42 eval q{use Text::MultiMarkdown};
44 debug(gettext("multimarkdown is enabled, but Text::MultiMarkdown is not installed"));
47 Text::MultiMarkdown::markdown(shift, {use_metadata => 0});
50 if (! defined $markdown_sub) {
51 eval q{use Text::Markdown};
53 if (Text::Markdown->can('markdown')) {
54 $markdown_sub=\&Text::Markdown::markdown;
57 $markdown_sub=\&Text::Markdown::Markdown;
63 $markdown_sub=\&Markdown::Markdown;
66 do "/usr/bin/markdown" ||
67 error(sprintf(gettext("failed to load Markdown.pm perl module (%s) or /usr/bin/markdown (%s)"), $@, $!));
68 $markdown_sub=\&Markdown::Markdown;
76 # Workaround for perl bug (#376329)
77 $content=Encode::encode_utf8($content);
78 eval {$content=&$markdown_sub($content)};
80 eval {$content=&$markdown_sub($content)};
81 print STDERR $@ if $@;
83 $content=Encode::decode_utf8($content);