summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/mdwn.pm
blob: 2274fea72489b3256cd3d05ee9b0ba7f0dd82d42 (plain)
  1. #!/usr/bin/perl
  2. # Markdown markup language
  3. package IkiWiki::Plugin::mdwn;
  4. use warnings;
  5. use strict;
  6. use IkiWiki;
  7. sub import { #{{{
  8. IkiWiki::hook(type => "htmlize", id => "mdwn", call => \&htmlize);
  9. } # }}}
  10. my $markdown_loaded=0;
  11. sub htmlize (@) { #{{{
  12. my %params=@_;
  13. my $content = $params{content};
  14. if (! $markdown_loaded) {
  15. # Note: This hack to make markdown run as a proper perl
  16. # module. A proper perl module is available in Debian
  17. # for markdown, but not upstream yet.
  18. no warnings 'once';
  19. $blosxom::version="is a proper perl module too much to ask?";
  20. use warnings 'all';
  21. eval q{use Markdown};
  22. if ($@) {
  23. do "/usr/bin/markdown" ||
  24. IkiWiki::error("failed to load Markdown.pm perl module ($@) or /usr/bin/markdown ($!)");
  25. }
  26. $markdown_loaded=1;
  27. require Encode;
  28. }
  29. # Workaround for perl bug (#376329)
  30. $content=Encode::encode_utf8($content);
  31. $content=Encode::encode_utf8($content);
  32. $content=Markdown::Markdown($content);
  33. $content=Encode::decode_utf8($content);
  34. $content=Encode::decode_utf8($content);
  35. return $content;
  36. } # }}}
  37. 1