Package Exports
- html-dom-parser
- html-dom-parser/index.js
- html-dom-parser/lib/html-to-dom-client
- html-dom-parser/lib/html-to-dom-client.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (html-dom-parser) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
html-dom-parser
HTML to DOM parser that works on both the server (Node.js) and the client (browser):
HTMLDOMParser(string[, options])It converts an HTML string to a JavaScript object that describes the DOM tree.
Example:
var parse = require('html-dom-parser');
parse('<div>text</div>');Output:
[ { type: 'tag',
name: 'div',
attribs: {},
children:
[ { data: 'text',
type: 'text',
next: null,
prev: null,
parent: [Circular] } ],
next: null,
prev: null,
parent: null } ]
Installation
NPM:
$ npm install html-dom-parser --saveYarn:
$ yarn add html-dom-parserCDN:
<script src="https://unpkg.com/html-dom-parser@latest/dist/html-dom-parser.js"></script>
<script>
window.HTMLDOMParser(/* string */);
</script>Usage
Import the module:
// CommonJS
var parse = require('html-dom-parser');
// ES Modules
import parse from 'html-dom-parser';Parse markup:
parse('<p class="primary" style="color: skyblue;">Hello world</p>');Output:
[ { type: 'tag',
name: 'p',
attribs: { class: 'primary', style: 'color: skyblue;' },
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; the client parser mimics the server parser by using the DOM API.
Testing
Run server and client tests:
$ npm testGenerate HTML coverage report for server tests:
$ npx nyc report --reporter=htmlLint files:
$ npm run lint
# fix lint errors
$ npm run lint:fixTest TypeScript declaration file for style and correctness:
$ npm run lint:dtsRelease
Only collaborators with credentials can release and publish:
$ npm run release
$ git push --follow-tags && npm publish