[REBOL] Re: Help required for a little parsing problem
From: g:santilli:tiscalinet:it at: 19-Nov-2000 11:50
Hello Nigel!
On 18-Nov-00, you wrote:
NB> Whilst I could probably write a (long) solution I'm sure
NB> there must be an elegant couple of line Rebol solution - one
NB> problem is that there may be any number of links in the post.
NB> Any suggestions?
Just an idea:
post-rule: [some [link | text]]
link: ["[url]" copy url to "[/url]" 6 skip (emit-link url)]
text: [copy chars [to "[url]" | skip to end] (emit chars)]
emit-link: func [url] [
emit build-tag [A HREF (url) TARGET "_blank"]
emit url
emit </A>
]
emit: func [text] [
insert tail output text
]
output: ""
parse-post: func [post] [
clear output
if parse/all post post-rule [copy output]
]
>> print parse-post "This is a post - Perl is good [url]http://www.perl.com[/url], Rebol
is better [url]http://www.rebol.com[/url]"
This is a post - Perl is good <A HREF="http://www.perl.com" TARGET="_blank">http://www.perl.com</A>,
Rebol is better <A HREF="http://www.rebol.com" TARGET="_blank">http://www.rebol.com</A>
(Perhaps it's a bit long...)
Regards,
Gabriele.
--
Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer
Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/