You think I'm kidding? Definitely not. After all, this is perfectly valid (wel ok, you could add the doctype, header, body tag etc) HTML.
The thing is, text does not have any real markup. You could read it all in, create a <p> block for every piece of code until an empty line is encountered, create ordered lists, unordered lists, create links for every URL in the text, but in the end, it will still look quite similar to the <pre> block.
[Rob]: The thing is, text does not have any real markup. You could read it all in, create a <p> block for every piece of code until an empty line is encountered, create ordered lists, unordered lists, create links for every URL in the text, but in the end, it will still look quite similar to the <pre> block.
Well, it is possible to make a few substantial improvements. E.g. the <pre> block will prevent word wrapping, which could well be a problem for some documents. So replacing each line break with <br> or <p> could well be an improvement.
Anyway Jay, the thing is that there's no standard way to do this. There are a number of aesthetic choices to make, depending on the nature of the text you're dealing with. Your best bet may be to code up something that reads each line, loops through each character, converts special characters to escape sequences, and appaned <br/> at the end of each line. Maybe leading spaces on a line could become . Depending on how you like the results, you can modify as necessary.
Or you can google for"java "text to html"" to look for existing code to do this sort of thing. A couple possibilities are this Text2HTML filter, or MarkdownJ. I've never used either, and don't know how close they may be to what you want. [ November 02, 2007: Message edited by: Jim Yingst ]
"I'm not back." - Bill Harding, Twister
posted 11 years ago
Ok the best implementation seems to be to read in each line in the text file , then add the html tags to the front and end , then spit that content into another file and add the html extension. I just thought they might be a java class or something that already did this, like htmlwriter or something Anyone know how to retrieve files from the hard drive? [ November 02, 2007: Message edited by: Jay Dilla ]
Ok, sounds like you just want plain text to look reasonably nice. Wrapping the whole thing with <html> and </html> is a good start.
The <pre> suggestion might be exactly right for you. That would preserve all the formatting in your text file, like indents and aligned columns. It's not the snazziest look, though.
If you rule out preformatted, do you want to keep the line breaks where they are now? Then you can just add <br> to the end of every line. That might wind up looking funny when the user resizes the browser.
If you want to call a block of text with no blank lines a paragraph and let the paragraph word-wrap and resize to the browser width, don't do the <br> bit. Instead replace a blank line with <p/> and let the rest flow right along with no tags.
Your idea of wrapping every line in some tag would be good for certain inputs. For example if you copy paragraphs from MS Word and paste them in a text editor, each paragraph will be one line, terminated by newline. For that, you could just wrap each line with <p> and <p/> and be done.
If you can put some minimal markup in the text you can borrow Wiki ideas and generate headings and lists with bullets or numbers pretty easily.
Do all those options make sense? Any of them sound right?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
posted 11 years ago
Is there a next line type method for FileWriter? I am able to copy from one file to another but I can format it correctly using filewriter.