]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/mdwn.pm
* mdwn: When htmlizing text, if it's a single line with no newline,
[git.ikiwiki.info.git] / IkiWiki / Plugin / mdwn.pm
index c087f2b41309f892e52476305bf31ccc48fb7840..1520b3eecc66d96eb7b0da44a441b01bc3fc5ad1 100644 (file)
@@ -4,7 +4,7 @@ package IkiWiki::Plugin::mdwn;
 
 use warnings;
 use strict;
-use IkiWiki;
+use IkiWiki 2.00;
 
 sub import { #{{{
        hook(type => "htmlize", id => "mdwn", call => \&htmlize);
@@ -41,13 +41,24 @@ sub htmlize (@) { #{{{
                require Encode;
        }
        
+       my $oneline = $content !~ /\n/;
+
        # Workaround for perl bug (#376329)
        $content=Encode::encode_utf8($content);
-       $content=Encode::encode_utf8($content);
-       $content=&$markdown_sub($content);
-       $content=Encode::decode_utf8($content);
+       eval {$content=&$markdown_sub($content)};
+       if ($@) {
+               eval {$content=&$markdown_sub($content)};
+               print STDERR $@ if $@;
+       }
        $content=Encode::decode_utf8($content);
 
+       if ($oneline) {
+               # hack to get rid of enclosing junk added by markdown
+               $content=~s!^<p>!!;
+               $content=~s!</p>$!!;
+               chomp $content;
+       }
+
        return $content;
 } # }}}