2006-07-04 00:08:04 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# Markdown markup language
|
|
|
|
package IkiWiki::Plugin::mdwn;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2007-04-27 04:55:52 +02:00
|
|
|
use IkiWiki 2.00;
|
2006-07-04 00:08:04 +02:00
|
|
|
|
|
|
|
sub import { #{{{
|
2008-07-25 23:52:00 +02:00
|
|
|
hook(type => "getsetup", id => "mdwn", call => \&getsetup);
|
2006-09-10 00:50:27 +02:00
|
|
|
hook(type => "htmlize", id => "mdwn", call => \&htmlize);
|
2006-07-04 00:08:04 +02:00
|
|
|
} # }}}
|
|
|
|
|
2008-07-25 23:52:00 +02:00
|
|
|
sub getsetup () { #{{{
|
|
|
|
return
|
|
|
|
multimarkdown => {
|
|
|
|
type => "boolean",
|
2008-07-27 03:07:15 +02:00
|
|
|
example => 0,
|
2008-07-26 20:43:47 +02:00
|
|
|
description => "enable multimarkdown features?",
|
2008-07-25 23:52:00 +02:00
|
|
|
safe => 1,
|
|
|
|
rebuild => 1,
|
|
|
|
},
|
|
|
|
} #}}}
|
|
|
|
|
2006-09-16 03:50:29 +02:00
|
|
|
my $markdown_sub;
|
2006-08-28 20:17:59 +02:00
|
|
|
sub htmlize (@) { #{{{
|
|
|
|
my %params=@_;
|
|
|
|
my $content = $params{content};
|
2006-07-04 00:08:04 +02:00
|
|
|
|
2006-09-16 03:50:29 +02:00
|
|
|
if (! defined $markdown_sub) {
|
|
|
|
# Markdown is forked and splintered upstream and can be
|
2008-05-13 18:43:25 +02:00
|
|
|
# available in a variety of forms. Support them all.
|
2006-07-04 00:08:04 +02:00
|
|
|
no warnings 'once';
|
|
|
|
$blosxom::version="is a proper perl module too much to ask?";
|
|
|
|
use warnings 'all';
|
2006-08-10 06:11:58 +02:00
|
|
|
|
2008-05-13 18:43:25 +02:00
|
|
|
if (exists $config{multimarkdown} && $config{multimarkdown}) {
|
|
|
|
eval q{use Text::MultiMarkdown};
|
|
|
|
if ($@) {
|
2008-07-25 23:52:00 +02:00
|
|
|
debug(gettext("multimarkdown is enabled, but Text::MultiMarkdown is not installed"));
|
2008-05-13 18:43:25 +02:00
|
|
|
}
|
|
|
|
$markdown_sub=sub {
|
|
|
|
Text::MultiMarkdown::markdown(shift, {use_metadata => 0});
|
|
|
|
}
|
2006-09-16 03:50:29 +02:00
|
|
|
}
|
2008-07-25 23:52:00 +02:00
|
|
|
if (! defined $markdown_sub) {
|
2006-09-16 03:14:30 +02:00
|
|
|
eval q{use Text::Markdown};
|
2006-09-16 03:50:29 +02:00
|
|
|
if (! $@) {
|
2008-03-05 02:29:52 +01:00
|
|
|
if (Text::Markdown->can('markdown')) {
|
|
|
|
$markdown_sub=\&Text::Markdown::markdown;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$markdown_sub=\&Text::Markdown::Markdown;
|
|
|
|
}
|
2006-09-16 03:50:29 +02:00
|
|
|
}
|
|
|
|
else {
|
2008-05-13 18:43:25 +02:00
|
|
|
eval q{use Markdown};
|
|
|
|
if (! $@) {
|
|
|
|
$markdown_sub=\&Markdown::Markdown;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
do "/usr/bin/markdown" ||
|
|
|
|
error(sprintf(gettext("failed to load Markdown.pm perl module (%s) or /usr/bin/markdown (%s)"), $@, $!));
|
|
|
|
$markdown_sub=\&Markdown::Markdown;
|
|
|
|
}
|
2006-09-16 03:14:30 +02:00
|
|
|
}
|
2006-08-10 06:11:58 +02:00
|
|
|
}
|
2008-05-13 18:43:25 +02:00
|
|
|
|
2006-07-04 00:08:04 +02:00
|
|
|
require Encode;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Workaround for perl bug (#376329)
|
|
|
|
$content=Encode::encode_utf8($content);
|
2007-11-27 22:36:37 +01:00
|
|
|
eval {$content=&$markdown_sub($content)};
|
|
|
|
if ($@) {
|
|
|
|
eval {$content=&$markdown_sub($content)};
|
|
|
|
print STDERR $@ if $@;
|
|
|
|
}
|
2006-07-04 00:08:04 +02:00
|
|
|
$content=Encode::decode_utf8($content);
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
} # }}}
|
|
|
|
|
|
|
|
1
|