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?",
30 example => 0, # /usr/bin/markdown
31 description => "path to an external markdown binary",
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 ($config{markdown_path}) {
51 eval q{use File::Temp};
53 debug(gettext("markdown_path is set, but File::Temp is not installed"));
56 debug("Markdown: $config{markdown_path}");
57 $tempdir=File::Temp::tempdir( CLEANUP => 1 );
62 ($fh, $filename) = File::Temp::tempfile( DIR => $tempdir );
63 print $fh "$content\n";
65 $content = `$config{markdown_path} $filename`;
69 } elsif (exists $config{multimarkdown} && $config{multimarkdown}) {
70 eval q{use Text::MultiMarkdown};
72 debug(gettext("multimarkdown is enabled, but Text::MultiMarkdown is not installed"));
75 debug("Markdown: Text::MultiMarkdown::markdown()");
77 Text::MultiMarkdown::markdown(shift, {use_metadata => 0});
81 if (! defined $markdown_sub) {
82 eval q{use Text::Markdown};
84 if (Text::Markdown->can('markdown')) {
85 debug("Markdown: Text::Markdown::markdown()");
86 $markdown_sub=\&Text::Markdown::markdown;
89 debug("Markdown: Text::Markdown::Markdown()");
90 $markdown_sub=\&Text::Markdown::Markdown;
96 debug("Markdown: Markdown::Markdown()");
97 $markdown_sub=\&Markdown::Markdown;
100 error("failed to load Markdown.pm perl module or $config{markdown_path}");
108 # Workaround for perl bug (#376329)
109 $content=Encode::encode_utf8($content);
110 eval {$content=&$markdown_sub($content)};
112 eval {$content=&$markdown_sub($content)};
113 print STDERR $@ if $@;
115 $content=Encode::decode_utf8($content);