Hi,
This is my problem :
In a string, some authors write URLs directly like :
http://www.my-domainename.com.
Others use simply :
www.my-domainename.com .
To render the text to HTML, a parser add http:// if it not exist and then build anchor.
See code below.
I need to add another case :
here, authors write all the HTML anchor like :
<a href="http://www.my-domainename.com">www.my-domainename.com<a>
and so the parser has nothing to do. How can I add these rules to existing one ?
Thx,
===Philippe
------------------------------------------------------------
ctx-parse: context [
msg-block: copy ""
process-url: func [txt /image /local t] [
t: copy txt
parse txt [["ftp." (insert t "ftp://") | "www." (insert t "http://")] to end]
either find [".jpg" ".gif" ".png" ".bmp"] find/last txt "."
[rejoin [{<img src="} t {" border="0">}]]
[rejoin [{<a href="} t {">} txt {</a>}]]
]
;all-chars: exclude charset [#" " - #"^(FF)"] charset "[<"
all-chars: charset [#" " - #"^(FF)"]
non-white-space: complement charset " ^/^-^M<>"
to-space: [some non-white-space | end]
is-url: complement charset " ^/^-^M<>()"
end-url: [some is-url | end]
deb: fin: url: none
rules: [
deb: ["http" opt "s" "://" | "www." | "ftp://" | "ftp." ] end-url fin: (append msg-block process-url copy/part deb fin)
| [crlf | cr | lf] (append msg-block "<br>")
| tab (append msg-block " ")
| "<" (append msg-block "<")
| ">" (append msg-block ">")
| deb: all-chars fin: (append msg-block copy/part deb fin)
]
parse-target: func [data /local msg] [
clear msg-block
parse/all trim/head/tail data [some rules]
copy msg-block
]
]
; usage:
; ctx-parse/parse target {A string with http:// link , or anchor link or www link}