Updated TODO.
[grutatxt.git] / grutatxt
blob974671d71e86581184d817ed310b2c3b0f6a7df8
1 #!/usr/bin/perl
3 use lib '.';
6 # grutatxt - Text to HTML (and other formats) converter
7 # http://www.triptico.com/software/grutatxt.html
9 # Copyright (C) 2000/2007 Angel Ortega <angel@triptico.com>
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 # http://www.triptico.com
28 use Getopt::Long;
29 use locale;
30 use Grutatxt;
32 $VERSION = $Grutatxt::VERSION . ':1';
34 # input file
35 $input_file = '-';
37 # output file
38 $output_file = '>-';
40 # CSS information
41 $css = '';
42 $embed_css = 0;
44 # page title
45 $title = '';
47 # offset for the h? headers
48 $header_offset = 0;
50 # default mode
51 $mode = 'HTML';
53 # use real dl
54 $dl_as_dl = 0;
56 # troff table type
57 $table_type = 'allbox';
59 # abstract line number
60 $abstract = 0;
62 # man page section
63 $man_section = 1;
65 # default tab size in LaTeX mode
66 $tabsize = 8;
68 # avoid time signature
69 $no_time_sig = 0;
71 #####################################################################
73 # parse options
74 if (!GetOptions('i|input=s' => \$input_file,
75 'o|output=s' => \$output_file,
76 'c|css=s' => \$css,
77 'e|embed-css' => \$embed_css,
78 't|title=s' => \$title,
79 'f|header-offset=s' => \$header_offset,
80 'b|table-headers' => \$table_headers,
81 'ct|center-tables' => \$center_tables,
82 'xt|expand-tables' => \$expand_tables,
83 'sp|strip-parens' => \$strip_parens,
84 'ts|tabsize=s' => \$tabsize,
85 'nb|no-body' => \$no_body,
86 'v|version' => \$version,
87 'h|help' => \$usage,
88 'm|mode=s' => \$mode,
89 's|man-section=s' => \$man_section,
90 'docclass=s' => \$latex_docclass,
91 'papersize=s' => \$papersize,
92 'encoding=s' => \$encoding,
93 'dl' => \$dl_as_dl,
94 'no-time-sig' => \$no_time_sig)
95 or $usage) {
96 usage();
99 if ($version) {
100 print "$VERSION\n"; exit(0);
103 open I, $input_file or die "Can't open $input_file: $!";
104 open O, ">$output_file" or die "Can't create $output_file: $!";
106 # if utf8 encoding is wanted, set the filehandles as utf8
107 # so that regular expressions match all characters
108 # (this is crap)
109 if (defined($encoding) && $encoding =~ /^utf-?8/i) {
110 binmode(I, ":utf8");
111 binmode(O, ":utf8");
114 $content = join('',<I>);
115 close I;
117 $content_title = '';
119 # make tab to space conversion only in LaTeX mode
120 $tabsize = 0 unless $mode =~ /^latex$/i;
122 $grutatxt = new Grutatxt(
123 'mode' => $mode,
124 'header-offset' => $header_offset,
125 'table-headers' => $table_headers,
126 'center-tables' => $center_tables,
127 'expand-tables' => $expand_tables,
128 'strip-parens' => $strip_parens,
129 'strip-dollars' => $strip_dollars,
130 'tabsize' => $tabsize,
131 'dl-as-dl' => $dl_as_dl,
132 'table-type' => $table_type,
133 'title' => \$content_title,
134 'abstract' => \$abstract,
135 'page-name' => $title,
136 'section' => $man_section,
137 'docclass' => $latex_docclass,
138 'papersize' => $papersize,
139 'encoding' => $encoding
142 @result = $grutatxt->process($content);
144 $title = $content_title unless $title;
145 $no_body = 1 unless $mode =~ /^html$/i;
147 unless ($no_body) {
148 print O "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n";
149 print O " \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n";
150 print O "<html><head>\n";
151 print O "<meta http-equiv='Content-Type' content='text/html; charset=" .
152 ($encoding || 'iso-8859-1') . "'>\n";
153 print O "<title>$title</title>\n";
155 printf O "<!-- converted from text by grutatxt $VERSION on %s -->\n", scalar(localtime)
156 unless $no_time_sig;
158 if ($css) {
159 if ($embed_css) {
160 if (open C, $css) {
161 my ($c) = join('', <C>);
162 close C;
164 print O "<style type='text/css'>\n";
165 print O $c . "\n";
166 print O "</style>\n";
168 else {
169 die "Can't open '$css' CSS file.";
172 else {
173 print O "<link rel=StyleSheet href='$css' type='text/css'>";
177 print O "</head><body>\n";
180 foreach my $l (@result) {
181 print O "$l\n";
184 print O "</body></html>\n" unless $no_body;
186 close O;
188 exit(0);
191 sub usage
193 print "grutatxt $VERSION - Grutatxt format processor\n";
194 print "Copyright (C) 2000/2007 Angel Ortega <angel\@triptico.com>\n";
195 print "This software is covered by the GPL license. NO WARRANTY.\n\n";
197 print "Usage:\n";
198 print "\n";
199 print "grutatxt [options] < input_text_file > output_html_file\n";
200 print "\n";
201 print "Global options:\n\n";
202 print " -i|--input=FILE Input file (STDIN)\n";
203 print " -o|--output=FILE Output file (STDOUT)\n";
204 print " -t|--title=TITLE Document title (if unset,\n";
205 print " level 1 heading is used)\n";
206 print " -sp|--strip-parens Strip parentheses in function\n";
207 print " names (shown monospaced anyway)\n";
208 print " -sd|--strip-dollars Strip leading \$ in variable\n";
209 print " names (shown monospaced anyway)\n";
210 print " -m|--mode=[HTML|troff|man|latex]\n";
211 print " Output mode: HTML, troff, man or latex\n";
212 print " (default: HTML)\n";
213 print " --no-time-sig Avoid time signature in HTML comment\n";
214 print "HTML options:\n\n";
215 print " -c|--css=CSS_URL_OR_FILE CSS URL (or file if using --embed-css)\n";
216 print " -e|--embed-css Embed CSS instead of linking to it\n";
217 print " -f|--header-offset=NUMBER Offset to add to <h1>,\n";
218 print " <h2>... headers (default 0)\n";
219 print " -b|--table-headers Use <th> instead of <td> in\n";
220 print " the first row of each table\n";
221 print " -ct|--center-tables Centers the tables\n";
222 print " -xt|--expand-tables Expands the tables (width=100\%)\n";
223 print " -nb|-no-body Don't generate <html><body>...\n";
224 print " </body></html> enclosing.\n";
225 print " --encoding=ENCODING Character encoding (default: iso-8859-1)\n";
226 print " -dl Use real <dl>, <dd> and <dt>\n";
227 print " instead of tables in definition lists.\n";
228 print "troff options:\n\n";
229 print " --table-type=TYPE Table type. Possible values:\n";
230 print " box, allbox, doublebox (default allbox)\n";
231 print "man options:\n\n";
232 print " -s|--man-section=SECTION Man page section (default: 1)\n\n";
233 print "LaTeX options:\n\n";
234 print " --docclass=CLASS Document class (default: report)\n";
235 print " --papersize=SIZE Paper size (default: a4paper)\n";
236 print " --encoding=ENCODING Character encoding (default: latin1)\n";
237 print " -ts|--tabsize=NUMBER Tab size for tab to space conversions in\n";
238 print " LaTeX verbatim environment (default: 8)\n";
240 exit(0);