summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/mdwn.pm
blob: 0fc077f5ec1cc1a30eaffba1ce8d323cccf160cf (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. 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. eval q{use Text::Markdown};
  24. if ($@) {
  25. do "/usr/bin/markdown" ||
  26. error("failed to load Markdown.pm perl module ($@) or /usr/bin/markdown ($!)");
  27. }
  28. }
  29. $markdown_loaded=1;
  30. require Encode;
  31. }
  32. # Workaround for perl bug (#376329)
  33. $content=Encode::encode_utf8($content);
  34. $content=Encode::encode_utf8($content);
  35. $content=Markdown::Markdown($content);
  36. $content=Encode::decode_utf8($content);
  37. $content=Encode::decode_utf8($content);
  38. return $content;
  39. } # }}}
  40. 1