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 { #{{{
|
2006-09-10 00:50:27 +02:00
|
|
|
hook(type => "htmlize", id => "mdwn", call => \&htmlize);
|
2006-07-04 00:08:04 +02:00
|
|
|
} # }}}
|
|
|
|
|
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
|
|
|
|
# available in a variety of incompatible 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
|
|
|
|
|
|
|
eval q{use Markdown};
|
2006-09-16 03:50:29 +02:00
|
|
|
if (! $@) {
|
|
|
|
$markdown_sub=\&Markdown::Markdown;
|
|
|
|
}
|
|
|
|
else {
|
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 {
|
2006-09-16 03:14:30 +02:00
|
|
|
do "/usr/bin/markdown" ||
|
2006-12-29 05:38:40 +01:00
|
|
|
error(sprintf(gettext("failed to load Markdown.pm perl module (%s) or /usr/bin/markdown (%s)"), $@, $!));
|
2006-09-16 03:50:29 +02:00
|
|
|
$markdown_sub=\&Markdown::Markdown;
|
2006-09-16 03:14:30 +02:00
|
|
|
}
|
2006-08-10 06:11:58 +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
|