]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/mdwn.pm
(no commit message)
[git.ikiwiki.info.git] / IkiWiki / Plugin / mdwn.pm
index 332325adc814134520381b088e7524b335342921..daf9d592e4189e1e06d279b568e43db3b3858262 100644 (file)
@@ -4,15 +4,21 @@ package IkiWiki::Plugin::mdwn;
 
 use warnings;
 use strict;
 
 use warnings;
 use strict;
-use IkiWiki 2.00;
+use IkiWiki 3.00;
 
 
-sub import { #{{{
+sub import {
        hook(type => "getsetup", id => "mdwn", call => \&getsetup);
        hook(type => "getsetup", id => "mdwn", call => \&getsetup);
-       hook(type => "htmlize", id => "mdwn", call => \&htmlize);
-} # }}}
+       hook(type => "htmlize", id => "mdwn", call => \&htmlize, longname => "Markdown");
+       hook(type => "htmlize", id => "md", call => \&htmlize, longname => "Markdown (popular file extension)", nocreate => 1);
+}
 
 
-sub getsetup () { #{{{
+sub getsetup () {
        return
        return
+               plugin => {
+                       safe => 1,
+                       rebuild => 1, # format plugin
+                       section => "format",
+               },
                multimarkdown => {
                        type => "boolean",
                        example => 0,
                multimarkdown => {
                        type => "boolean",
                        example => 0,
@@ -20,10 +26,17 @@ sub getsetup () { #{{{
                        safe => 1,
                        rebuild => 1,
                },
                        safe => 1,
                        rebuild => 1,
                },
-} #}}}
+               nodiscount => {
+                       type => "boolean",
+                       example => 0,
+                       description => "disable use of markdown discount?",
+                       safe => 1,
+                       rebuild => 1,
+               },
+}
 
 my $markdown_sub;
 
 my $markdown_sub;
-sub htmlize (@) { #{{{
+sub htmlize (@) {
        my %params=@_;
        my $content = $params{content};
 
        my %params=@_;
        my $content = $params{content};
 
@@ -39,8 +52,29 @@ sub htmlize (@) { #{{{
                        if ($@) {
                                debug(gettext("multimarkdown is enabled, but Text::MultiMarkdown is not installed"));
                        }
                        if ($@) {
                                debug(gettext("multimarkdown is enabled, but Text::MultiMarkdown is not installed"));
                        }
-                       $markdown_sub=sub {
-                               Text::MultiMarkdown::markdown(shift, {use_metadata => 0});
+                       else {
+                               $markdown_sub=sub {
+                                       Text::MultiMarkdown::markdown(shift, {use_metadata => 0});
+                               }
+                       }
+               }
+               if (! defined $markdown_sub &&
+                   (! exists $config{nodiscount} || ! $config{nodiscount})) {
+                       eval q{use Text::Markdown::Discount};
+                       if (! $@) {
+                               $markdown_sub=sub {
+                                       my $t=shift;
+                                       # Workaround for discount binding bug
+                                       # https://rt.cpan.org/Ticket/Display.html?id=73657
+                                       return "" if $t=~/^\s*$/;
+                                       # Workaround for discount's eliding
+                                       # of <style> blocks.
+                                       # https://rt.cpan.org/Ticket/Display.html?id=74016
+                                       $t=~s/<style/<elyts/ig;
+                                       my $r=Text::Markdown::Discount::markdown($t);
+                                       $r=~s/<elyts/<style/ig;
+                                       return $r;
+                               }
                        }
                }
                if (! defined $markdown_sub) {
                        }
                }
                if (! defined $markdown_sub) {
@@ -59,8 +93,9 @@ sub htmlize (@) { #{{{
                                        $markdown_sub=\&Markdown::Markdown;
                                }
                                else {
                                        $markdown_sub=\&Markdown::Markdown;
                                }
                                else {
+                                       my $error = $@;
                                        do "/usr/bin/markdown" ||
                                        do "/usr/bin/markdown" ||
-                                               error(sprintf(gettext("failed to load Markdown.pm perl module (%s) or /usr/bin/markdown (%s)"), $@, $!));
+                                               error(sprintf(gettext("failed to load Markdown.pm perl module (%s) or /usr/bin/markdown (%s)"), $error, $!));
                                        $markdown_sub=\&Markdown::Markdown;
                                }
                        }
                                        $markdown_sub=\&Markdown::Markdown;
                                }
                        }
@@ -79,6 +114,6 @@ sub htmlize (@) { #{{{
        $content=Encode::decode_utf8($content);
 
        return $content;
        $content=Encode::decode_utf8($content);
 
        return $content;
-} # }}}
+}
 
 1
 
 1