summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/mdwn.pm
blob: 625f77f2121aa73b1b29e471bc1828592c260898 (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_sub;
  11. sub htmlize (@) { #{{{
  12. my %params=@_;
  13. my $content = $params{content};
  14. if (! defined $markdown_sub) {
  15. # Markdown is forked and splintered upstream and can be
  16. # available in a variety of incompatible forms. Support
  17. # them all.
  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. $markdown_sub=\&Markdown::Markdown;
  24. }
  25. else {
  26. eval q{use Text::Markdown};
  27. if (! $@) {
  28. $markdown_sub=\&Text::Markdown::Markdown;
  29. }
  30. else {
  31. do "/usr/bin/markdown" ||
  32. error("failed to load Markdown.pm perl module ($@) or /usr/bin/markdown ($!)");
  33. $markdown_sub=\&Markdown::Markdown;
  34. }
  35. }
  36. require Encode;
  37. }
  38. # Workaround for perl bug (#376329)
  39. $content=Encode::encode_utf8($content);
  40. $content=Encode::encode_utf8($content);
  41. $content=&$markdown_sub($content);
  42. $content=Encode::decode_utf8($content);
  43. $content=Encode::decode_utf8($content);
  44. return $content;
  45. } # }}}
  46. 1