walk = document.createTreeWalker(document, NodeFilter.SHOW_TEXT, null, false); | |
prevSentence = ""; | |
sentences = ['']; | |
while(n=walk.nextNode()) { | |
nextSentences = n.nodeValue.split('.'); | |
sentences[sentences.length - 1] += nextSentences.pop(); | |
sentences = sentences.concat(nextSentences); | |
} | |
sentences.forEach(function(sentence){ | |
if(/test/gi.test(sentence)) console.log(sentence); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment