JSPM

  • Created
  • Published
  • Downloads 2354680
  • Score
    100M100P100Q198442F
  • License MIT

An HTML to DOM parser that works on the server and client.

Package Exports

  • html-dom-parser
  • html-dom-parser/index.js
  • 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

NPM

NPM version Build Status Coverage Status Dependency status

An HTML to DOM parser that works on both the server and the browser:

HTMLDOMParser(string[, options])

The parser converts an HTML string to a JavaScript object that describes the DOM tree.

repl.it | JSFiddle

Installation

NPM:

$ npm install html-dom-parser --save

Yarn:

$ yarn add html-dom-parser

unpkg (CDN):

<script src="https://unpkg.com/html-dom-parser@latest/dist/html-dom-parser.js"></script>
<script>
  window.HTMLDOMParser(/* string */);
</script>

Usage

Import parser:

// server
var parser = require('html-dom-parser');

// client
var parser = window.HTMLDOMParser;

Parse input:

parser('<p>Hello, world!</p>');

Get output:

[ { type: 'tag',
    name: 'p',
    attribs: {},
    children:
     [ { data: 'Hello, world!',
         type: 'text',
         next: null,
         prev: null,
         parent: [Circular] } ],
    next: null,
    prev: null,
    parent: null } ]

On the server-side (Node.js), the parser is a wrapper of parseDOM from htmlparser2.

On the client-side (browser), the parser uses the DOM API to mimic the output schema of the server parser.

Testing

$ npm test
$ npm run lint # npm run lint:fix
$ npm run dtslint

License

MIT