2 # Markdown markup language
3 package IkiWiki::Plugin::mdwn;
10 hook(type => "checkconfig", id => "mdwn", call => \&checkconfig);
11 hook(type => "getsetup", id => "mdwn", call => \&getsetup);
12 hook(type => "htmlize", id => "mdwn", call => \&htmlize, longname => "Markdown");
13 hook(type => "htmlize", id => "md", call => \&htmlize, longname => "Markdown (popular file extension)", nocreate => 1);
20 rebuild => 1, # format plugin
26 description => "enable multimarkdown features?",
33 description => "disable use of markdown discount?",
40 description => "enable footnotes in Markdown (where supported)?",
47 $config{mdwn_footnotes} = 1 unless defined $config{mdwn_footnotes};
53 my $content = $params{content};
55 if (! defined $markdown_sub) {
56 # Markdown is forked and splintered upstream and can be
57 # available in a variety of forms. Support them all.
59 $blosxom::version="is a proper perl module too much to ask?";
62 if (exists $config{multimarkdown} && $config{multimarkdown}) {
63 eval q{use Text::MultiMarkdown};
65 debug(gettext("multimarkdown is enabled, but Text::MultiMarkdown is not installed"));
69 my %flags=( use_metadata => 0 );
71 if ($config{mdwn_footnotes}) {
72 $flags{disable_footnotes}=1;
75 Text::MultiMarkdown::markdown(shift, \%flags);
79 if (! defined $markdown_sub &&
80 (! exists $config{nodiscount} || ! $config{nodiscount})) {
81 eval q{use Text::Markdown::Discount};
86 # Workaround for discount binding bug
87 # https://rt.cpan.org/Ticket/Display.html?id=73657
88 return "" if $t=~/^\s*$/;
92 # Disable Pandoc-style % Title, % Author, % Date
93 # Use the meta plugin instead
94 $flags |= Text::Markdown::Discount::MKD_NOHEADER();
96 # Disable Unicodification of quote marks, em dashes...
97 # Use the typography plugin instead
98 $flags |= Text::Markdown::Discount::MKD_NOPANTS();
100 if ($config{mdwn_footnotes}) {
101 $flags |= Text::Markdown::Discount::MKD_EXTRA_FOOTNOTE();
104 # Workaround for discount's eliding
106 # https://rt.cpan.org/Ticket/Display.html?id=74016
107 if (Text::Markdown::Discount->can("MKD_NOSTYLE")) {
108 $flags |= Text::Markdown::Discount::MKD_NOSTYLE();
111 # This is correct for the libmarkdown.so.2 ABI
112 $flags |= 0x00400000;
115 return Text::Markdown::Discount::markdown($t, $flags);
119 if (! defined $markdown_sub) {
120 eval q{use Text::Markdown};
122 if (Text::Markdown->can('markdown')) {
123 $markdown_sub=\&Text::Markdown::markdown;
126 $markdown_sub=\&Text::Markdown::Markdown;
130 eval q{use Markdown};
132 $markdown_sub=\&Markdown::Markdown;
136 do "/usr/bin/markdown" ||
137 error(sprintf(gettext("failed to load Markdown.pm perl module (%s) or /usr/bin/markdown (%s)"), $error, $!));
138 $markdown_sub=\&Markdown::Markdown;
146 # Workaround for perl bug (#376329)
147 $content=Encode::encode_utf8($content);
148 eval {$content=&$markdown_sub($content)};
150 eval {$content=&$markdown_sub($content)};
151 print STDERR $@ if $@;
153 $content=Encode::decode_utf8($content);