Skip to content

Instantly share code, notes, and snippets.

@softwarespot
Created October 2, 2017 20:04
Show Gist options
  • Save softwarespot/8b67fb33bf7a0f652f21561b7c5343cc to your computer and use it in GitHub Desktop.
Save softwarespot/8b67fb33bf7a0f652f21561b7c5343cc to your computer and use it in GitHub Desktop.
Parse HTML
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