hiliting all instances of a string in a field
frank at backtalk.com
Wed Mar 3 15:48:11 CST 2004
On Wednesday, March 3, 2004, at 06:05 PM,
use-revolution-request at lists.runrev.com wrote:
>>> Has anyone written a function that will find all instances of a
>>> string in the htmlText of a field EXCEPT if it appears in a tag such
>>> as <a></a>? I need to hilite all instances of the string in the
>>> field. I figure I'm either missing a really obvious function already
>>> in Rev that will do it or I need a fancy regular expression.
Is this the kind of thing you want to do?
That was pretty easy to do:
1. Remove all < > and / from the topic string (the topic string is the
string you're wanting to hilite)
2. split the html you're wanting to hilite using the topic string.
Unfortunately you can't use Transcript's "split" command because it
only splits on a character, but you can use offset to simulate a string
3. as you step through each found topic string, look for the next ">"
and next "<" characters. Call the offset of the "<" character
nextOpen, and the offset of the ">" character nextClose.
4. Check whether to hilite or not:
If nextClose < nextOpen then
' we're in the middle of a tag, so don't hilite it
'we're not in a tag, so hilite the topic string
'do this by replacing the topic string you've found with this
' "<span class=" & quote & hiliterCssName & quote & ">" &
topicStr & "</span>"
5. You can find the css value for hiliterCssName by looking in the css
file for the above referenced page.
More information about the use-livecode