summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/mdwn.pm
blob: 8e037f5de192377018cd81c8f12a10c89d76d9bf (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 $content = shift;
  13. if (! $markdown_loaded) {
  14. # Note: This hack to make markdown run as a proper perl
  15. # module. A proper perl module is available in Debian
  16. # for markdown, but not upstream yet.
  17. no warnings 'once';
  18. $blosxom::version="is a proper perl module too much to ask?";
  19. use warnings 'all';
  20. eval q{use Markdown};
  21. if ($@) {
  22. do "/usr/bin/markdown" ||
  23. IkiWiki::error("failed to load Markdown.pm perl module ($@) or /usr/bin/markdown ($!)");
  24. }
  25. $markdown_loaded=1;
  26. require Encode;
  27. }
  28. # Workaround for perl bug (#376329)
  29. $content=Encode::encode_utf8($content);
  30. $content=Encode::encode_utf8($content);
  31. $content=Markdown::Markdown($content);
  32. $content=Encode::decode_utf8($content);
  33. $content=Encode::decode_utf8($content);
  34. return $content;
  35. } # }}}
  36. 1