Created
October 2, 2017 20:04
-
-
Save softwarespot/8b67fb33bf7a0f652f21561b7c5343cc to your computer and use it in GitHub Desktop.
Parse HTML
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
const parse5 = require('parse5'); | |
const document = parse5.parse(` | |
<!DOCTYPE html> | |
<html> | |
<body> | |
<h1 "j"="k">My First Heading</h1> | |
<script>var x = 1 | |
console.log('') | |
</script> | |
</body> | |
</html> | |
`); | |
const Paul = require('paul'); | |
const paul = new Paul(['childNodes']); | |
console.log(parse5.serialize(document)); | |
// paul.depthForEach(document, (node) => { | |
// if (isScriptNode(node)) { | |
// console.log(parse5.serialize(node)); | |
// // console.log(node) | |
// } | |
// }); | |
function isScriptNode(node) { | |
return node.nodeName === 'script'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment