"use strict"; /** * highlight v3 | MIT license | Johann Burkard * Highlights arbitrary terms in a node. * * - Modified by Marshal 2011-6-24 (added regex) * - Modified by Brian Reavis 2012-8-27 (cleanup) */ Object.defineProperty(exports, "__esModule", { value: true }); exports.removeHighlight = exports.highlight = void 0; const vanilla_ts_1 = require("../vanilla.js"); const highlight = (element, regex) => { if (regex === null) return; // convet string to regex if (typeof regex === 'string') { if (!regex.length) return; regex = new RegExp(regex, 'i'); } // Wrap matching part of text node with highlighting , e.g. // Soccer -> Soccer for regex = /soc/i const highlightText = (node) => { var match = node.data.match(regex); if (match && node.data.length > 0) { var spannode = document.createElement('span'); spannode.className = 'highlight'; var middlebit = node.splitText(match.index); middlebit.splitText(match[0].length); var middleclone = middlebit.cloneNode(true); spannode.appendChild(middleclone); (0, vanilla_ts_1.replaceNode)(middlebit, spannode); return 1; } return 0; }; // Recurse element node, looking for child text nodes to highlight, unless element // is childless,