[REBOL] Re: Tags, anyone?
From: brett:codeconscious at: 16-Apr-2002 10:07
Hi Ammon,
I know there is the BUILD-TAG function.
And that
>> series? <test>
== true
So you can do:
>> find <test href="blah"> 'href
== <href="blah">
Also note that because tag is a series it is easy to get caught with
rejoin when forming a string from tags:
>> rejoin [<test> "color"]
== <testcolor>
So my habit is to use join where the first argument dictates the
datatype of my result:
>> join {} [<test> "color" </test>]
== "<test>color</test>"
You can load/markup...
>> load/markup {<test>some text </test>}
== [<test> "some text " </test>]
...and use tag in parse:
parse load/markup {<test>some text </test>} [
tag! string! tag!
]
Ages ago I wrote some stuff to play with markup and change tags
into blocks using load/markup and the fact that tags are series:
http://www.codeconscious.com/rebsite/rebol-library/tag-tool.r
http://www.codeconscious.com/rebsite/rebol-library/markup-tools.r
Tag-tool.r gives the import-tag function:
>> import-tag <body bgcolor=white>
== [body bgcolor "white"]
Which can be used as input to build-tag:
>> build-tag [body bgcolor "white"]
== <body bgcolor="white">
markup-tools.r gives the load-markup function which produce a "flat"
representation of the markup where tags are made into blocks.
>> load-markup {<text>some <b>text</b></text>}
== [[text] "some " [b] "text" [/b] [/text]]
There is also form-markup which converts this representation back into a
string:
>> form-markup [ [p] "paragraph 1" [p] "paragraph2" ]
== "<p>paragraph 1<p>paragraph2"
I did this to give a basic markup manipulation facility:
m: load-markup {<body bgcolor="white">some <b>text</b></body>}
change next find first m 'bgcolor "blue"
form-markup m
== {<body bgcolor="blue">some <b>text</b></body>}
For XML stuff there is Gavin's great work:
http://www3.sympatico.ca/gavin.mckenzie/
Regards,
Brett.