HTML pretty printer

Started by lm on 29-Mar-2022/4:10:59-7:00
How do I do a HTML pretty printer in Rebol, ie. write each tag couple on separate lines ?
That is a large task. To support all HTML, you need a full HTML parser. There are several of those in libraries for different REBOL versions. I don't know if one does pretty-printing, but if not, you could implement it off the REBOL format that a library parses the HTML into.
Don't understand what you want... Show it in this sample - "<tr><td> text <hr> <font> text2 </td></tr><tr><td> text3 </font> </td></tr> text4 <br> text5"
Like this? >> a: "123 <a> bbb </a> cccc ddd <2> 222 </2> eee" >> foreach b parse a none [ if/else b/1 = #"<" [ if/else b/2 = #"/" [print b] [print " " prin b] ] [ prin b ] prin " " ] 123 <a> bbb </a> cccc ddd <2> 222 </2> eee
@Sergey: I've come up with following solution: probe parse page [ any [to {<} mark: (mark: insert mark "^/") :mark skip] to end ] "<tr><td> text <hr> <font> text2 </td></tr><tr><td> text3 </font> </td></tr> text4 <br> text5" becomes as follows: <tr> <td>text <hr> <font>text2 </td> </tr> <tr> <td>text3 </font> </td> </tr>text4 <br>text5
But it is not "couple"... Or your not maind 2 tags? (sorry, my english is bad...)
Rebol (Unlike Red) has the /markup refinement for LOAD. It splits a string into tags and strings. h: "<tr><td> text <hr> <font> text2 </td></tr><tr><td> text3 </font> </td></tr> text4 <br> text 5" foreach x load/markup h [print x] That gets you each tag and each string on a newline. How you want them nested or indented is a more nuanced issue, eg, foreach x load/markup h [either tag? x [print x][prin x]]

Reply