Let's say I want to create a twitter client which list tweets. How would I create and detect a clickable link within a text zone ?
Update: I mean in rebol VID
Let's say I want to create a twitter client which list tweets. How would I create and detect a clickable link within a text zone ?
Update: I mean in rebol VID
In principle, you want to:
REBOL.org uses code very similar to the code below to do that. Note there are three elements to the implementation:
an external function that simply wraps a URL in an anchor tag
;; ======================================
;; Definitions provided by
;; Andrew Martin, 15-June-2004
;; ....not all are needed for locating URLs ... so
;; feel free to remove unnecessary items
Octet: charset [#"^(00)" - #"^(FF)"]
Digit: charset "0123456789"
Digits: [some Digit]
Upper: charset [#"A" - #"Z"]
Lower: charset [#"a" - #"z"]
Alpha: union Upper Lower
Alphas: [some Alpha]
AlphaDigit: union Alpha Digit
AlphaDigits: [some AlphaDigit]
Hex: charset "0123456789ABCDEFabcdef"
Char: union AlphaDigit charset "-_~+*'"
Chars: [some [Char | Escape]]
Escape: [#"%" Hex Hex]
Path: union AlphaDigit charset "-_~+*'/.?=&;{}#"
Domain-Label: Chars
Domain: [Domain-Label any [#"." Domain-Label]]
IP-Address: [Digits #"." Digits #"." Digits #"." Digits]
User: [some [Char | Escape | #"."]]
Host: [Domain | IP-Address]
Email^: [User #"@" Host]
Url^: [["http://" | "ftp://" | "https://"] some Path]
;; function to locate URLs in a string
;; and call an action func when each is found
;; ==========================================
find-urls: func [
String [string!]
action-func [function!]
/local Start Stop
][
parse/all String [
any [
Start: copy url url^ Stop: (
Stop: change/part Start action-func url Stop
print start
)
thru </a> ;; this is dependent on the action-func setting </a> as an end marker
| skip
]
end
]
return String
]
;; example of usage with an action-func that
;; replaces url references with an anchor tag
;; ===========================================
target-string: {this string has this url http://www.test.com/path in it
and also this one: https://www.test.com/example.php}
find-urls target-string
func [url][print url return rejoin [{<a href="} url {">} url </a>]]
probe target-string
{this string has this url <a href="http://www.test.com/path">http://www.test.com/path</a> in it
and also this one: <a href="https://www.test.com/example.php">https://www.test.com/example.php</a>}
Notes
This is a script that detects URLs in face/text
and overlays hyperlinks: http://www.ross-gill.com/r/link-up.html
view layout [
my-text: text read %some.txt
do [link-up my-text]
]
It's based on the pattern in the article below, so you may need to adapt the recognition pattern to your specifications. The links are passed through a to-link
function which by default is the same as to-url