wiki2html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #! /usr/bin/perl
  2. # Copyright (C) 2007 Alex Schroeder <alex@gnu.org>
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. =head1 wiki2html
  17. This program converts text in markup from stdin to HTML on stdout. As
  18. Oddmuse has a render engine that can be extended by plugins, you need
  19. to pass the Oddmuse script and all its modules on the command line.
  20. Example:
  21. wiki2html ~/WebServer/CGI-Executables/current \
  22. ~/WebServer/Oddmuse/modules/*.pl \
  23. < in.txt > out.html
  24. =head2 Options
  25. =over
  26. =item --title
  27. Use this option to provide a title for the resulting HTML.
  28. =item --css
  29. Use this option to provide an URL or a filename for the CSS file.
  30. =item --links
  31. The presence of this option enables the linking of local pages. The
  32. presence of local pages is determined using the C<pageidx> file in the
  33. default data directory, ie. C</tmp/oddmuse/pageidx>.
  34. =back
  35. =cut
  36. package OddMuse;
  37. $RunCGI = 0;
  38. $title = "wiki2html output";
  39. $css = "http://www.oddmuse.org/oddmuse.css";
  40. use Getopt::Long;
  41. GetOptions("title=s" => \$title, "css=s" => \$css, "links" => \$links);
  42. =head2 Code
  43. The important part is to understand the calling convetion of
  44. C<ApplyRules>. The first parameter is the URL-encoded input, the
  45. second parameter is a boolean saying whether local links should be
  46. rendered, and the last one is the opening tag with which to start.
  47. Also note that the C<Init> call is necessary to initialize the CGI
  48. object.
  49. The code as it stands will try to read pages and config files from the
  50. default data directory. The easiest way to provide your own config
  51. file is probably to just add your config file to the list of files to
  52. be loaded:
  53. wiki2html ~/WebServer/CGI-Executables/current \
  54. ~/WebServer/Oddmuse/config \
  55. ~/WebServer/Oddmuse/modules/*.pl \
  56. < in.txt > out.html
  57. =cut
  58. foreach my $f (@ARGV) { do $f; }
  59. local $/;
  60. my $input = <STDIN>;
  61. if (not $input) {
  62. print STDERR "Please supply raw wiki text as input on stdin.\n";
  63. exit 1; # die() will print HTML...
  64. }
  65. print (qq(<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"),
  66. qq( "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n),
  67. qq(<html>\n<head>\n),
  68. qq(<title>$title</title\n>),
  69. qq(<meta http-equiv="Content-Type" content="text/html;charset=$HttpCharset" />\n),
  70. qq(<link type="text/css" rel="stylesheet" href="$css" />\n),
  71. qq(</head><body>\n),
  72. qq(<div class="header"><h1>$title</h1></div>\n),
  73. qq(<div class="wrapper">\n),
  74. qq(<div class="content browse">));
  75. Init();
  76. ApplyRules(QuoteHtml($input), $links, undef, undef, 'p');
  77. print (qq(\n</div>\n</div>\n</body>\n</html>\n));