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?",
31 description => "disable use of markdown discount?",
40 my $content = $params{content};
42 if (! defined $markdown_sub) {
43 # Markdown is forked and splintered upstream and can be
44 # available in a variety of forms. Support them all.
46 $blosxom::version="is a proper perl module too much to ask?";
49 if (exists $config{multimarkdown} && $config{multimarkdown}) {
50 eval q{use Text::MultiMarkdown};
52 debug(gettext("multimarkdown is enabled, but Text::MultiMarkdown is not installed"));
56 Text::MultiMarkdown::markdown(shift, {use_metadata => 0});
60 if (! defined $markdown_sub &&
61 (! exists $config{nodiscount} || ! $config{nodiscount})) {
62 eval q{use Text::Markdown::Discount};
66 # Workaround for discount binding bug
67 # https://rt.cpan.org/Ticket/Display.html?id=73657
68 return "" if $t=~/^\s*$/;
69 # Workaround for discount's eliding
71 # https://rt.cpan.org/Ticket/Display.html?id=74016
72 $t=~s/<style/<elyts/ig;
73 my $r=Text::Markdown::Discount::markdown($t);
74 $r=~s/<elyts/<style/ig;
79 if (! defined $markdown_sub) {
80 eval q{use Text::Markdown};
82 if (Text::Markdown->can('markdown')) {
83 $markdown_sub=\&Text::Markdown::markdown;
86 $markdown_sub=\&Text::Markdown::Markdown;
92 $markdown_sub=\&Markdown::Markdown;
96 do "/usr/bin/markdown" ||
97 error(sprintf(gettext("failed to load Markdown.pm perl module (%s) or /usr/bin/markdown (%s)"), $error, $!));
98 $markdown_sub=\&Markdown::Markdown;
106 # Workaround for perl bug (#376329)
107 $content=Encode::encode_utf8($content);
108 eval {$content=&$markdown_sub($content)};
110 eval {$content=&$markdown_sub($content)};
111 print STDERR $@ if $@;
113 $content=Encode::decode_utf8($content);