Skip to content

Instantly share code, notes, and snippets.

@jahvi
Created August 11, 2019 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jahvi/f3c3975fd9947c4f908fd0d4b8ac4cf1 to your computer and use it in GitHub Desktop.
Save jahvi/f3c3975fd9947c4f908fd0d4b8ac4cf1 to your computer and use it in GitHub Desktop.
import { parse } from 'node-html-parser';
const root = parse('<ul id="list"><li>Hello World</li></ul>');
console.log(root.firstChild.structure);
// ul#list
// li
// #text
console.log(root.querySelector('#list'));
// { tagName: 'ul',
// rawAttrs: 'id="list"',
// childNodes:
// [ { tagName: 'li',
// rawAttrs: '',
// childNodes: [Object],
// classNames: [] } ],
// id: 'list',
// classNames: [] }
console.log(root.toString());
// <ul id="list"><li>Hello World</li></ul>
root.set_content('<li>Hello World</li>');
root.toString(); // <li>Hello World</li>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment