An isomorphic HTML to DOM parser:
Parser(string[, options])
The parser converts an HTML string to a JavaScript object that describes the DOM tree.
NPM:
npm install --save html-dom-parserYarn:
yarn add html-dom-parserCDN:
<script src="https://unpkg.com/html-dom-parser@latest/dist/html-dom-parser.js"></script>Import parser:
// server
var Parser = require('html-dom-parser');
// client
var Parser = window.HTMLDOMParser;Parse input:
Parser('<p>Hello, world!</p>');Return output:
[ { type: 'tag',
name: 'p',
attribs: {},
children:
[ { data: 'Hello, world!',
type: 'text',
next: null,
prev: null,
parent: [Circular] } ],
next: null,
prev: null,
parent: null } ]The server parser is a wrapper of htmlparser2's parseDOM() and the client parser uses the browser's DOM API to mimic the output of the server parser.
$ npm test
$ npm run lint