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?",
31 description => "path to an external markdown binary",
38 if (! defined $config{markdown_path}) {
39 $config{markdown_path}="/usr/bin/markdown";
47 my $content = $params{content};
49 if (! defined $markdown_sub) {
50 # Markdown is forked and splintered upstream and can be
51 # available in a variety of forms. Support them all.
53 $blosxom::version="is a proper perl module too much to ask?";
56 if ($config{markdown_path}) {
57 eval q{use File::Temp};
59 debug(gettext("markdown_path is set, but File::Temp is not installed"));
62 debug("Markdown: $config{markdown_path}");
63 $tempdir=File::Temp::tempdir( CLEANUP => 1 );
68 ($fh, $filename) = File::Temp::tempfile( DIR => $tempdir );
69 print $fh "$content\n";
71 $content = `$config{markdown_path} $filename`;
75 } elsif (exists $config{multimarkdown} && $config{multimarkdown}) {
76 eval q{use Text::MultiMarkdown};
78 debug(gettext("multimarkdown is enabled, but Text::MultiMarkdown is not installed"));
81 debug("Markdown: Text::MultiMarkdown::markdown()");
83 Text::MultiMarkdown::markdown(shift, {use_metadata => 0});
87 if (! defined $markdown_sub) {
88 eval q{use Text::Markdown};
90 if (Text::Markdown->can('markdown')) {
91 debug("Markdown: Text::Markdown::markdown()");
92 $markdown_sub=\&Text::Markdown::markdown;
95 debug("Markdown: Text::Markdown::Markdown()");
96 $markdown_sub=\&Text::Markdown::Markdown;
100 eval q{use Markdown};
102 debug("Markdown: Markdown::Markdown()");
103 $markdown_sub=\&Markdown::Markdown;
106 error(sprintf(gettext("failed to load Markdown.pm perl module (%s) or $config{markdown_path} (%s)"), $@, $!));
114 # Workaround for perl bug (#376329)
115 $content=Encode::encode_utf8($content);
116 eval {$content=&$markdown_sub($content)};
118 eval {$content=&$markdown_sub($content)};
119 print STDERR $@ if $@;
121 $content=Encode::decode_utf8($content);