2006-07-04 00:08:04 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# Markdown markup language
|
|
|
|
package IkiWiki::Plugin::mdwn;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
use IkiWiki;
|
|
|
|
|
|
|
|
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 (! $@) {
|
|
|
|
$markdown_sub=\&Text::Markdown::Markdown;
|
|
|
|
}
|
|
|
|
else {
|
2006-09-16 03:14:30 +02:00
|
|
|
do "/usr/bin/markdown" ||
|
|
|
|
error("failed to load Markdown.pm perl module ($@) or /usr/bin/markdown ($!)");
|
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);
|
|
|
|
$content=Encode::encode_utf8($content);
|
2006-09-16 03:53:14 +02:00
|
|
|
$content=&$markdown_sub($content);
|
2006-07-04 00:08:04 +02:00
|
|
|
$content=Encode::decode_utf8($content);
|
|
|
|
$content=Encode::decode_utf8($content);
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
} # }}}
|
|
|
|
|
|
|
|
1
|