Sha256: 4b921d688aa7246e2ff297f5d85e30daf9281e5f1857a9adb4a307562c98c020
Contents?: true
Size: 689 Bytes
Versions: 58
Compression:
Stored size: 689 Bytes
Contents
function regexText(node) { if (node.nodeType == 3) { // is it a text node? const reg = /\*\*(\S+)\*\*/g; const replacement = '<span class="typography__power-text">$1</span>'; const nodeContainsMatch = node.data.search(reg) != -1; if (nodeContainsMatch) { node.parentElement.innerHTML = node.parentElement.innerHTML.replace(reg, replacement); } } if (node.nodeType == 1 && node.nodeName != 'SCRIPT') { for (var i = 0; i < node.childNodes.length; i++) { regexText(node.childNodes[i]); } } } // USAGE: // document.addEventListener('DOMContentLoaded', function() [ // regexText(document.body); // ]); // // export default regexText;
Version data entries
58 entries across 58 versions & 1 rubygems