LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-13-2006, 08:15 PM   #1
Chex
LQ Newbie
 
Registered: Jan 2006
Location: Maryland, USA
Distribution: SUSE 10.0
Posts: 18

Rep: Reputation: 0
Smile a program for text to html???


hello!

I'm wondering... is there a program to convert text into HTML? I have several long documents which I want to post to the web, and I was just wondering if there is any kind of tool that could make this easier.

There are a few such programs for Windows, but you have to pay for them -- and I don't have Windows...

Of course, I could always do the work by hand ... but it'd be nice if there was such an application (one that would insert the HTML tags for line breaks and so on). Maybe this is a weird request??

I am using SUSE 10.0, with KDE 3.5.

Whatever the answer is, thank you!

(Also, what HTML editors do you guys like best? I've tried Bluefish and Quanta, and so far I like Quanta best... but I am just wondering about the opinions of others, and what you think makes (your favourite HTML editor) the best. This question is mostly just to satisfy my own curiosity ...)
 
Old 02-13-2006, 09:06 PM   #2
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
You could use OpenOffice for this but it's a bit bulky install for just this use.
Maybe someone got some other progs?
 
Old 02-13-2006, 09:50 PM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
There are many programs named in the style <type>2html. I know of tex2html, doc2html sgml2html. As well as the "jw" program which can convert between various document types.

I didn't find a text2 html, but you could use a simple sed script to do it.

Code:
1i\
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\
<html>\
<head>\
 \<meta content="text/html; charset=ISO-8859-1"\
 http-equiv="content-type">\
  \<title></title>
s/^\(.*$\)/\1<br>/
$a\
<\/head>\
<\/html>
Save this file as text2html.sed and call it like:
sed -f text2html.sed textfilename.txt > htmlfilename.html
You could use a bash for loop to convert all *.txt files in a directory:
Code:
for textfile in *.txt; do
  sed -f text2html.sed ${textfile} > ${textfile%txt}html
done
Actually, I've never done any work in html. So I produced a simple html page of just text in Mozilla Composer, and based the script on the html page that I saved. There are only 3 sed commands! So the reason that you couldn't find a linux program to do it, it that is easy to do using normal tools.

------------------

I tried something else. I loaded in a text file in konqueror and exported it to html.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Generator" content="Kate, the KDE Advanced Text Editor" />
<title>sample3.html</title>
</head>
<body>
<pre>
This is TeX, Version 3.141592 (Web2C 7.5.4) (format=tex 2005.9.18)  11 NOV 2005 23:03
**grfguide.tex
(./grfguide.tex
! Undefined control sequence.
l.9 \begin
          {filecontents*}{a.ps}
? R
OK, entering \nonstopmode...
[1] )
Output written on grfguide.dvi (1 page, 408 bytes).
</pre></body>
</html>
You could write a simple bash script that uses here documents to
A) Write the first 10 lines to the output, containing <title>${1}</title>, or something similar so that each page gets the title of the file you are converting.
B) Insert the contents of the text file.
C) Add the last 3 lines.

One thing to consider is having to check if the text contains any sequences of characters such as </head> that would have a meaning to the browser. You would need to escape them either manually or by adding a number of sed commands to do this automatically. If this would be a rare occurance, you could load that text file into konqueror and export it as html. Konqueror uses Kate to do the job, so you can just use "kate".

Another option would be to produce a KDE style script to use KATE to convert a number of text files to html. This option would allow you to even use a file requestor to select the files to convert. This does assume that you have KDE installed.

Last edited by jschiwal; 02-13-2006 at 10:28 PM.
 
Old 02-13-2006, 10:43 PM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Here is a bash script, using sed to produce the 2nd style of text html page:
Code:
#!/bin/bash
sed -e '1i\
<?xml version="1.0" encoding="UTF-8"?>\
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">\
<html xmlns="http://www.w3.org/1999/xhtml">\
<head>\
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\
<meta name="Generator" content="Kate, the KDE Advanced Text Editor" />\
<title>'"${1}"'</title>\
</head>\
<body>\
<pre>' -e '$a\
</pre>\
</body> ' ${1} >${1%.txt}.html
This still doesn't escape HTML commands embedded in the text. That I'll leave up to you.

Last edited by jschiwal; 02-13-2006 at 11:02 PM. Reason: removed backslash from '<pre>' on line 12 of the code.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
text to xml to html osio Programming 5 07-28-2005 12:39 PM
how to convert text(html) back to html. d1l2w3 Linux - Software 4 04-08-2005 08:16 PM
html to text + encoding? David the H. Linux - General 6 11-22-2004 05:10 AM
what are the 'best' text editors (for C, html, js, etc) name_in_use450 Linux - General 4 08-31-2004 08:01 AM
Converting Text To HTML Glock Shooter Programming 6 07-03-2002 06:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration