Highlight Class
+ + + + +Provides methods for highlighting strings within other strings by wrapping +them in HTML.
+ +The highlight methods first escape any special HTML characters in the input
+strings and then highlight the appropriate substrings by wrapping them in a
+<b class="yui3-highlight"></b> element. The <b> element is used rather than
+<strong> in accordance with HTML5's definition of <b> as being purely
+presentational, which is exactly what highlighting is.
-
+
- Index + + +
- Methods + + +
- Properties + + + +
Item Index
+ + +Methods
+ +-
+
+
- + all + + + static + + + + +
- + allCase + + + static + + + + +
- + allFold + + + static + + + + +
- + start + + + static + + + + +
- + startCase + + + static + + + + +
- + startFold + + + static + + + + +
- + words + + + static + + + + +
- + wordsCase + + + static + + + + +
- + wordsFold + + + static + + + + +
Properties
+ +-
+
+
- + _REGEX + + + static + + + + +
- + _REPLACER + + + static + + + + +
- + _START_REGEX + + + static + + + + +
- + _TEMPLATE + + + static + + + + +
Methods
+ + +all
+
+
+ -
+
+
-
+
+
haystack+ +
+
+ -
+
+
needles+ +
+
+ -
+
+
[options]+ +
+
+
Highlights all occurrences in the haystack string of the items in the +needles array, regardless of where they occur. The returned string will +have all HTML characters escaped except for the highlighting markup.
+Parameters:
+ + +Returns:
+ +allCase
+
+
+ -
+
+
-
+
+
haystack+ +
+
+ -
+
+
needles+ +
+
+ -
+
+
[options]+ +
+
+
Same as all(), but case-sensitive by default.
Parameters:
+ + +Returns:
+ +allFold
+
+
+ -
+
+
-
+
+
haystack+ +
+
+ -
+
+
needles+ +
+
+ -
+
+
[options]+ +
+
+
Accent-folding version of all().
Parameters:
+ +-
+
+
-
+
+
haystack+ String + + + + +++ + +String to apply highlighting to.
+
+
+ -
+
+
needles+ String | String[] + + + + +++ + +String or array of strings that should be + highlighted.
+
+
+ -
+
+
[options]+ Object + optional + + + + +++ + +Options object.
+-
+
+
-
+
+
[startsWith=false]+ Boolean + optional + + +++ + +If
+true, matches must be + anchored to the beginning of the string.
+
+
+
+ -
+
+
Returns:
+ +start
+
+
+ -
+
+
-
+
+
haystack+ +
+
+ -
+
+
needles+ +
+
+ -
+
+
[options]+ +
+
+
Highlights needles that occur at the start of haystack. The returned +string will have all HTML characters escaped except for the highlighting +markup.
+Parameters:
+ +-
+
+
-
+
+
haystack+ String + + + + +++ + +String to apply highlighting to.
+
+
+ -
+
+
needles+ String | String[] + + + + +++ + +String or array of strings that should be + highlighted.
+
+
+ -
+
+
[options]+ Object + optional + + + + +++ + +Options object.
+-
+
+
-
+
+
[caseSensitive=false]+ Boolean + optional + + +++ + +If
+true, matching will + be case-sensitive.
+
+
+
+ -
+
+
Returns:
+ +startCase
+
+
+ -
+
+
-
+
+
haystack+ +
+
+ -
+
+
needles+ +
+
+
Same as start(), but case-sensitive by default.
Parameters:
+ + +Returns:
+ +startFold
+
+
+ -
+
+
-
+
+
haystack+ +
+
+ -
+
+
needles+ +
+
+
Accent-folding version of start().
Parameters:
+ + +Returns:
+ +words
+
+
+ -
+
+
-
+
+
haystack+ +
+
+ -
+
+
needles+ +
+
+ -
+
+
[options]+ +
+
+
Highlights complete words in the haystack string that are also in the +needles array. The returned string will have all HTML characters escaped +except for the highlighting markup.
+Parameters:
+ +-
+
+
-
+
+
haystack+ String + + + + +++ + +String to apply highlighting to.
+
+
+ -
+
+
needles+ String | String[] + + + + +++ + +String or array of strings containing words + that should be highlighted. If a string is passed, it will be split + into words; if an array is passed, it is assumed to have already been + split.
+
+
+ -
+
+
[options]+ Object + optional + + + + +++ + +Options object.
+-
+
+
-
+
+
[caseSensitive=false]+ Boolean + optional + + +++ + +If
+true, matching will + be case-sensitive.
+
+
+
+ -
+
+
Returns:
+ +wordsCase
+
+
+ -
+
+
-
+
+
haystack+ +
+
+ -
+
+
needles+ +
+
+
Same as words(), but case-sensitive by default.
Parameters:
+ +-
+
+
-
+
+
haystack+ String + + + + +++ + +String to apply highlighting to.
+
+
+ -
+
+
needles+ String | String[] + + + + +++ + +String or array of strings containing words + that should be highlighted. If a string is passed, it will be split + into words; if an array is passed, it is assumed to have already been + split.
+
+
+
Returns:
+ +wordsFold
+
+
+ -
+
+
-
+
+
haystack+ +
+
+ -
+
+
needles+ +
+
+
Accent-folding version of words().
Parameters:
+ +-
+
+
-
+
+
haystack+ String + + + + +++ + +String to apply highlighting to.
+
+
+ -
+
+
needles+ String | String[] + + + + +++ + +String or array of strings containing words + that should be highlighted. If a string is passed, it will be split + into words; if an array is passed, it is assumed to have already been + split.
+
+
+
Returns:
+ +Properties
+ + +_REGEX
+ String
+
+
+
+
+ protected
+
+
+
+ final
+
+
+
+ static
+
+
+
+
+ Regular expression template for highlighting a match that occurs anywhere
+in a string. The placeholder %needles will be replaced with a list of
+needles to match, joined by | characters.
This regex should have two capturing subpatterns:
+ +-
+
- Zero or one unclosed HTML entity (e.g. "&" without a ";" at the + end). +
- The
%needlesplaceholder.
+
The first subpattern match is used to emulate a negative lookbehind +assertion in order to prevent highlighting inside HTML entities.
+_REPLACER
+ Function | String
+
+
+
+
+ protected
+
+
+
+ final
+
+
+
+ static
+
+
+
+
+ Regex replacer function or string for normal matches.
+_START_REGEX
+ String
+
+
+
+
+ protected
+
+
+
+ final
+
+
+
+ static
+
+
+
+
+ Regular expression template for highlighting start-of-string matches
+(i.e., only matches that occur at the beginning of a string). The
+placeholder %needles will be replaced with a list of needles to match,
+joined by | characters.
See _REGEX for a description of the capturing subpatterns this regex
+string should contain.
_TEMPLATE
+ String
+
+
+
+
+ protected
+
+
+
+ final
+
+
+
+ static
+
+
+
+
+ Highlight template which will be used as a replacement for matched
+substrings. The placeholder {s} will be replaced with the matched
+substring.
Default: '<b class="yui3-highlight">{s}</b>'
+ + + + + +