Home   Archive   Permalink

text4
text5"

posted by:   Sergey_Vl     29-Mar-2022/8:30:24-7:00



Like this?
>> a: "123 bbb cccc ddd <2> 222 eee"
>> foreach b parse a none [
     if/else b/1 = #"<" [
            if/else b/2 = #"/" [print b] [print " " prin b]
            ] [
            prin b
            ]
     prin " "
     ]
123
bbb
cccc ddd
<2> 222
eee

posted by:   Sergey_Vl     29-Mar-2022/8:53:28-7:00



@Sergey:
    
I've come up with following solution:
    
probe parse page [
     any [to {<} mark: (mark: insert mark "^/") :mark skip] to end
]
    
" text4
text5"
    
becomes as follows:
    





text4

text5
    
    


posted by:   lm     29-Mar-2022/8:54:23-7:00



But it is not "couple"... Or your not maind 2 tags? (sorry, my english is bad...)

posted by:   Sergey_Vl     29-Mar-2022/17:14:18-7:00



Rebol (Unlike Red) has the /markup refinement for LOAD. It splits a string into tags and strings.
    
h: " text4
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]]

posted by:   Mario     30-Mar-2022/0:26:46-7:00



Name:


Message:


Type the reverse of this captcha text: "e k o p"





HTML pretty printer

How do I do a HTML pretty printer in Rebol, ie. write each tag couple on separate lines ?


posted by:   lm     29-Mar-2022/4:10:59-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.

posted by:   Kaj     29-Mar-2022/8:10:43-7:00



Don't understand what you want... Show it in this sample - "
text
text2
text3
text
text2
text3
text


text2
text3

text
text2
text3
Home