The goog.dom.annotate Namespace

.annotateTerms(node, terms, annotateFn, opt_ignoreCase, opt_classesToSkip, opt_maxMs)

Calls {@code annotateFn} for each occurrence of a search term in text nodes under {@code node}. Returns the number of hits.

node {Node}
A DOM node.
terms {Array}
An array of [searchTerm, matchWholeWordOnly] tuples. The matchWholeWordOnly value is a per-term attribute because some terms may be CJK, while others are not. (For correctness, matchWholeWordOnly should always be false for CJK terms.).
annotateFn {Function}
A function that takes (1) the number of the term that is "hit", (2) the HTML string (search term) to be annotated, and returns the annotated term as an HTML string.
opt_ignoreCase {*=}
Whether to ignore the case of the query terms when looking for matches.
opt_classesToSkip {Array.<string>=}
Nodes with one of these CSS class names (and its descendants) will be skipped.
opt_maxMs {number=}
Number of milliseconds after which this function, if still annotating, should stop and return.
returns {boolean}
Whether any terms were annotated.

.annotateText(text, terms, annotateFn, opt_ignoreCase)

Annotates occurrences of query terms in plain text. This process consists of identifying all occurrences of all query terms, calling a provided function to get the appropriate replacement HTML for each occurrence, and HTML-escaping all the text.

text {string}
The plain text to be searched.
terms {Array}
An array of [{string} searchTerm, {boolean} matchWholeWordOnly] tuples. The matchWholeWordOnly value is a per-term attribute because some terms may be CJK, while others are not. (For correctness, matchWholeWordOnly should always be false for CJK terms.).
annotateFn {Function}
{function(number, string) : string} A function that takes (1) the number of the term that is "hit", (2) the HTML string (search term) to be annotated, and returns the annotated term as an HTML string.
opt_ignoreCase {*=}
Whether to ignore the case of the query terms when looking for matches.
returns {?string}
The HTML equivalent of {@code text} with terms annotated, or null if the text did not contain any of the terms.