lib/highlighter.js
function(subject, search) {
    var children = [];
    var remaining = subject;

    while (remaining) {
      var remainingCleaned = (this.props.ignoreDiacritics
        ? removeDiacritics(remaining, this.props.diacriticsBlacklist)
        : remaining
      );

      if (!search.test(remainingCleaned)) {
        children.push(this.renderPlain(remaining));
        return children;
      }

      var boundaries = this.getMatchBoundaries(remainingCleaned, search);

      if (boundaries.first === 0 && boundaries.last === 0) {
        // Regex zero-width match
        return children;
      }

      // Capture the string that leads up to a match...
      var nonMatch = remaining.slice(0, boundaries.first);
      if (nonMatch) {
        children.push(this.renderPlain(nonMatch));
      }

      // Now, capture the matching string...
      var match = remaining.slice(boundaries.first, boundaries.last);
      if (match) {
        children.push(this.renderHighlight(match));
      }

      // And if there's anything left over, recursively run this method again.
      remaining = remaining.slice(boundaries.last);

    }

    return children;
  }
function(subject, search) {
    var children = [];
    var remaining = subject;

    while (remaining) {
      var remainingCleaned = (this.props.ignoreDiacritics
        ? removeDiacritics(remaining, this.props.diacriticsBlacklist)
        : remaining
      );

      if (!search.test(remainingCleaned)) {
        children.push(this.renderPlain(remaining));
        return children;
      }

      var boundaries = this.getMatchBoundaries(remainingCleaned, search);

      if (boundaries.first === 0 && boundaries.last === 0) {
        // Regex zero-width match
        return children;
      }

      // Capture the string that leads up to a match...
      var nonMatch = remaining.slice(0, boundaries.first);
      if (nonMatch) {
        children.push(this.renderPlain(nonMatch));
      }

      // Now, capture the matching string...
      var match = remaining.slice(boundaries.first, boundaries.last);
      if (match) {
        children.push(this.renderHighlight(match));
      }

      // And if there's anything left over, recursively run this method again.
      remaining = remaining.slice(boundaries.last);

    }

    return children;
  }
function ( subject , search ) { var children = [ ] ; var remaining = subject ; while ( remaining ) { var remainingCleaned = ( this . props . ignoreDiacritics ? removeDiacritics ( remaining , this . props . diacriticsBlacklist ) : remaining ) ; if ( ! search . test ( remainingCleaned ) ) { children . push ( this . renderPlain ( remaining ) ) ; return children ; } var boundaries = this . getMatchBoundaries ( remainingCleaned , search ) ; if ( boundaries . first === 0 && boundaries . last === 0 ) { // Regex zero-width match return children ; } // Capture the string that leads up to a match... var nonMatch = remaining . slice ( 0 , boundaries . first ) ; if ( nonMatch ) { children . push ( this . renderPlain ( nonMatch ) ) ; } // Now, capture the matching string... var match = remaining . slice ( boundaries . first , boundaries . last ) ; if ( match ) { children . push ( this . renderHighlight ( match ) ) ; } // And if there's anything left over, recursively run this method again. remaining = remaining . slice ( boundaries . last ) ; } return children ; }
Determines which strings of text should be highlighted or not.

@param  {string} subject
The body of text that will be searched for highlighted words.
@param  {string} search
The search used to search for highlighted words.

@return {Array}
An array of ReactElements
Determines which strings of text should be highlighted or not .