how to get html from plain formatted text?
I have an array that looks like
Ant run name : Basics of Edumate
Overall result : pass
Ant run took: 4 minutes 13 seconds
--------------------------
Details for all test suits
--------------------------
login 开发者_运维百科: Pass
AddCycleTemplate: Pass
AddCycleTemplate: Pass
AddAcademicYear : Pass
AddAcademicYear : Pass
AddCampus : Pass
Is there any easy way how I can convert this in ruby into html that keeps the formatting?
If these are the only kinds of lines you will ever see, then you could certainly write a Ruby script that does the following:
First, output a doctype declaration, an opening html tag, an head section, an opening body tag, and an opening table tag with whatever style you like.
Read your Ant output line by line. If the line has a colon in it, split it on the colon and output a table row with two columns (each side of the split). If the line does not have a colon write its text as colspan=2, perhaps with a style indicating a large margin-top and margin-bottom, except if it is all dashes in which case you should ignore it.
Output HTML to close the table and the body.
This is certainly a hack and not a general solution by any means, but hey if you are writing a tool just for yourself so you can have some pretty little ant outputs, go for it. This is no more than 20 lines of Ruby. Write it to read from stdin and write to stdout so you can pipe your ant output to it!
if you don't care about formatting, just encapsulate the entire thing in <pre></pre> tags and you're set. All new lines and whitespaces will be preserved and default font is a monospaced one.
精彩评论