5.0....no nifty MX stuff. ----- Original Message ----- From: "Ben Doom" <[EMAIL PROTECTED]> To: "CF-Community" <[EMAIL PROTECTED]> Sent: Monday, September 08, 2003 1:17 PM Subject: RE: highlight UDF
> What version of CF? > > I might be able to come up with a better way using lookahead... > > > -- Ben Doom > Programmer & General Lackey > Moonbow Software, Inc > > : -----Original Message----- > : From: Deanna Schneider [mailto:[EMAIL PROTECTED] > : Sent: Monday, September 08, 2003 1:43 PM > : To: CF-Community > : Subject: highlight UDF > : > : > : Hey folks, > : I suck at regex, which is why I helped sponsor that little tool that Mike > : found, but I'm still having trouble figuring this out. And, since it was > : originally written by Raymond, I thought I'd throw this out here. > : > : There's this UDF, which we already modified once to use a span > : class instead > : of just a simple background color, that highlights a search term. But, if > : the search term happens to contain the letters inside the span, like say, > : for instance, if someone searchs for "pan", the UDF overwrites the span > : text. I'm sure there's a way to write the regex to look for the > : search term > : except when it's in this "<span class="hlt">anythinghere</span>" > : but I don't > : know how to do it. Here's the UDF: > : <cfscript> > : /** > : * Applies a simple highlight to a word in a string. > : * > : * @param string The string to format. > : * @param word The word to highlight. > : * @param front This is the HTML that will be placed in front of the > : highlighted match. It defaults to <span style= > : * @param back This is the HTML that will be placed at the end of the > : highlighted match. Defaults to </span> > : * @param matchCase If true, the highlight will only match when the case > : is the same. Defaults to false. > : * @author Raymond Camden ([EMAIL PROTECTED]) > : * @version 1, July 30, 2001 > : */ > : function highLight(str, wordList) { > : > : > : /** > : * Modification by Kevin Graeme > : * Added a class descriptor called "hlt" to the global css styles, > : * and changed the span style from a direct style to a called class. > : * This resolves a Netscape 4.x CSS implementation problem. > : */ > : /* var front = "<span style=""background-color: yellow;"">"; */ > : var front = "<span class=""hlt"">"; > : var back = "</span>"; > : var matchCase = false; > : > : //check for empty word list, this is the base condition for the recursion > : if(ListLen(wordList) Lt 1) > : return str; > : else > : word = ListFirst(wordList); > : > : if(ArrayLen(arguments) GTE 3) front = arguments[3]; > : if(ArrayLen(arguments) GTE 4) back = arguments[4]; > : if(ArrayLen(arguments) GTE 5) matchCase = arguments[5]; > : > : > : if(Not matchCase) > : CurTxt = REReplaceNoCase(str,"(#word#)","#front#\1#back#","ALL"); > : else > : CurTxt = REReplace(str,"(#word#)","#front#\1#back#","ALL"); > : > : return Highlight(CurTxt, ListRest(wordList), front, back, matchCase); > : > : } > : > : </cfscript> > : > : > : > : > : --------------------------------------------------------- > : Deanna Schneider > : UWEX-Cooperative Extension > : Interactive Media Developer > : > : > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Archives: http://www.houseoffusion.com/lists.cfm?link=t:5 Subscription: http://www.houseoffusion.com/lists.cfm?link=s:5 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.5 Signup for the Fusion Authority news alert and keep up with the latest news in ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm
