开发者

how to get html from plain formatted text?

开发者 https://www.devze.com 2023-03-19 18:57 出处:网络
I have an array that looks like Ant run name: Basics of Edumate Overall result: pass Ant run took: 4 minutes 13 seconds

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:

  1. 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.

  2. 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.

  3. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消