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");
12 hook(type => "htmlize", id => "md", call => \&htmlize, longname => "Markdown (popular file extension)", nocreate => 1);
19 rebuild => 1, # format plugin
25 description => "enable multimarkdown features?",
32 description => "disable use of markdown discount?",
41 my $content = $params{content};
43 if (! defined $markdown_sub) {
44 # Markdown is forked and splintered upstream and can be
45 # available in a variety of forms. Support them all.
47 $blosxom::version="is a proper perl module too much to ask?";
50 if (exists $config{multimarkdown} && $config{multimarkdown}) {
51 eval q{use Text::MultiMarkdown};
53 debug(gettext("multimarkdown is enabled, but Text::MultiMarkdown is not installed"));
57 Text::MultiMarkdown::markdown(shift, {use_metadata => 0});
61 if (! defined $markdown_sub &&
62 (! exists $config{nodiscount} || ! $config{nodiscount})) {
63 eval q{use Text::Markdown::Discount};
67 # Workaround for discount binding bug
68 # https://rt.cpan.org/Ticket/Display.html?id=73657
69 return "" if $t=~/^\s*$/;
70 # Workaround for discount's eliding
72 # https://rt.cpan.org/Ticket/Display.html?id=74016
73 $t=~s/<style/<elyts/ig;
74 my $r=Text::Markdown::Discount::markdown($t);
75 $r=~s/<elyts/<style/ig;
80 if (! defined $markdown_sub) {
81 eval q{use Text::Markdown};
83 if (Text::Markdown->can('markdown')) {
84 $markdown_sub=\&Text::Markdown::markdown;
87 $markdown_sub=\&Text::Markdown::Markdown;
93 $markdown_sub=\&Markdown::Markdown;
97 do "/usr/bin/markdown" ||
98 error(sprintf(gettext("failed to load Markdown.pm perl module (%s) or /usr/bin/markdown (%s)"), $error, $!));
99 $markdown_sub=\&Markdown::Markdown;
107 # Workaround for perl bug (#376329)
108 $content=Encode::encode_utf8($content);
109 eval {$content=&$markdown_sub($content)};
111 eval {$content=&$markdown_sub($content)};
112 print STDERR $@ if $@;
114 $content=Encode::decode_utf8($content);