domhandler
Handler for htmlparser2 that turns pages into a dom
Last updated 5 years ago by feedic .
BSD-2-Clause · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install domhandler 
SYNC missed versions from official npm registry.

domhandler Node.js CI

The DOM handler creates a tree containing all nodes of a page. The tree can be manipulated using the domutils or cheerio libraries and rendered using dom-serializer .

Usage

const handler = new DomHandler([ <func> callback(err, dom), ] [ <obj> options ]);
// const parser = new Parser(handler[, options]);

Available options are described below.

Example

const { Parser } = require("htmlparser2");
const { DomHandler } = require("domhandler");
const rawHtml =
    "Xyz <script language= javascript>var foo = '<<bar>>';</script><!--<!-- Waah! -- -->";
const handler = new DomHandler((error, dom) => {
    if (error) {
        // Handle error
    } else {
        // Parsing completed, do something
        console.log(dom);
    }
});
const parser = new Parser(handler);
parser.write(rawHtml);
parser.end();

Output:

[
    {
        data: "Xyz ",
        type: "text",
    },
    {
        type: "script",
        name: "script",
        attribs: {
            language: "javascript",
        },
        children: [
            {
                data: "var foo = '<bar>';<",
                type: "text",
            },
        ],
    },
    {
        data: "<!-- Waah! -- ",
        type: "comment",
    },
];

Option: withStartIndices

Add a startIndex property to nodes. When the parser is used in a non-streaming fashion, startIndex is an integer indicating the position of the start of the node in the document. The default value is false.

Option: withEndIndices

Add an endIndex property to nodes. When the parser is used in a non-streaming fashion, endIndex is an integer indicating the position of the end of the node in the document. The default value is false.


License: BSD-2-Clause

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

Current Tags

  • 6.0.1                                ...           latest (24 days ago)

35 Versions

  • 6.0.1                                ...           24 days ago
  • 6.0.0                                ...           25 days ago
  • 5.0.3                                ...           4 years ago
  • 5.0.2                                ...           4 years ago
  • 5.0.1                                ...           4 years ago
  • 5.0.0                                ...           4 years ago
  • 4.3.1                                ...           4 years ago
  • 4.3.0                                ...           4 years ago
  • 4.2.2                                ...           5 years ago
  • 4.2.1                                ...           5 years ago
  • 4.2.0                                ...           5 years ago
  • 4.1.0                                ...           5 years ago
  • 4.0.0                                ...           5 years ago
  • 3.3.0                                ...           6 years ago
  • 3.2.0                                ...           6 years ago
  • 3.1.0                                ...           6 years ago
  • 3.0.0                                ...           7 years ago
  • 2.4.2                                ...           8 years ago
  • 2.4.1                                ...           9 years ago
  • 2.4.0                                ...           9 years ago
  • 2.3.0                                ...           11 years ago
  • 2.2.1                                ...           11 years ago
  • 2.2.0                                ...           12 years ago
  • 2.1.0                                ...           13 years ago
  • 2.0.3                                ...           13 years ago
  • 2.0.2                                ...           13 years ago
  • 2.0.1                                ...           13 years ago
  • 2.0.0                                ...           13 years ago
  • 1.3.2                                ...           14 years ago
  • 1.3.1                                ...           14 years ago
  • 1.3.0                                ...           14 years ago
  • 1.2.0                                ...           14 years ago
  • 1.1.0                                ...           14 years ago
  • 1.0.1                                ...           14 years ago
  • 1.0.0                                ...           14 years ago

Copyright 2013 - present © cnpmjs.org | Home |