API Docs for: 3.18.1

Highlight Class

Module: highlight-base
Parent Module: highlight

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.

Item Index

Methods

Properties

Methods

all

(
  • haystack
  • needles
  • [options]
)
String static

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:

  • 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.

    • [startsWith=false] Boolean optional

      If true, matches must be anchored to the beginning of the string.

Returns:

String:

Escaped and highlighted copy of haystack.

allCase

(
  • haystack
  • needles
  • [options]
)
String static

Same as all(), but case-sensitive by default.

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. See all() for details.

Returns:

String:

Escaped and highlighted copy of haystack.

allFold

(
  • haystack
  • needles
  • [options]
)
String static

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:

String:

Escaped and highlighted copy of haystack.

start

(
  • haystack
  • needles
  • [options]
)
String static

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:

String:

Escaped and highlighted copy of haystack.

startCase

(
  • haystack
  • needles
)
String static

Same as start(), but case-sensitive by default.

Parameters:

  • haystack String

    String to apply highlighting to.

  • needles String | String[]

    String or array of strings that should be highlighted.

Returns:

String:

Escaped and highlighted copy of haystack.

startFold

(
  • haystack
  • needles
)
String static

Accent-folding version of start().

Parameters:

  • haystack String

    String to apply highlighting to.

  • needles String | String[]

    String or array of strings that should be highlighted.

Returns:

String:

Escaped and highlighted copy of haystack.

words

(
  • haystack
  • needles
  • [options]
)
String static

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:

String:

Escaped and highlighted copy of haystack.

wordsCase

(
  • haystack
  • needles
)
String static

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:

String:

Escaped and highlighted copy of haystack.

wordsFold

(
  • haystack
  • needles
)
String static

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:

String:

Escaped and highlighted copy of haystack.

Properties