summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/hnb.pm
blob: d5b5ce3b4a1a46e67eb7dca435976c5b73658034 (plain)
  1. #!/usr/bin/perl
  2. # hnb markup
  3. # Licensed under the GPL v2 or greater
  4. # Copyright (C) 2008 by Axel Beckert <abe@deuxchevaux.org>
  5. #
  6. # TODO: Make a switch to allow both HTML export routines of hnb
  7. # (`export_html` and `export_htmlcss`) to be used.
  8. package IkiWiki::Plugin::hnb;
  9. use warnings;
  10. use strict;
  11. use IkiWiki 2.00;
  12. use File::Temp qw(:mktemp);
  13. sub import {
  14. hook(type => "getsetup", id => "hnb", call => \&getsetup);
  15. hook(type => "htmlize", id => "hnb", call => \&htmlize);
  16. }
  17. sub getsetup () {
  18. return
  19. plugin => {
  20. safe => 1,
  21. rebuild => 1, # format plugin
  22. },
  23. }
  24. sub htmlize (@) {
  25. my %params = @_;
  26. # hnb outputs version number etc. every time to STDOUT, so
  27. # using files makes it easier to seprarate.
  28. my $tmpin = mkstemp( "/tmp/ikiwiki-hnbin.XXXXXXXXXX" );
  29. my $tmpout = mkstemp( "/tmp/ikiwiki-hnbout.XXXXXXXXXX" );
  30. open(TMP, '>', $tmpin) or die "Can't write to $tmpin: $!";
  31. print TMP $params{content};
  32. close TMP;
  33. system("hnb '$tmpin' 'go root' 'export_html $tmpout' > /dev/null");
  34. unlink $tmpin;
  35. open(TMP, '<', $tmpout) or die "Can't read from $tmpout: $!";
  36. local $/;
  37. my $ret = <TMP>;
  38. close TMP;
  39. unlink $tmpout;
  40. $ret =~ s/.*<body>//si;
  41. $ret =~ s/<body>.*//si;
  42. return $ret;
  43. }
  44. 1;