Skip to content

Commit

Permalink
Merge 9f47477 into 26d76cb
Browse files Browse the repository at this point in the history
  • Loading branch information
micahjon committed Nov 4, 2016
2 parents 26d76cb + 9f47477 commit bedb74b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/contrib/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ var highlight = function($element, pattern) {

var highlight = function(node) {
var skip = 0;
// Wrap matching part of text node with highlighting <span>, e.g.
// Soccer -> <span class="highlight">Soc</span>cer for regex = /soc/i
if (node.nodeType === 3) {
var pos = node.data.search(regex);
if (pos >= 0 && node.data.length > 0) {
Expand All @@ -25,7 +27,10 @@ var highlight = function($element, pattern) {
middlebit.parentNode.replaceChild(spannode, middlebit);
skip = 1;
}
} else if (node.nodeType === 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) {
}
// Recurse element node, looking for child text nodes to highlight, unless element
// is childless, <script>, <style>, or already highlighted: <span class="hightlight">
else if (node.nodeType === 1 && node.childNodes && !/(script|style)/i.test(node.tagName) && ( node.className !== 'highlight' || node.tagName !== 'SPAN' )) {
for (var i = 0; i < node.childNodes.length; ++i) {
i += highlight(node.childNodes[i]);
}
Expand Down

0 comments on commit bedb74b

Please sign in to comment.