Skip to content

Instantly share code, notes, and snippets.

@andrejewski
Last active October 27, 2018 08:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrejewski/773487d4f4a46b16865405d7b74eabf9 to your computer and use it in GitHub Desktop.
Save andrejewski/773487d4f4a46b16865405d7b74eabf9 to your computer and use it in GitHub Desktop.
Strip whitespace from Himalaya output
function removeEmptyNodes (nodes) {
return nodes.filter(node => {
if (node.type === 'element') {
node.children = removeEmptyNodes(node.children);
return true
}
return node.content.length
})
}
function stripWhitespace (nodes) {
return nodes.map(node => {
if (node.type === 'element') {
node.children = stripWhitespace(node.children)
} else {
node.content = node.content.trim()
}
return node
})
}
function removeWhitespace(nodes) {
return removeEmptyNodes(stripWhitespace(nodes))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment