lm — 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 ?
Kaj — 29-Mar-2022/8:10:43-7:00
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.
Sergey_Vl — 29-Mar-2022/8:30:24-7:00
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"
Sergey_Vl — 29-Mar-2022/8:53:28-7:00
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
lm — 29-Mar-2022/8:54:23-7:00
@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
Sergey_Vl — 29-Mar-2022/17:14:18-7:00
But it is not "couple"... Or your not maind 2 tags? (sorry, my english is bad...)
Mario — 30-Mar-2022/0:26:46-7:00
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]]