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, longname => "Markdown");
18 rebuild => 1, # format plugin
24 description => "enable multimarkdown features?",
33 my $content = $params{content};
35 if (! defined $markdown_sub) {
36 # Markdown is forked and splintered upstream and can be
37 # available in a variety of forms. Support them all.
39 $blosxom::version="is a proper perl module too much to ask?";
42 if (exists $config{multimarkdown} && $config{multimarkdown}) {
43 eval q{use Text::MultiMarkdown};
45 debug(gettext("multimarkdown is enabled, but Text::MultiMarkdown is not installed"));
49 Text::MultiMarkdown::markdown(shift, {use_metadata => 0});
53 if (! defined $markdown_sub) {
54 eval q{use Text::Markdown::Discount};
57 # Workaround for discount binding bug
58 # https://rt.cpan.org/Ticket/Display.html?id=73657
59 return "" if $_[0]=~/^\s*$/;
60 Text::Markdown::Discount::markdown(@_);
64 if (! defined $markdown_sub) {
65 eval q{use Text::Markdown};
67 if (Text::Markdown->can('markdown')) {
68 $markdown_sub=\&Text::Markdown::markdown;
71 $markdown_sub=\&Text::Markdown::Markdown;
77 $markdown_sub=\&Markdown::Markdown;
80 do "/usr/bin/markdown" ||
81 error(sprintf(gettext("failed to load Markdown.pm perl module (%s) or /usr/bin/markdown (%s)"), $@, $!));
82 $markdown_sub=\&Markdown::Markdown;
90 # Workaround for perl bug (#376329)
91 $content=Encode::encode_utf8($content);
92 eval {$content=&$markdown_sub($content)};
94 eval {$content=&$markdown_sub($content)};
95 print STDERR $@ if $@;
97 $content=Encode::decode_utf8($content);