summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/hnb.pm
blob: 846b0f2c9333f27c2356fecca9d679cba8159964 (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 => "htmlize", id => "hnb", call => \&htmlize);
  15. }
  16. sub htmlize (@) {
  17. my %params = @_;
  18. # hnb outputs version number etc. every time to STDOUT, so
  19. # using files makes it easier to seprarate.
  20. my $tmpin = mkstemp( "/tmp/ikiwiki-hnbin.XXXXXXXXXX" );
  21. my $tmpout = mkstemp( "/tmp/ikiwiki-hnbout.XXXXXXXXXX" );
  22. open(TMP, '>', $tmpin) or die "Can't write to $tmpin: $!";
  23. print TMP $params{content};
  24. close TMP;
  25. system("hnb '$tmpin' 'go root' 'export_html $tmpout' > /dev/null");
  26. unlink $tmpin;
  27. open(TMP, '<', $tmpout) or die "Can't read from $tmpout: $!";
  28. local $/;
  29. my $ret = <TMP>;
  30. close TMP;
  31. unlink $tmpout;
  32. $ret =~ s/.*<body>//si;
  33. $ret =~ s/<body>.*//si;
  34. return $ret;
  35. }
  36. 1;