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 $t=~s/<style/<elyts/ig;
86 my $r=Text::Markdown::Discount::markdown($t, $flags);
87 $r=~s/<elyts/<style/ig;
92 if (! defined $markdown_sub) {
93 eval q{use Text::Markdown};
95 if (Text::Markdown->can('markdown')) {
96 $markdown_sub=\&Text::Markdown::markdown;
99 $markdown_sub=\&Text::Markdown::Markdown;
103 eval q{use Markdown};
105 $markdown_sub=\&Markdown::Markdown;
109 do "/usr/bin/markdown" ||
110 error(sprintf(gettext("failed to load Markdown.pm perl module (%s) or /usr/bin/markdown (%s)"), $error, $!));
111 $markdown_sub=\&Markdown::Markdown;
119 # Workaround for perl bug (#376329)
120 $content=Encode::encode_utf8($content);
121 eval {$content=&$markdown_sub($content)};
123 eval {$content=&$markdown_sub($content)};
124 print STDERR $@ if $@;
126 $content=Encode::decode_utf8($content);