Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fb55/domhandler
Handler for htmlparser2, to get a DOM
https://github.com/fb55/domhandler
dom dom-builder domhandler htmlparser2 tree
Last synced: 12 days ago
JSON representation
Handler for htmlparser2, to get a DOM
- Host: GitHub
- URL: https://github.com/fb55/domhandler
- Owner: fb55
- License: bsd-2-clause
- Created: 2012-08-14T14:52:52.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2024-10-29T13:44:35.000Z (13 days ago)
- Last Synced: 2024-10-29T16:13:16.387Z (13 days ago)
- Topics: dom, dom-builder, domhandler, htmlparser2, tree
- Language: TypeScript
- Homepage: https://domhandler.js.org
- Size: 3.37 MB
- Stars: 339
- Watchers: 7
- Forks: 63
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# domhandler [![Node.js CI](https://github.com/fb55/domhandler/actions/workflows/nodejs-test.yml/badge.svg)](https://github.com/fb55/domhandler/actions/workflows/nodejs-test.yml)
The DOM handler creates a tree containing all nodes of a page.
The tree can be manipulated using the [domutils](https://github.com/fb55/domutils)
or [cheerio](https://github.com/cheeriojs/cheerio) libraries and
rendered using [dom-serializer](https://github.com/cheeriojs/dom-serializer) .## Usage
```javascript
const handler = new DomHandler([ callback(err, dom), ] [ options ]);
// const parser = new Parser(handler[, options]);
```Available options are described below.
## Example
```javascript
const { Parser } = require("htmlparser2");
const { DomHandler } = require("domhandler");
const rawHtml =
"Xyz var foo = '<<bar>>';";
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:
```javascript
[
{
data: "Xyz ",
type: "text",
},
{
type: "script",
name: "script",
attribs: {
language: "javascript",
},
children: [
{
data: "var foo = '';<",
type: "text",
},
],
},
{
data: "