Skip to content

Instantly share code, notes, and snippets.

@daniellizik
Created July 13, 2017 15:32
Show Gist options
  • Save daniellizik/ec5cd5f12aa9cb8512003aa7b2a70aaa to your computer and use it in GitHub Desktop.
Save daniellizik/ec5cd5f12aa9cb8512003aa7b2a70aaa to your computer and use it in GitHub Desktop.
.textContent but with parse5
import { parseFragment } from 'parse5'
const walk = (node = {}) => {
return (node.value || '') + (node.childNodes || []).reduce((child) => {
return walk(child)
})
}
export default (htmlStr) => [parseFragment(htmlStr)].reduce(walk)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment