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);
14 sub getsetup () { #{{{
19 description => "enable multimarkdown features?",
26 sub htmlize (@) { #{{{
28 my $content = $params{content};
30 if (! defined $markdown_sub) {
31 # Markdown is forked and splintered upstream and can be
32 # available in a variety of forms. Support them all.
34 $blosxom::version="is a proper perl module too much to ask?";
37 if (exists $config{multimarkdown} && $config{multimarkdown}) {
38 eval q{use Text::MultiMarkdown};
40 debug(gettext("multimarkdown is enabled, but Text::MultiMarkdown is not installed"));
43 Text::MultiMarkdown::markdown(shift, {use_metadata => 0});
46 if (! defined $markdown_sub) {
47 eval q{use Text::Markdown};
49 if (Text::Markdown->can('markdown')) {
50 $markdown_sub=\&Text::Markdown::markdown;
53 $markdown_sub=\&Text::Markdown::Markdown;
59 $markdown_sub=\&Markdown::Markdown;
62 do "/usr/bin/markdown" ||
63 error(sprintf(gettext("failed to load Markdown.pm perl module (%s) or /usr/bin/markdown (%s)"), $@, $!));
64 $markdown_sub=\&Markdown::Markdown;
72 # Workaround for perl bug (#376329)
73 $content=Encode::encode_utf8($content);
74 eval {$content=&$markdown_sub($content)};
76 eval {$content=&$markdown_sub($content)};
77 print STDERR $@ if $@;
79 $content=Encode::decode_utf8($content);