Index: branches/wmf/1.17wmf1/resources/jquery/jquery.highlightText.js |
— | — | @@ -21,10 +21,12 @@ |
22 | 22 | // if this is a text node |
23 | 23 | if ( node.nodeType == 3 ) { |
24 | 24 | // TODO - need to be smarter about the character matching here. |
25 | | - // non latin characters can make regex think a new word has begun. |
26 | | - // look for an occurence of our pattern and store the starting position |
27 | | - var pos = node.data.search( new RegExp( "\\b" + $.escapeRE( pat ), "i" ) ); |
28 | | - if ( pos >= 0 ) { |
| 25 | + // non latin characters can make regex think a new word has begun: do not use \b |
| 26 | + // http://stackoverflow.com/questions/3787072/regex-wordwrap-with-utf8-characters-in-js |
| 27 | + // look for an occurence of our pattern and store the starting position |
| 28 | + var match = node.data.match( new RegExp( "(^|\\s)" + $.escapeRE( pat ), "i" ) ); |
| 29 | + if ( match ) { |
| 30 | + var pos = match.index + match[1].length; // include length of any matched spaces |
29 | 31 | // create the span wrapper for the matched text |
30 | 32 | var spannode = document.createElement( 'span' ); |
31 | 33 | spannode.className = 'highlight'; |