Last active
October 27, 2018 08:53
-
-
Save andrejewski/773487d4f4a46b16865405d7b74eabf9 to your computer and use it in GitHub Desktop.
Strip whitespace from Himalaya output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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