summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/hnb.pm
blob: 5157a6b93ce54c80ffac7330e50033cde57eddb4 (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 3.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. section => "format",
  23. },
  24. }
  25. sub htmlize (@) {
  26. my %params = @_;
  27. # hnb outputs version number etc. every time to STDOUT, so
  28. # using files makes it easier to seprarate.
  29. my ($infh, $tmpin) = mkstemp( "/tmp/ikiwiki-hnbin.XXXXXXXXXX" );
  30. my ($outfh, $tmpout) = mkstemp( "/tmp/ikiwiki-hnbout.XXXXXXXXXX" );
  31. open(TMP, '>', $tmpin) or die "Can't write to $tmpin: $!";
  32. print TMP $params{content};
  33. close TMP;
  34. system("hnb '$tmpin' 'go root' 'export_html $tmpout' > /dev/null");
  35. unlink $tmpin;
  36. open(TMP, '<', $tmpout) or die "Can't read from $tmpout: $!";
  37. local $/;
  38. my $ret = <TMP>;
  39. close TMP;
  40. unlink $tmpout;
  41. $ret =~ s/.*<body>//si;
  42. $ret =~ s/<body>.*//si;
  43. return $ret;
  44. }
  45. 1;