Re: Blatt wrapper question
George Walters wrote:
> I think that would work. I've looked in the archives for a txt to html
> converter but did not find one. There's one in pearl and some for sale.
> Has anyone attempted this in EU?
Yep. If you want to buy a converter, please tell me.
Or use the following code. It is deliberately simple (for instance if there
is a URL in the text, it won't be "clickable" in the generated HTML file).
However, it exactly shows the text like it is in the plain text file, with
all columns at their correct position.
function rextract (sequence source, object x)
for i = length(source) to 1 by -1 do
if equal(source[i], x) then
return source[1..i-1]
end if
end for
return source
end function
constant
HTML_HEADER = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01
Transitional//EN\">\n"
& "<html>\n"
& "<head>\n"
& "<meta http-equiv=\"Content-Type\" content=\"text/html;
charset=iso-8859-15\">\n"
& "<title>%s</title>\n"
& "</head>\n\n"
& "<body>\n",
HTML_FOOTER = "</body>\n"
& "</html>"
global procedure text2html (sequence infile)
object line
sequence title, outfile
integer ifn, ofn
title = rextract(infile, '.')
outfile = title & ".htm"
ifn = open(infile, "r")
ofn = open(outfile, "w")
printf(ofn, HTML_HEADER, {title})
puts(ofn, "<pre>\n")
while 1 do
line = gets(ifn)
if atom(line) then exit end if
puts(ofn, line)
end while
puts(ofn, "</pre>\n")
puts(ofn, HTML_FOOTER)
close(ifn)
close(ofn)
end procedure
include file.e -- for dir()
include get.e -- for wait_key()
constant CMD = command_line()
object list, void
if length(CMD) < 3 then
puts(1, "Usage: txt2html <filespec>")
void = wait_key()
abort(1)
end if
list = dir(CMD[3])
if atom(list) then
puts(1, "No matching file found: " & CMD[3])
void = wait_key()
abort(1)
end if
for i = 1 to length(list) do
text2html(list[i][D_NAME])
end for
Regards,
Juergen
|
Not Categorized, Please Help
|
|