2 <H3>txt2html - a text to HTML conversion tool
4 <P><B>txt2html
</B> is a simple tool for converting text files into HTML files.
5 Text files can contain simple formatting and mark-up commands that
6 <B>txt2html
</B> converts into HTML.
8 <P><B>txt2html
</B> was written by
<A HREF =
"http://www.cs.sandia.gov/~sjplimp">Steve Plimpton
</A>. I use it for
9 <A HREF =
"http://www.cs.sandia.gov/~sjplimp/lammps.html">documentation
</A> and
<A HREF =
"http://www.cs.sandia.gov/~sjplimp">WWW pages
</A>. Anna Reese added the table
12 <P>See the
<A HREF =
"example.txt">example.txt
</A> and
<A HREF =
"example.html">example.html
</A>
13 files in the
<B>txt2html
</B> directory for examples of what all the
14 formatting commands and mark-up syntax end up looking like in HTML.
27 <DD> read from text file, write HTML to standard output
28 <DT>txt2html file1 file2 file3 ...
29 <DD> read each argument as text file, write one HTML file per argument
31 <P>Input files are first opened with the specified name. If that fails,
32 a
".txt" suffix is added. Output files are created with an
".html"
33 suffix, which is either added or replaces the
".txt" suffix.
39 <P>The source for
<B>txt2html
</B> is a single C++ file. Compile it by typing:
41 <PRE>g++ -o txt2html txt2html.cpp
45 <P><B>How the tool works:
</B>
47 <P><B>txt2html
</B> reads a text file, one
<I>paragraph
</I> at a time. A paragraph
51 <LI> a line whose final word starts with
":" (a format string)
52 <LI> the end of the file
54 <P>Any line in the paragraph which ends with
"\" is concatenated to the
55 following line by removing the
"\" character and following newline.
56 This can be useful for some of the formatting commands described below
57 that operate on individual lines in the paragraph.
59 <P>If a paragraph starts with a
"<" character and ends with a
">"
60 character, it is treated as raw HTML and is written directly into the
63 <P>If a paragraph does not end with a format string, then it is
64 surrounded with HTML paragraph markers (
<P
> and
</P
>),
65 <A HREF =
"#markup">mark-up
</A> is performed, and the paragraph is written to the
68 <P>If the paragraph ends with a format string, then
<A HREF =
"#format">formatting
</A>
69 is performed,
<A HREF =
"#markup">mark-up
</A> is performed, and the paragraph is
70 written to the output file.
74 <A NAME =
"format"></A><B>Formatting:
</B>
76 <P>A format string is the last word of a paragraph if it starts with a
77 ":" character. A format string contains one or more comma-separated
78 commands, like
":ulb,l" or
":c,h3". Note that a format string cannot
79 contain spaces, else it would not be the last word. An individual
80 command can have
0 or more arguments:
82 <UL><LI> <I>b
</I> or
<I>line()
</I> =
0 arguments
83 <LI> <I>image(file)
</I> =
1 argument
84 <LI> <I>link(alias,value)
</I> =
2 or more comma-separated arguments
86 <P>Format commands add HTML markers at the beginning or end of the
87 paragraph and individual lines. Commands are processed in the order
88 they appear in the format string. Thus if two commands add HTML
89 markers to the beginning of the paragraph, the
2nd command's marker
90 will appear
2nd. The reverse is true at the end of the paragraph; the
91 2nd command's marker will appear
1st. Some comands, like
<I>line
</I> or
92 <I>image
</I> make most sense if used as stand-alone commands without an
93 accompanying paragraph.
95 <P>Commands that format the entire paragraph:
97 <UL><LI> p --
> surround the paragraph with
<P
> </P
>
98 <LI> b --
> put
<BR
> at the end of the paragraph
99 <LI> pre --
> surround the paragraph with
<PRE
> </PRE
>
100 <LI> c --
> surround the paragraph with
<CENTER
> </CENTER
>
101 <LI> h1,h2,h3,h4,h5,h6 --
> surround the paragraph with
<H1
> </H1
>, etc
103 <P>Commands that format the lines of the paragraph as a list:
105 <UL><LI> ul --
> surround the paragraph with
<UL
> </UL
>, put
<LI
> at start of every line
106 <LI> ol --
> surround the paragraph with
<OL
> </OL
>, put
<LI
> at start of every line
107 <LI> dl --
> surround the paragraph with
<DL
> </DL
>, alternate
<DT
> and
<DD
> at start of every line
109 <P>Commands that treat the paragraph as one entry in a list:
111 <UL><LI> l --
> put
<LI
> at the beginning of the paragraph
112 <LI> dt --
> put
<DT
> at the beginning of the paragraph
113 <LI> dd --
> put
<DD
> at the beginning of the paragraph
114 <LI> ulb --
> put
<UL
> at the beginning of the paragraph
115 <LI> ule --
> put
</UL
> at the end of the paragraph
116 <LI> olb --
> put
<OL
> at the beginning of the paragraph
117 <LI> ole --
> put
</OL
> at the end of the paragraph
118 <LI> dlb --
> put
<DL
> at the beginning of the paragraph
119 <LI> dle --
> put
</DL
> at the end of the paragraph
121 <P>Commands applied to each line of the paragraph:
123 <UL><LI> all(p) --
> surround each line with
<P
> </P
>
124 <LI> all(c) --
> surround each line with
<CENTER
> </CENTER
>
125 <LI> all(b) --
> append a
<BR
> to each line
126 <LI> all(l) --
> prepend a
<LI
> to each line
128 <P>Special commands (all HTML is inserted at beginning of paragraph):
130 <UL><LI> line --
> insert a horizontal line =
<HR
>
131 <LI> image(file) --
> insert an image =
<IMG SRC =
"file">
132 <LI> image(file,link) --
> insert an image that when clicked on goes to link
133 <LI> link(name) --
> insert a named link that can be referred to elsewhere (see
<A HREF =
"#markup">mark-up
</A>) =
<A NAME =
"name"></A
>
134 <LI> link(alias,value) --
> define a link alias that can be used elsewhere in this file (see
<A HREF =
"#markup">mark-up
</A>)
138 <UL><LI> tb(c=
3,b=
5,w=
100%,a=c) --
> format the paragraph as a table
140 <P>Arguments within tb() can appear in any order and are all optional,
141 since they each have default values.
143 <UL><LI> c=N --
> Make an N-column table. Treat the paragraph as one
144 long list of entries (separated by the separator character) and put
145 them into N columns one after the other. If N =
0, treat each line
146 of the paragraph as one row of the table with as many columns as
147 there are maximum entries in any line. Default is c=
0.
149 <LI> s=: --
> Use the character string following the equal sign as
150 the separator between entries. Default separator is a comma
"," which
151 you cannot specify directly since the comma delimits the tb() arguments
153 <LI> b=N --
> Create a border N pixels wide. If N is
0, there is no
154 border between or outside the cells. If N is
1, there is a minimal
155 border between and outside all cells. For N
> 1, the border between
156 cells does not change but the outside border gets wider. Default is
159 <LI> w=N or w=N% --> The first form makes each cell of the table at
160 least N pixels wide. The second form makes the entire table take up
161 N% of the width of the browser window. Default is w=
0 which means
162 each cell will be just as wide as the text it contains.
164 <LI> a=X --> Align the entire table at the left, center, or right of the
165 browser window, for X =
"l",
"c", or
"r". Default is a=c.
167 <LI> ea=X --> Align the text in each entry at the left, center, or
168 right of its cell, for X =
"l",
"c", or
"r". Default is browser's
169 default (typically left).
171 <LI> eva=X --> Vertically align the text in each entry at the
172 top, middle, baseline, or bottom of its cell, for X =
"t",
"m",
"ba",
173 or
"bo". Default is browser's default (typically middle).
175 <LI> cwM=N or cwM=N% --> The first form makes column M be at least
176 N pixels wide. The second form makes column M take up N% of the
177 width of the browser window. This setting overrides the
"w"
178 argument for column M. Only one column per table can be tweaked
179 with this argument. Default is no settings for any column.
181 <LI> caM=X --> Align the text in each entry of column M at the left,
182 center, or right of its cell, for X =
"l",
"c", or
"r". This
183 setting overrides the
"ea" argument for column M. Only one column
184 per table can be tweaked with this argument. Default is no settings
187 <LI> cvaM=X --> Vertically align the text in each entry of column m
188 at the top, middle, baseline, or bottom of its cell, for X =
"t",
189 "m",
"ba", or
"bo". This setting overrides the
"eva" argument for
190 column M. Only one column per table can be tweaked with this
191 argument. Default is no settings for any column.
195 <A NAME =
"markup"></A><B>Mark-up:
</B>
197 <P>The text of the paragraph is scanned for special mark-up characters
198 which are converted into HTML.
200 <P>Bold and italic characters:
202 <UL> <LI> "[" (left brace) --
> turn-on bold by inserting a
<B
>
203 <LI> "]" (right brace) --
> turn-off bold by inserting a
</B
>
204 <LI> "{" (left bracket) --
> turn-on italics by inserting a
<I
>
205 <LI> "}" (right bracket) --
> turn-off italics by
206 inserting a
</I
> </UL>
208 <P>If a backspace '\' preceeds any of the bold/italic mark-up characters,
209 then mark-up is not performed; the mark-up character is simply left in
212 <P>Links are inserted by enclosing a section of text in double quotes,
213 and appending an underscore to the ending quote, followed by the link.
214 The link ends when whitespace is found, except that trailing
215 punctuation characters (comma, period, semi-colon, colon, question
216 mark, exclamation point, parenthesis) are not considered part of the
219 <P> A link of the form
"text"_link becomes
<A HREF =
220 "link">text
</A
> in the HTML output. The only exception is if
221 "link" is defined elsewhere in the file as an alias (see the link
222 command above). In that case, the value is used instead of the alias
225 <P>With these rules, links can take several forms.
227 <UL> <LI> "This links"_#abc to another part of this file which is
228 labeled with a :link(abc) command.
<BR>
229 <LI> "This links"_other.html to another file named other.html.
<BR>
230 <LI> "This links"_other.html#abc to another file which has an
"abc"
231 location defined internally.
<BR>
232 <LI> "This links"_http://www.google.com to a WWW site.
<BR>
233 <LI> "This"_M12 could be used in place of any of the above forms. It
234 requires an alias like :link(M12,http://www.google.com) to be defined
235 elsewhere in the file.
</UL>