Skip to content

Added changes to highlight function #73

Description

@ayotundeoludahunsi

function highlight(str, term) {
--------------------------------- ADDED CHANGES ----------------------------------------------------------
term = term.replace(/^\s+|\s+$/g, '') //replace trailing spaces
term = term.replace(/\s\s+/g, '|') //replace all spaces, tabs, newlines by | => regex OR,
//instead of using "term" as a single word

            var highlight_regex = new RegExp('(' + term + ')', 'gi');
            return str.replace(highlight_regex,
                '<span class="highlight">$1</span>');
        };

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions