summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/hnb.pm
blob: b6511205e06b24dbdfc90e7e098320c1914de9a6 (plain)
  1. #!/usr/bin/perl
  2. # hnb markup
  3. package IkiWiki::Plugin::hnb;
  4. # Copyright (C) 2008 by Axel Beckert <abe@deuxchevaux.org>
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License
  8. # as published by the Free Software Foundation; either version 2
  9. # of the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. #
  20. # You can reach the author by snail-mail at the following address:
  21. #
  22. # Axel Beckert
  23. # Kuerbergstrasse 20
  24. # 8049 Zurich, Switzerland
  25. #
  26. # Version History:
  27. #
  28. # 2008-03-10 / 0.01: Initial release
  29. # 2008-05-08 / 0.01.1: License, version and version history added
  30. # 2008-05-26 / 0.02: Using content instead of page, s/mktemp/File::Temp/
  31. my $VERSION ='0.02';
  32. use warnings;
  33. use strict;
  34. use IkiWiki 2.00;
  35. use File::Temp qw(:mktemp);
  36. sub import {
  37. hook(type => "htmlize", id => "hnb", call => \&htmlize);
  38. }
  39. sub htmlize (@) {
  40. my %params = @_;
  41. # hnb does output version number etc. every time to STDOUT, so
  42. # using files makes it easier to seprarate.
  43. my ($fhi, $tmpin) = mkstemp( "/tmp/ikiwiki-hnbin.XXXXXXXXXX" );
  44. my ($fho, $tmpout) = mkstemp( "/tmp/ikiwiki-hnbout.XXXXXXXXXX" );
  45. open(TMP, '>', $tmpin) or die "Can't write to $tmpin: $!";
  46. print TMP $params{content};
  47. close TMP;
  48. system("hnb '$tmpin' 'go root' 'export_html $tmpout' > /dev/null");
  49. # Nicer, but too much output
  50. #system('hnb', $tmpin, 'go root', "export_html $tmpout");
  51. unlink $tmpin;
  52. open(TMP, '<', $tmpout) or die "Can't read from $tmpout: $!";
  53. local $/;
  54. my $ret = <TMP>;
  55. close TMP;
  56. unlink $tmpout;
  57. $ret =~ s/.*<body>//si;
  58. $ret =~ s/<body>.*//si;
  59. return $ret;
  60. }
  61. 1;