summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/otl.pm
blob: 40c52976171f901e05a576ee80e330b8c139b52b (plain)
  1. #!/usr/bin/perl
  2. # outline markup
  3. package IkiWiki::Plugin::otl;
  4. use warnings;
  5. use strict;
  6. use IkiWiki;
  7. use IPC::Open2;
  8. sub import { #{{{
  9. IkiWiki::hook(type => "filter", id => "otl", call => \&filter);
  10. IkiWiki::hook(type => "htmlize", id => "otl", call => \&htmlize);
  11. } # }}}
  12. sub filter (@) { #{{{
  13. my %params=@_;
  14. # Munge up check boxes to look a little bit better. This is a hack.
  15. my $checked=IkiWiki::htmllink($params{page}, $params{page},
  16. "smileys/star_on.png", 0);
  17. my $unchecked=IkiWiki::htmllink($params{page}, $params{page},
  18. "smileys/star_off.png", 0);
  19. $params{content}=~s/^(\s+)\[X\]\s/${1}$checked /mg;
  20. $params{content}=~s/^(\s+)\[_\]\s/${1}$unchecked /mg;
  21. return $params{content};
  22. } # }}}
  23. sub htmlize ($) { #{{{
  24. my $tries=10;
  25. while (1) {
  26. eval {
  27. open2(*IN, *OUT, 'otl2html -S /dev/null -T /dev/stdin');
  28. };
  29. last unless $@;
  30. $tries--;
  31. if ($tries < 1) {
  32. IkiWiki::debug("failed to run otl2html: $@");
  33. return shift;
  34. }
  35. }
  36. # open2 doesn't respect "use open ':utf8'"
  37. binmode (IN, ':utf8');
  38. binmode (OUT, ':utf8');
  39. print OUT shift;
  40. close OUT;
  41. local $/ = undef;
  42. my $ret=<IN>;
  43. $ret=~s/.*<body>//s;
  44. $ret=~s/<body>.*//s;
  45. $ret=~s/<div class="Footer">.*//s;
  46. return $ret;
  47. } # }}}
  48. 1