2006-07-04 00:08:04 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# Markdown markup language
|
|
|
|
package IkiWiki::Plugin::mdwn;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2008-12-23 22:34:19 +01:00
|
|
|
use IkiWiki 3.00;
|
2006-07-04 00:08:04 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub import {
|
2008-07-25 23:52:00 +02:00
|
|
|
hook(type => "getsetup", id => "mdwn", call => \&getsetup);
|
2009-05-16 14:59:27 +02:00
|
|
|
hook(type => "htmlize", id => "mdwn", call => \&htmlize, longname => "Markdown");
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-07-04 00:08:04 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub getsetup () {
|
2008-07-25 23:52:00 +02:00
|
|
|
return
|
2008-08-03 22:40:12 +02:00
|
|
|
plugin => {
|
|
|
|
safe => 1,
|
|
|
|
rebuild => 1, # format plugin
|
|
|
|
},
|
2008-07-25 23:52:00 +02:00
|
|
|
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,
|
|
|
|
},
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-07-25 23:52:00 +02:00
|
|
|
|
2006-09-16 03:50:29 +02:00
|
|
|
my $markdown_sub;
|
2008-12-17 21:22:16 +01:00
|
|
|
sub htmlize (@) {
|
2006-08-28 20:17:59 +02:00
|
|
|
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
|
|
|
}
|
2009-10-26 16:56:42 +01:00
|
|
|
else {
|
|
|
|
$markdown_sub=sub {
|
|
|
|
Text::MultiMarkdown::markdown(shift, {use_metadata => 0});
|
|
|
|
}
|
2008-05-13 18:43:25 +02:00
|
|
|
}
|
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;
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-07-04 00:08:04 +02:00
|
|
|
|
|
|
|
1
|