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};
68 # Workaround for discount binding bug
69 # https://rt.cpan.org/Ticket/Display.html?id=73657
70 return "" if $t=~/^\s*$/;
74 # Disable Pandoc-style % Title, % Author, % Date
75 # Use the meta plugin instead
76 $flags |= Text::Markdown::Discount::MKD_NOHEADER();
78 # Disable Unicodification of quote marks, em dashes...
79 # Use the typography plugin instead
80 $flags |= Text::Markdown::Discount::MKD_NOPANTS();
82 # Workaround for discount's eliding
84 # https://rt.cpan.org/Ticket/Display.html?id=74016
85 if (Text::Markdown::Discount->can("MKD_NOSTYLE")) {
86 $flags |= Text::Markdown::Discount::MKD_NOSTYLE();
89 # This is correct for the libmarkdown.so.2 ABI
93 return Text::Markdown::Discount::markdown($t, $flags);
97 if (! defined $markdown_sub) {
98 eval q{use Text::Markdown};
100 if (Text::Markdown->can('markdown')) {
101 $markdown_sub=\&Text::Markdown::markdown;
104 $markdown_sub=\&Text::Markdown::Markdown;
108 eval q{use Markdown};
110 $markdown_sub=\&Markdown::Markdown;
114 do "/usr/bin/markdown" ||
115 error(sprintf(gettext("failed to load Markdown.pm perl module (%s) or /usr/bin/markdown (%s)"), $error, $!));
116 $markdown_sub=\&Markdown::Markdown;
124 # Workaround for perl bug (#376329)
125 $content=Encode::encode_utf8($content);
126 eval {$content=&$markdown_sub($content)};
128 eval {$content=&$markdown_sub($content)};
129 print STDERR $@ if $@;
131 $content=Encode::decode_utf8($content);