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
32 $VERSION = $Grutatxt::VERSION
. ":1";
47 # offset for the h? headers
57 $table_type = "allbox";
59 # abstract line number
65 # default tab size in LaTeX mode
68 #####################################################################
71 if(!GetOptions
( "i|input=s" => \
$input_file,
72 "o|output=s" => \
$output_file,
74 "e|embed-css" => \
$embed_css,
75 "t|title=s" => \
$title,
76 "f|header-offset=s" => \
$header_offset,
77 "b|table-headers" => \
$table_headers,
78 "ct|center-tables" => \
$center_tables,
79 "xt|expand-tables" => \
$expand_tables,
80 "sp|strip-parens" => \
$strip_parens,
81 "ts|tabsize=s" => \
$tabsize,
82 "nb|no-body" => \
$no_body,
83 "v|version" => \
$version,
86 "s|man-section=s" => \
$man_section,
87 "docclass=s" => \
$latex_docclass,
88 "papersize=s" => \
$papersize,
89 "encoding=s" => \
$encoding,
98 print "$VERSION\n"; exit(0);
101 open I
, $input_file or die "Can't open $input_file: $!";
102 open O
, ">$output_file" or die "Can't create $output_file: $!";
104 # if utf8 encoding is wanted, set the filehandles as utf8
105 # so that regular expressions match all characters
107 if(defined($encoding) && $encoding =~ /^utf-?8/i)
113 $content = join("",<I
>);
118 # make tab to space conversion only in LaTeX mode
119 $tabsize = 0 unless $mode =~ /^latex$/i;
121 $grutatxt = new Grutatxt
(
123 "header-offset" => $header_offset,
124 "table-headers" => $table_headers,
125 "center-tables" => $center_tables,
126 "expand-tables" => $expand_tables,
127 "strip-parens" => $strip_parens,
128 "strip-dollars" => $strip_dollars,
129 "tabsize" => $tabsize,
130 "dl-as-dl" => $dl_as_dl,
131 "table-type" => $table_type,
132 "title" => \
$content_title,
133 "abstract" => \
$abstract,
134 "page-name" => $title,
135 "section" => $man_section,
136 "docclass" => $latex_docclass,
137 "papersize" => $papersize,
138 "encoding" => $encoding
141 @result = $grutatxt->process($content);
143 $title = $content_title unless $title;
144 $no_body = 1 unless $mode =~ /^html$/i;
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);
163 my ($c) = join('', <C
>);
166 print O
"<style type='text/css'>\n";
168 print O
"</style>\n";
172 die "Can't open '$css' CSS file.";
177 print O
"<link rel=StyleSheet href='$css' type='text/css'>";
181 print O
"</head><body>\n";
184 foreach my $l (@result)
189 print O
"</body></html>\n" unless $no_body;
198 print "grutatxt $VERSION - Grutatxt format processor\n";
199 print "Copyright (C) 2000/2007 Angel Ortega <angel\@triptico.com>\n";
200 print "This software is covered by the GPL license. NO WARRANTY.\n\n";
204 print "grutatxt [options] < input_text_file > output_html_file\n";
206 print "Global options:\n\n";
207 print " -i|--input=FILE Input file (STDIN)\n";
208 print " -o|--output=FILE Output file (STDOUT)\n";
209 print " -t|--title=TITLE Document title (if unset,\n";
210 print " level 1 heading is used)\n";
211 print " -sp|--strip-parens Strip parentheses in function\n";
212 print " names (shown monospaced anyway)\n";
213 print " -sd|--strip-dollars Strip leading \$ in variable\n";
214 print " names (shown monospaced anyway)\n";
215 print " -m|--mode=[HTML|troff|man|latex]\n";
216 print " Output mode: HTML, troff, man or latex\n";
217 print " (default: HTML)\n";
218 print "HTML options:\n\n";
219 print " -c|--css=CSS_URL_OR_FILE CSS URL (or file if using --embed-css)\n";
220 print " -e|--embed-css Embed CSS instead of linking to it\n";
221 print " -f|--header-offset=NUMBER Offset to add to <h1>,\n";
222 print " <h2>... headers (default 0)\n";
223 print " -b|--table-headers Use <th> instead of <td> in\n";
224 print " the first row of each table\n";
225 print " -ct|--center-tables Centers the tables\n";
226 print " -xt|--expand-tables Expands the tables (width=100\%)\n";
227 print " -nb|-no-body Don't generate <html><body>...\n";
228 print " </body></html> enclosing.\n";
229 print " --encoding=ENCODING Character encoding (default: iso-8859-1)\n";
230 print " -dl Use real <dl>, <dd> and <dt>\n";
231 print " instead of tables in definition lists.\n";
232 print "troff options:\n\n";
233 print " --table-type=TYPE Table type. Possible values:\n";
234 print " box, allbox, doublebox (default allbox)\n";
235 print "man options:\n\n";
236 print " -s|--man-section=SECTION Man page section (default: 1)\n\n";
237 print "LaTeX options:\n\n";
238 print " --docclass=CLASS Document class (default: report)\n";
239 print " --papersize=SIZE Paper size (default: a4paper)\n";
240 print " --encoding=ENCODING Character encoding (default: latin1)\n";
241 print " -ts|--tabsize=NUMBER Tab size for tab to space conversions in\n";
242 print " LaTeX verbatim environment (default: 8)\n";