wiki.pl: Port some fixes from upstream
[Orgmuse.git] / wiki2html
blob86f0447b63156e4b4fa5a85173f574e856beae1c
1 #! /usr/bin/perl
2 # Copyright (C) 2007 Alex Schroeder <alex@gnu.org>
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.
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.
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/>.
17 =head1 wiki2html
19 This program converts text in markup from stdin to HTML on stdout. As
20 Oddmuse has a render engine that can be extended by plugins, you need
21 to pass the Oddmuse script and all its modules on the command line.
23 Example:
25 wiki2html ~/WebServer/CGI-Executables/current \
26 ~/WebServer/Oddmuse/modules/*.pl \
27 < in.txt > out.html
29 =head2 Options
31 =over
33 =item --title
35 Use this option to provide a title for the resulting HTML.
37 =item --css
39 Use this option to provide an URL or a filename for the CSS file.
41 =item --links
43 The presence of this option enables the linking of local pages. The
44 presence of local pages is determined using the C<pageidx> file in the
45 default data directory, ie. C</tmp/oddmuse/pageidx>.
47 =back
49 =cut
51 package OddMuse;
52 $RunCGI = 0;
54 $title = "wiki2html output";
55 $css = "http://www.oddmuse.org/oddmuse.css";
57 use Getopt::Long;
58 GetOptions("title=s" => \$title, "css=s" => \$css, "links" => \$links);
60 =head2 Code
62 The important part is to understand the calling convetion of
63 C<ApplyRules>. The first parameter is the URL-encoded input, the
64 second parameter is a boolean saying whether local links should be
65 rendered, and the last one is the opening tag with which to start.
66 Also note that the C<Init> call is necessary to initialize the CGI
67 object.
69 The code as it stands will try to read pages and config files from the
70 default data directory. The easiest way to provide your own config
71 file is probably to just add your config file to the list of files to
72 be loaded:
74 wiki2html ~/WebServer/CGI-Executables/current \
75 ~/WebServer/Oddmuse/config \
76 ~/WebServer/Oddmuse/modules/*.pl \
77 < in.txt > out.html
79 =cut
81 foreach my $f (@ARGV) { do $f; }
82 local $/;
83 my $input = <STDIN>;
84 if (not $input) {
85 print STDERR "Please supply raw wiki text as input on stdin.\n";
86 exit 1; # die() will print HTML...
89 print (qq(<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"),
90 qq( "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n),
91 qq(<html>\n<head>\n),
92 qq(<title>$title</title\n>),
93 qq(<meta http-equiv="Content-Type" content="text/html;charset=$HttpCharset" />\n),
94 qq(<link type="text/css" rel="stylesheet" href="$css" />\n),
95 qq(</head><body>\n),
96 qq(<div class="header"><h1>$title</h1></div>\n),
97 qq(<div class="wrapper">\n),
98 qq(<div class="content browse">));
101 Init();
102 ApplyRules(QuoteHtml($input), $links, undef, undef, 'p');
104 print (qq(\n</div>\n</div>\n</body>\n</html>\n));