update
This commit is contained in:
+108
-35
@@ -2,70 +2,129 @@
|
||||
|
||||
[](https://npmjs.org/package/htmlparser2)
|
||||
[](https://npmjs.org/package/htmlparser2)
|
||||
[](http://travis-ci.org/fb55/htmlparser2)
|
||||
[](https://github.com/fb55/htmlparser2/actions?query=workflow%3A%22Node.js+Test%22)
|
||||
[](https://coveralls.io/r/fb55/htmlparser2)
|
||||
|
||||
A forgiving HTML/XML/RSS parser. The parser can handle streams and provides a callback interface.
|
||||
The fast & forgiving HTML/XML parser.
|
||||
|
||||
## Installation
|
||||
npm install htmlparser2
|
||||
|
||||
A live demo of htmlparser2 is available [here](https://astexplorer.net/#/2AmVrGuGVJ).
|
||||
npm install htmlparser2
|
||||
|
||||
A live demo of `htmlparser2` is available [here](https://astexplorer.net/#/2AmVrGuGVJ).
|
||||
|
||||
## Ecosystem
|
||||
|
||||
| Name | Description |
|
||||
| ------------------------------------------------------------- | ------------------------------------------------------- |
|
||||
| [htmlparser2](https://github.com/fb55/htmlparser2) | Fast & forgiving HTML/XML parser |
|
||||
| [domhandler](https://github.com/fb55/domhandler) | Handler for htmlparser2 that turns documents into a DOM |
|
||||
| [domutils](https://github.com/fb55/domutils) | Utilities for working with domhandler's DOM |
|
||||
| [css-select](https://github.com/fb55/css-select) | CSS selector engine, compatible with domhandler's DOM |
|
||||
| [cheerio](https://github.com/cheeriojs/cheerio) | The jQuery API for domhandler's DOM |
|
||||
| [dom-serializer](https://github.com/cheeriojs/dom-serializer) | Serializer for domhandler's DOM |
|
||||
|
||||
## Usage
|
||||
|
||||
`htmlparser2` itself provides a callback interface that allows consumption of documents with minimal allocations.
|
||||
For a more ergonomic experience, read [Getting a DOM](#getting-a-dom) below.
|
||||
|
||||
```javascript
|
||||
var htmlparser = require("htmlparser2");
|
||||
var parser = new htmlparser.Parser({
|
||||
onopentag: function(name, attribs){
|
||||
if(name === "script" && attribs.type === "text/javascript"){
|
||||
console.log("JS! Hooray!");
|
||||
}
|
||||
},
|
||||
ontext: function(text){
|
||||
console.log("-->", text);
|
||||
},
|
||||
onclosetag: function(tagname){
|
||||
if(tagname === "script"){
|
||||
console.log("That's it?!");
|
||||
}
|
||||
}
|
||||
}, {decodeEntities: true});
|
||||
parser.write("Xyz <script type='text/javascript'>var foo = '<<bar>>';</ script>");
|
||||
const htmlparser2 = require("htmlparser2");
|
||||
const parser = new htmlparser2.Parser({
|
||||
onopentag(name, attributes) {
|
||||
/*
|
||||
* This fires when a new tag is opened.
|
||||
*
|
||||
* If you don't need an aggregated `attributes` object,
|
||||
* have a look at the `onopentagname` and `onattribute` events.
|
||||
*/
|
||||
if (name === "script" && attributes.type === "text/javascript") {
|
||||
console.log("JS! Hooray!");
|
||||
}
|
||||
},
|
||||
ontext(text) {
|
||||
/*
|
||||
* Fires whenever a section of text was processed.
|
||||
*
|
||||
* Note that this can fire at any point within text and you might
|
||||
* have to stich together multiple pieces.
|
||||
*/
|
||||
console.log("-->", text);
|
||||
},
|
||||
onclosetag(tagname) {
|
||||
/*
|
||||
* Fires when a tag is closed.
|
||||
*
|
||||
* You can rely on this event only firing when you have received an
|
||||
* equivalent opening tag before. Closing tags without corresponding
|
||||
* opening tags will be ignored.
|
||||
*/
|
||||
if (tagname === "script") {
|
||||
console.log("That's it?!");
|
||||
}
|
||||
},
|
||||
});
|
||||
parser.write(
|
||||
"Xyz <script type='text/javascript'>const foo = '<<bar>>';</ script>"
|
||||
);
|
||||
parser.end();
|
||||
```
|
||||
|
||||
Output (simplified):
|
||||
Output (with multiple text events combined):
|
||||
|
||||
```
|
||||
--> Xyz
|
||||
JS! Hooray!
|
||||
--> var foo = '<<bar>>';
|
||||
--> const foo = '<<bar>>';
|
||||
That's it?!
|
||||
```
|
||||
|
||||
## Documentation
|
||||
This example only shows three of the possible events.
|
||||
Read more about the parser, its events and options in the [wiki](https://github.com/fb55/htmlparser2/wiki/Parser-options).
|
||||
|
||||
Read more about the parser and its options in the [wiki](https://github.com/fb55/htmlparser2/wiki/Parser-options).
|
||||
### Usage with streams
|
||||
|
||||
## Get a DOM
|
||||
The `DomHandler` (known as `DefaultHandler` in the original `htmlparser` module) produces a DOM (document object model) that can be manipulated using the [`DomUtils`](https://github.com/fb55/DomUtils) helper.
|
||||
While the `Parser` interface closely resembles Node.js streams, it's not a 100% match.
|
||||
Use the `WritableStream` interface to process a streaming input:
|
||||
|
||||
The `DomHandler`, while still bundled with this module, was moved to its [own module](https://github.com/fb55/domhandler). Have a look at it for further information.
|
||||
```javascript
|
||||
const { WritableStream } = require("htmlparser2/lib/WritableStream");
|
||||
const parserStream = new WritableStream({
|
||||
ontext(text) {
|
||||
console.log("Streaming:", text);
|
||||
},
|
||||
});
|
||||
|
||||
const htmlStream = fs.createReadStream("./my-file.html");
|
||||
htmlStream.pipe(parserStream).on("finish", () => console.log("done"));
|
||||
```
|
||||
|
||||
## Getting a DOM
|
||||
|
||||
The `DomHandler` produces a DOM (document object model) that can be manipulated using the [`DomUtils`](https://github.com/fb55/DomUtils) helper.
|
||||
|
||||
```js
|
||||
const htmlparser2 = require("htmlparser2");
|
||||
|
||||
const dom = htmlparser2.parseDocument();
|
||||
```
|
||||
|
||||
The `DomHandler`, while still bundled with this module, was moved to its [own module](https://github.com/fb55/domhandler).
|
||||
Have a look at that for further information.
|
||||
|
||||
## Parsing RSS/RDF/Atom Feeds
|
||||
|
||||
```javascript
|
||||
new htmlparser.FeedHandler(function(<error> error, <object> feed){
|
||||
...
|
||||
});
|
||||
const feed = htmlparser2.parseFeed(content, options);
|
||||
```
|
||||
|
||||
Note: While the provided feed handler works for most feeds, you might want to use [danmactough/node-feedparser](https://github.com/danmactough/node-feedparser), which is much better tested and actively maintained.
|
||||
Note: While the provided feed handler works for most feeds,
|
||||
you might want to use [danmactough/node-feedparser](https://github.com/danmactough/node-feedparser), which is much better tested and actively maintained.
|
||||
|
||||
## Performance
|
||||
|
||||
After having some artificial benchmarks for some time, __@AndreasMadsen__ published his [`htmlparser-benchmark`](https://github.com/AndreasMadsen/htmlparser-benchmark), which benchmarks HTML parses based on real-world websites.
|
||||
After having some artificial benchmarks for some time, **@AndreasMadsen** published his [`htmlparser-benchmark`](https://github.com/AndreasMadsen/htmlparser-benchmark), which benchmarks HTML parses based on real-world websites.
|
||||
|
||||
At the time of writing, the latest versions of all supported parsers show the following performance characteristics on [Travis CI](https://travis-ci.org/AndreasMadsen/htmlparser-benchmark/builds/10805007) (please note that Travis doesn't guarantee equal conditions for all tests):
|
||||
|
||||
@@ -84,8 +143,22 @@ sax : 49.6513 ms/file ± 26.6032
|
||||
|
||||
## How does this module differ from [node-htmlparser](https://github.com/tautologistics/node-htmlparser)?
|
||||
|
||||
This is a fork of the `htmlparser` module. The main difference is that this is intended to be used only with node (it runs on other platforms using [browserify](https://github.com/substack/node-browserify)). `htmlparser2` was rewritten multiple times and, while it maintains an API that's compatible with `htmlparser` in most cases, the projects don't share any code anymore.
|
||||
This module started as a fork of the `htmlparser` module.
|
||||
The main difference is that `htmlparser2` is intended to be used only with node (it runs on other platforms using [browserify](https://github.com/substack/node-browserify)).
|
||||
`htmlparser2` was rewritten multiple times and, while it maintains an API that's compatible with `htmlparser` in most cases, the projects don't share any code anymore.
|
||||
|
||||
The parser now provides a callback interface close to [sax.js](https://github.com/isaacs/sax-js) (originally targeted at [readabilitySAX](https://github.com/fb55/readabilitysax)). As a result, old handlers won't work anymore.
|
||||
The parser now provides a callback interface inspired by [sax.js](https://github.com/isaacs/sax-js) (originally targeted at [readabilitySAX](https://github.com/fb55/readabilitysax)).
|
||||
As a result, old handlers won't work anymore.
|
||||
|
||||
The `DefaultHandler` and the `RssHandler` were renamed to clarify their purpose (to `DomHandler` and `FeedHandler`). The old names are still available when requiring `htmlparser2`, your code should work as expected.
|
||||
|
||||
## Security contact information
|
||||
|
||||
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security).
|
||||
Tidelift will coordinate the fix and disclosure.
|
||||
|
||||
## `htmlparser2` for enterprise
|
||||
|
||||
Available as part of the Tidelift Subscription
|
||||
|
||||
The maintainers of `htmlparser2` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-htmlparser2?utm_source=npm-htmlparser2&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import MultiplexHandler from "./MultiplexHandler";
|
||||
import { Handler } from "./Parser";
|
||||
export declare class CollectingHandler extends MultiplexHandler {
|
||||
private readonly cbs;
|
||||
events: [keyof Handler, ...unknown[]][];
|
||||
constructor(cbs?: Partial<Handler>);
|
||||
onreset(): void;
|
||||
restart(): void;
|
||||
}
|
||||
//# sourceMappingURL=CollectingHandler.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"CollectingHandler.d.ts","sourceRoot":"","sources":["../src/CollectingHandler.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAInC,qBAAa,iBAAkB,SAAQ,gBAAgB;IAGvC,OAAO,CAAC,QAAQ,CAAC,GAAG;IAFzB,MAAM,EAAE,CAAC,MAAM,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC,EAAE,CAAM;gBAEvB,GAAG,GAAE,OAAO,CAAC,OAAO,CAAM;IAOvD,OAAO,IAAI,IAAI;IAKf,OAAO,IAAI,IAAI;CAOlB"}
|
||||
+57
-54
@@ -1,57 +1,60 @@
|
||||
module.exports = CollectingHandler;
|
||||
|
||||
function CollectingHandler(cbs) {
|
||||
this._cbs = cbs || {};
|
||||
this.events = [];
|
||||
}
|
||||
|
||||
var EVENTS = require("./").EVENTS;
|
||||
Object.keys(EVENTS).forEach(function(name) {
|
||||
if (EVENTS[name] === 0) {
|
||||
name = "on" + name;
|
||||
CollectingHandler.prototype[name] = function() {
|
||||
this.events.push([name]);
|
||||
if (this._cbs[name]) this._cbs[name]();
|
||||
};
|
||||
} else if (EVENTS[name] === 1) {
|
||||
name = "on" + name;
|
||||
CollectingHandler.prototype[name] = function(a) {
|
||||
this.events.push([name, a]);
|
||||
if (this._cbs[name]) this._cbs[name](a);
|
||||
};
|
||||
} else if (EVENTS[name] === 2) {
|
||||
name = "on" + name;
|
||||
CollectingHandler.prototype[name] = function(a, b) {
|
||||
this.events.push([name, a, b]);
|
||||
if (this._cbs[name]) this._cbs[name](a, b);
|
||||
};
|
||||
} else {
|
||||
throw Error("wrong number of arguments");
|
||||
}
|
||||
});
|
||||
|
||||
CollectingHandler.prototype.onreset = function() {
|
||||
this.events = [];
|
||||
if (this._cbs.onreset) this._cbs.onreset();
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
||||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
||||
to[j] = from[i];
|
||||
return to;
|
||||
};
|
||||
|
||||
CollectingHandler.prototype.restart = function() {
|
||||
if (this._cbs.onreset) this._cbs.onreset();
|
||||
|
||||
for (var i = 0, len = this.events.length; i < len; i++) {
|
||||
if (this._cbs[this.events[i][0]]) {
|
||||
var num = this.events[i].length;
|
||||
|
||||
if (num === 1) {
|
||||
this._cbs[this.events[i][0]]();
|
||||
} else if (num === 2) {
|
||||
this._cbs[this.events[i][0]](this.events[i][1]);
|
||||
} else {
|
||||
this._cbs[this.events[i][0]](
|
||||
this.events[i][1],
|
||||
this.events[i][2]
|
||||
);
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CollectingHandler = void 0;
|
||||
var MultiplexHandler_1 = __importDefault(require("./MultiplexHandler"));
|
||||
var CollectingHandler = /** @class */ (function (_super) {
|
||||
__extends(CollectingHandler, _super);
|
||||
function CollectingHandler(cbs) {
|
||||
if (cbs === void 0) { cbs = {}; }
|
||||
var _this = _super.call(this, function (name) {
|
||||
var _a;
|
||||
var args = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
args[_i - 1] = arguments[_i];
|
||||
}
|
||||
}
|
||||
_this.events.push(__spreadArray([name], args));
|
||||
(_a = _this.cbs[name]) === null || _a === void 0 ? void 0 : _a.apply(void 0, args);
|
||||
}) || this;
|
||||
_this.cbs = cbs;
|
||||
_this.events = [];
|
||||
return _this;
|
||||
}
|
||||
};
|
||||
CollectingHandler.prototype.onreset = function () {
|
||||
var _a, _b;
|
||||
this.events = [];
|
||||
(_b = (_a = this.cbs).onreset) === null || _b === void 0 ? void 0 : _b.call(_a);
|
||||
};
|
||||
CollectingHandler.prototype.restart = function () {
|
||||
var _a, _b, _c;
|
||||
(_b = (_a = this.cbs).onreset) === null || _b === void 0 ? void 0 : _b.call(_a);
|
||||
for (var _i = 0, _d = this.events; _i < _d.length; _i++) {
|
||||
var _e = _d[_i], name_1 = _e[0], args = _e.slice(1);
|
||||
(_c = this.cbs[name_1]) === null || _c === void 0 ? void 0 : _c.apply(void 0, args);
|
||||
}
|
||||
};
|
||||
return CollectingHandler;
|
||||
}(MultiplexHandler_1.default));
|
||||
exports.CollectingHandler = CollectingHandler;
|
||||
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
import DomHandler, { DomHandlerOptions } from "domhandler";
|
||||
import { ParserOptions } from "./Parser";
|
||||
declare enum FeedItemMediaMedium {
|
||||
image = 0,
|
||||
audio = 1,
|
||||
video = 2,
|
||||
document = 3,
|
||||
executable = 4
|
||||
}
|
||||
declare enum FeedItemMediaExpression {
|
||||
sample = 0,
|
||||
full = 1,
|
||||
nonstop = 2
|
||||
}
|
||||
interface FeedItemMedia {
|
||||
url?: string;
|
||||
fileSize?: number;
|
||||
type?: string;
|
||||
medium: FeedItemMediaMedium | undefined;
|
||||
isDefault: boolean;
|
||||
expression?: FeedItemMediaExpression;
|
||||
bitrate?: number;
|
||||
framerate?: number;
|
||||
samplingrate?: number;
|
||||
channels?: number;
|
||||
duration?: number;
|
||||
height?: number;
|
||||
width?: number;
|
||||
lang?: string;
|
||||
}
|
||||
interface FeedItem {
|
||||
id?: string;
|
||||
title?: string;
|
||||
link?: string;
|
||||
description?: string;
|
||||
pubDate?: Date;
|
||||
media?: FeedItemMedia[];
|
||||
}
|
||||
interface Feed {
|
||||
type?: string;
|
||||
id?: string;
|
||||
title?: string;
|
||||
link?: string;
|
||||
description?: string;
|
||||
updated?: Date;
|
||||
author?: string;
|
||||
items?: FeedItem[];
|
||||
}
|
||||
export declare class FeedHandler extends DomHandler {
|
||||
feed?: Feed;
|
||||
/**
|
||||
*
|
||||
* @param callback
|
||||
* @param options
|
||||
*/
|
||||
constructor(callback?: ((error: Error | null) => void) | DomHandlerOptions, options?: DomHandlerOptions);
|
||||
onend(): void;
|
||||
}
|
||||
/**
|
||||
* Parse a feed.
|
||||
*
|
||||
* @param feed The feed that should be parsed, as a string.
|
||||
* @param options Optionally, options for parsing. When using this option, you should set `xmlMode` to `true`.
|
||||
*/
|
||||
export declare function parseFeed(feed: string, options?: ParserOptions & DomHandlerOptions): Feed | undefined;
|
||||
export {};
|
||||
//# sourceMappingURL=FeedHandler.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"FeedHandler.d.ts","sourceRo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AM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;CACtB;AAGD,qBAAa,WAAY,SAAQ,UAAU;IACvC,IAAI,CAAC,EAAE,IAAI,CAAC;IAEZ;;;;OAIG;gBAEC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,CAAC,GAAG,iBAAiB,EAC9D,OAAO,CAAC,EAAE,iBAAiB;IAS/B,KAAK,IAAI,IAAI;CAkGhB;AA4FD;;;;;GAKG;AACH,wBAAgB,SAAS,CACrB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,aAAa,GAAG,iBAAqC,GAC/D,IAAI,GAAG,SAAS,CAIlB"}
|
||||
+216
-95
@@ -1,114 +1,235 @@
|
||||
var DomHandler = require("domhandler");
|
||||
var DomUtils = require("domutils");
|
||||
|
||||
//TODO: make this a streamable handler
|
||||
function FeedHandler(callback, options) {
|
||||
this.init(callback, options);
|
||||
}
|
||||
|
||||
require("inherits")(FeedHandler, DomHandler);
|
||||
|
||||
FeedHandler.prototype.init = DomHandler;
|
||||
|
||||
function getElements(what, where) {
|
||||
return DomUtils.getElementsByTagName(what, where, true);
|
||||
}
|
||||
function getOneElement(what, where) {
|
||||
return DomUtils.getElementsByTagName(what, where, true, 1)[0];
|
||||
}
|
||||
function fetch(what, where, recurse) {
|
||||
return DomUtils.getText(
|
||||
DomUtils.getElementsByTagName(what, where, recurse, 1)
|
||||
).trim();
|
||||
}
|
||||
|
||||
function addConditionally(obj, prop, what, where, recurse) {
|
||||
var tmp = fetch(what, where, recurse);
|
||||
if (tmp) obj[prop] = tmp;
|
||||
}
|
||||
|
||||
var isValidFeed = function(value) {
|
||||
return value === "rss" || value === "feed" || value === "rdf:RDF";
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
|
||||
FeedHandler.prototype.onend = function() {
|
||||
var feed = {},
|
||||
feedRoot = getOneElement(isValidFeed, this.dom),
|
||||
tmp,
|
||||
childs;
|
||||
|
||||
if (feedRoot) {
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.parseFeed = exports.FeedHandler = void 0;
|
||||
var domhandler_1 = __importDefault(require("domhandler"));
|
||||
var DomUtils = __importStar(require("domutils"));
|
||||
var Parser_1 = require("./Parser");
|
||||
var FeedItemMediaMedium;
|
||||
(function (FeedItemMediaMedium) {
|
||||
FeedItemMediaMedium[FeedItemMediaMedium["image"] = 0] = "image";
|
||||
FeedItemMediaMedium[FeedItemMediaMedium["audio"] = 1] = "audio";
|
||||
FeedItemMediaMedium[FeedItemMediaMedium["video"] = 2] = "video";
|
||||
FeedItemMediaMedium[FeedItemMediaMedium["document"] = 3] = "document";
|
||||
FeedItemMediaMedium[FeedItemMediaMedium["executable"] = 4] = "executable";
|
||||
})(FeedItemMediaMedium || (FeedItemMediaMedium = {}));
|
||||
var FeedItemMediaExpression;
|
||||
(function (FeedItemMediaExpression) {
|
||||
FeedItemMediaExpression[FeedItemMediaExpression["sample"] = 0] = "sample";
|
||||
FeedItemMediaExpression[FeedItemMediaExpression["full"] = 1] = "full";
|
||||
FeedItemMediaExpression[FeedItemMediaExpression["nonstop"] = 2] = "nonstop";
|
||||
})(FeedItemMediaExpression || (FeedItemMediaExpression = {}));
|
||||
// TODO: Consume data as it is coming in
|
||||
var FeedHandler = /** @class */ (function (_super) {
|
||||
__extends(FeedHandler, _super);
|
||||
/**
|
||||
*
|
||||
* @param callback
|
||||
* @param options
|
||||
*/
|
||||
function FeedHandler(callback, options) {
|
||||
var _this = this;
|
||||
if (typeof callback === "object") {
|
||||
callback = undefined;
|
||||
options = callback;
|
||||
}
|
||||
_this = _super.call(this, callback, options) || this;
|
||||
return _this;
|
||||
}
|
||||
FeedHandler.prototype.onend = function () {
|
||||
var _a, _b;
|
||||
var feedRoot = getOneElement(isValidFeed, this.dom);
|
||||
if (!feedRoot) {
|
||||
this.handleCallback(new Error("couldn't find root of feed"));
|
||||
return;
|
||||
}
|
||||
var feed = {};
|
||||
if (feedRoot.name === "feed") {
|
||||
childs = feedRoot.children;
|
||||
|
||||
var childs = feedRoot.children;
|
||||
feed.type = "atom";
|
||||
addConditionally(feed, "id", "id", childs);
|
||||
addConditionally(feed, "title", "title", childs);
|
||||
if (
|
||||
(tmp = getOneElement("link", childs)) &&
|
||||
(tmp = tmp.attribs) &&
|
||||
(tmp = tmp.href)
|
||||
)
|
||||
feed.link = tmp;
|
||||
var href = getAttribute("href", getOneElement("link", childs));
|
||||
if (href) {
|
||||
feed.link = href;
|
||||
}
|
||||
addConditionally(feed, "description", "subtitle", childs);
|
||||
if ((tmp = fetch("updated", childs))) feed.updated = new Date(tmp);
|
||||
var updated = fetch("updated", childs);
|
||||
if (updated) {
|
||||
feed.updated = new Date(updated);
|
||||
}
|
||||
addConditionally(feed, "author", "email", childs, true);
|
||||
|
||||
feed.items = getElements("entry", childs).map(function(item) {
|
||||
var entry = {},
|
||||
tmp;
|
||||
|
||||
item = item.children;
|
||||
|
||||
addConditionally(entry, "id", "id", item);
|
||||
addConditionally(entry, "title", "title", item);
|
||||
if (
|
||||
(tmp = getOneElement("link", item)) &&
|
||||
(tmp = tmp.attribs) &&
|
||||
(tmp = tmp.href)
|
||||
)
|
||||
entry.link = tmp;
|
||||
if ((tmp = fetch("summary", item) || fetch("content", item)))
|
||||
entry.description = tmp;
|
||||
if ((tmp = fetch("updated", item)))
|
||||
entry.pubDate = new Date(tmp);
|
||||
feed.items = getElements("entry", childs).map(function (item) {
|
||||
var entry = {};
|
||||
var children = item.children;
|
||||
addConditionally(entry, "id", "id", children);
|
||||
addConditionally(entry, "title", "title", children);
|
||||
var href = getAttribute("href", getOneElement("link", children));
|
||||
if (href) {
|
||||
entry.link = href;
|
||||
}
|
||||
var description = fetch("summary", children) || fetch("content", children);
|
||||
if (description) {
|
||||
entry.description = description;
|
||||
}
|
||||
var pubDate = fetch("updated", children);
|
||||
if (pubDate) {
|
||||
entry.pubDate = new Date(pubDate);
|
||||
}
|
||||
entry.media = getMediaElements(children);
|
||||
return entry;
|
||||
});
|
||||
} else {
|
||||
childs = getOneElement("channel", feedRoot.children).children;
|
||||
|
||||
}
|
||||
else {
|
||||
var childs = (_b = (_a = getOneElement("channel", feedRoot.children)) === null || _a === void 0 ? void 0 : _a.children) !== null && _b !== void 0 ? _b : [];
|
||||
feed.type = feedRoot.name.substr(0, 3);
|
||||
feed.id = "";
|
||||
addConditionally(feed, "title", "title", childs);
|
||||
addConditionally(feed, "link", "link", childs);
|
||||
addConditionally(feed, "description", "description", childs);
|
||||
if ((tmp = fetch("lastBuildDate", childs)))
|
||||
feed.updated = new Date(tmp);
|
||||
var updated = fetch("lastBuildDate", childs);
|
||||
if (updated) {
|
||||
feed.updated = new Date(updated);
|
||||
}
|
||||
addConditionally(feed, "author", "managingEditor", childs, true);
|
||||
|
||||
feed.items = getElements("item", feedRoot.children).map(function(
|
||||
item
|
||||
) {
|
||||
var entry = {},
|
||||
tmp;
|
||||
|
||||
item = item.children;
|
||||
|
||||
addConditionally(entry, "id", "guid", item);
|
||||
addConditionally(entry, "title", "title", item);
|
||||
addConditionally(entry, "link", "link", item);
|
||||
addConditionally(entry, "description", "description", item);
|
||||
if ((tmp = fetch("pubDate", item)))
|
||||
entry.pubDate = new Date(tmp);
|
||||
feed.items = getElements("item", feedRoot.children).map(function (item) {
|
||||
var entry = {};
|
||||
var children = item.children;
|
||||
addConditionally(entry, "id", "guid", children);
|
||||
addConditionally(entry, "title", "title", children);
|
||||
addConditionally(entry, "link", "link", children);
|
||||
addConditionally(entry, "description", "description", children);
|
||||
var pubDate = fetch("pubDate", children);
|
||||
if (pubDate)
|
||||
entry.pubDate = new Date(pubDate);
|
||||
entry.media = getMediaElements(children);
|
||||
return entry;
|
||||
});
|
||||
}
|
||||
this.feed = feed;
|
||||
this.handleCallback(null);
|
||||
};
|
||||
return FeedHandler;
|
||||
}(domhandler_1.default));
|
||||
exports.FeedHandler = FeedHandler;
|
||||
function getMediaElements(where) {
|
||||
return getElements("media:content", where).map(function (elem) {
|
||||
var media = {
|
||||
medium: elem.attribs.medium,
|
||||
isDefault: !!elem.attribs.isDefault,
|
||||
};
|
||||
if (elem.attribs.url) {
|
||||
media.url = elem.attribs.url;
|
||||
}
|
||||
if (elem.attribs.fileSize) {
|
||||
media.fileSize = parseInt(elem.attribs.fileSize, 10);
|
||||
}
|
||||
if (elem.attribs.type) {
|
||||
media.type = elem.attribs.type;
|
||||
}
|
||||
if (elem.attribs.expression) {
|
||||
media.expression = elem.attribs
|
||||
.expression;
|
||||
}
|
||||
if (elem.attribs.bitrate) {
|
||||
media.bitrate = parseInt(elem.attribs.bitrate, 10);
|
||||
}
|
||||
if (elem.attribs.framerate) {
|
||||
media.framerate = parseInt(elem.attribs.framerate, 10);
|
||||
}
|
||||
if (elem.attribs.samplingrate) {
|
||||
media.samplingrate = parseInt(elem.attribs.samplingrate, 10);
|
||||
}
|
||||
if (elem.attribs.channels) {
|
||||
media.channels = parseInt(elem.attribs.channels, 10);
|
||||
}
|
||||
if (elem.attribs.duration) {
|
||||
media.duration = parseInt(elem.attribs.duration, 10);
|
||||
}
|
||||
if (elem.attribs.height) {
|
||||
media.height = parseInt(elem.attribs.height, 10);
|
||||
}
|
||||
if (elem.attribs.width) {
|
||||
media.width = parseInt(elem.attribs.width, 10);
|
||||
}
|
||||
if (elem.attribs.lang) {
|
||||
media.lang = elem.attribs.lang;
|
||||
}
|
||||
return media;
|
||||
});
|
||||
}
|
||||
function getElements(tagName, where) {
|
||||
return DomUtils.getElementsByTagName(tagName, where, true);
|
||||
}
|
||||
function getOneElement(tagName, node) {
|
||||
return DomUtils.getElementsByTagName(tagName, node, true, 1)[0];
|
||||
}
|
||||
function fetch(tagName, where, recurse) {
|
||||
if (recurse === void 0) { recurse = false; }
|
||||
return DomUtils.getText(DomUtils.getElementsByTagName(tagName, where, recurse, 1)).trim();
|
||||
}
|
||||
function getAttribute(name, elem) {
|
||||
if (!elem) {
|
||||
return null;
|
||||
}
|
||||
this.dom = feed;
|
||||
DomHandler.prototype._handleCallback.call(
|
||||
this,
|
||||
feedRoot ? null : Error("couldn't find root of feed")
|
||||
);
|
||||
};
|
||||
|
||||
module.exports = FeedHandler;
|
||||
var attribs = elem.attribs;
|
||||
return attribs[name];
|
||||
}
|
||||
function addConditionally(obj, prop, what, where, recurse) {
|
||||
if (recurse === void 0) { recurse = false; }
|
||||
var tmp = fetch(what, where, recurse);
|
||||
if (tmp)
|
||||
obj[prop] = tmp;
|
||||
}
|
||||
function isValidFeed(value) {
|
||||
return value === "rss" || value === "feed" || value === "rdf:RDF";
|
||||
}
|
||||
/**
|
||||
* Parse a feed.
|
||||
*
|
||||
* @param feed The feed that should be parsed, as a string.
|
||||
* @param options Optionally, options for parsing. When using this option, you should set `xmlMode` to `true`.
|
||||
*/
|
||||
function parseFeed(feed, options) {
|
||||
if (options === void 0) { options = { xmlMode: true }; }
|
||||
var handler = new FeedHandler(options);
|
||||
new Parser_1.Parser(handler, options).end(feed);
|
||||
return handler.feed;
|
||||
}
|
||||
exports.parseFeed = parseFeed;
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
import type { Parser, Handler } from "./Parser";
|
||||
/**
|
||||
* Calls a specific handler function for all events that are encountered.
|
||||
*/
|
||||
export default class MultiplexHandler implements Handler {
|
||||
private readonly func;
|
||||
/**
|
||||
* @param func The function to multiplex all events to.
|
||||
*/
|
||||
constructor(func: (event: keyof Handler, ...args: unknown[]) => void);
|
||||
onattribute(name: string, value: string, quote: string | null | undefined): void;
|
||||
oncdatastart(): void;
|
||||
oncdataend(): void;
|
||||
ontext(text: string): void;
|
||||
onprocessinginstruction(name: string, value: string): void;
|
||||
oncomment(comment: string): void;
|
||||
oncommentend(): void;
|
||||
onclosetag(name: string): void;
|
||||
onopentag(name: string, attribs: {
|
||||
[key: string]: string;
|
||||
}): void;
|
||||
onopentagname(name: string): void;
|
||||
onerror(error: Error): void;
|
||||
onend(): void;
|
||||
onparserinit(parser: Parser): void;
|
||||
onreset(): void;
|
||||
}
|
||||
//# sourceMappingURL=MultiplexHandler.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"MultiplexHandler.d.ts","sourceRoot":"","sources":["../src/MultiplexHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEhD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAiB,YAAW,OAAO;IAKhD,OAAO,CAAC,QAAQ,CAAC,IAAI;IAJzB;;OAEG;gBAEkB,IAAI,EAAE,CACnB,KAAK,EAAE,MAAM,OAAO,EACpB,GAAG,IAAI,EAAE,OAAO,EAAE,KACjB,IAAI;IAGb,WAAW,CACP,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACjC,IAAI;IAGP,YAAY,IAAI,IAAI;IAGpB,UAAU,IAAI,IAAI;IAGlB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAG1B,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAG1D,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAGhC,YAAY,IAAI,IAAI;IAGpB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAG9B,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,IAAI;IAGjE,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAGjC,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAG3B,KAAK,IAAI,IAAI;IAGb,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAGlC,OAAO,IAAI,IAAI;CAGlB"}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
/**
|
||||
* Calls a specific handler function for all events that are encountered.
|
||||
*/
|
||||
var MultiplexHandler = /** @class */ (function () {
|
||||
/**
|
||||
* @param func The function to multiplex all events to.
|
||||
*/
|
||||
function MultiplexHandler(func) {
|
||||
this.func = func;
|
||||
}
|
||||
MultiplexHandler.prototype.onattribute = function (name, value, quote) {
|
||||
this.func("onattribute", name, value, quote);
|
||||
};
|
||||
MultiplexHandler.prototype.oncdatastart = function () {
|
||||
this.func("oncdatastart");
|
||||
};
|
||||
MultiplexHandler.prototype.oncdataend = function () {
|
||||
this.func("oncdataend");
|
||||
};
|
||||
MultiplexHandler.prototype.ontext = function (text) {
|
||||
this.func("ontext", text);
|
||||
};
|
||||
MultiplexHandler.prototype.onprocessinginstruction = function (name, value) {
|
||||
this.func("onprocessinginstruction", name, value);
|
||||
};
|
||||
MultiplexHandler.prototype.oncomment = function (comment) {
|
||||
this.func("oncomment", comment);
|
||||
};
|
||||
MultiplexHandler.prototype.oncommentend = function () {
|
||||
this.func("oncommentend");
|
||||
};
|
||||
MultiplexHandler.prototype.onclosetag = function (name) {
|
||||
this.func("onclosetag", name);
|
||||
};
|
||||
MultiplexHandler.prototype.onopentag = function (name, attribs) {
|
||||
this.func("onopentag", name, attribs);
|
||||
};
|
||||
MultiplexHandler.prototype.onopentagname = function (name) {
|
||||
this.func("onopentagname", name);
|
||||
};
|
||||
MultiplexHandler.prototype.onerror = function (error) {
|
||||
this.func("onerror", error);
|
||||
};
|
||||
MultiplexHandler.prototype.onend = function () {
|
||||
this.func("onend");
|
||||
};
|
||||
MultiplexHandler.prototype.onparserinit = function (parser) {
|
||||
this.func("onparserinit", parser);
|
||||
};
|
||||
MultiplexHandler.prototype.onreset = function () {
|
||||
this.func("onreset");
|
||||
};
|
||||
return MultiplexHandler;
|
||||
}());
|
||||
exports.default = MultiplexHandler;
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
import Tokenizer from "./Tokenizer";
|
||||
export interface ParserOptions {
|
||||
/**
|
||||
* Indicates whether special tags (`<script>`, `<style>`, and `<title>`) should get special treatment
|
||||
* and if "empty" tags (eg. `<br>`) can have children. If `false`, the content of special tags
|
||||
* will be text only. For feeds and other XML content (documents that don't consist of HTML),
|
||||
* set this to `true`.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
xmlMode?: boolean;
|
||||
/**
|
||||
* Decode entities within the document.
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
decodeEntities?: boolean;
|
||||
/**
|
||||
* If set to true, all tags will be lowercased.
|
||||
*
|
||||
* @default !xmlMode
|
||||
*/
|
||||
lowerCaseTags?: boolean;
|
||||
/**
|
||||
* If set to `true`, all attribute names will be lowercased. This has noticeable impact on speed.
|
||||
*
|
||||
* @default !xmlMode
|
||||
*/
|
||||
lowerCaseAttributeNames?: boolean;
|
||||
/**
|
||||
* If set to true, CDATA sections will be recognized as text even if the xmlMode option is not enabled.
|
||||
* NOTE: If xmlMode is set to `true` then CDATA sections will always be recognized as text.
|
||||
*
|
||||
* @default xmlMode
|
||||
*/
|
||||
recognizeCDATA?: boolean;
|
||||
/**
|
||||
* If set to `true`, self-closing tags will trigger the onclosetag event even if xmlMode is not set to `true`.
|
||||
* NOTE: If xmlMode is set to `true` then self-closing tags will always be recognized.
|
||||
*
|
||||
* @default xmlMode
|
||||
*/
|
||||
recognizeSelfClosing?: boolean;
|
||||
/**
|
||||
* Allows the default tokenizer to be overwritten.
|
||||
*/
|
||||
Tokenizer?: typeof Tokenizer;
|
||||
}
|
||||
export interface Handler {
|
||||
onparserinit(parser: Parser): void;
|
||||
/**
|
||||
* Resets the handler back to starting state
|
||||
*/
|
||||
onreset(): void;
|
||||
/**
|
||||
* Signals the handler that parsing is done
|
||||
*/
|
||||
onend(): void;
|
||||
onerror(error: Error): void;
|
||||
onclosetag(name: string): void;
|
||||
onopentagname(name: string): void;
|
||||
/**
|
||||
*
|
||||
* @param name Name of the attribute
|
||||
* @param value Value of the attribute.
|
||||
* @param quote Quotes used around the attribute. `null` if the attribute has no quotes around the value, `undefined` if the attribute has no value.
|
||||
*/
|
||||
onattribute(name: string, value: string, quote?: string | undefined | null): void;
|
||||
onopentag(name: string, attribs: {
|
||||
[s: string]: string;
|
||||
}): void;
|
||||
ontext(data: string): void;
|
||||
oncomment(data: string): void;
|
||||
oncdatastart(): void;
|
||||
oncdataend(): void;
|
||||
oncommentend(): void;
|
||||
onprocessinginstruction(name: string, data: string): void;
|
||||
}
|
||||
export declare class Parser {
|
||||
/** The start index of the last event. */
|
||||
startIndex: number;
|
||||
/** The end index of the last event. */
|
||||
endIndex: number | null;
|
||||
private tagname;
|
||||
private attribname;
|
||||
private attribvalue;
|
||||
private attribs;
|
||||
private stack;
|
||||
private readonly foreignContext;
|
||||
private readonly cbs;
|
||||
private readonly options;
|
||||
private readonly lowerCaseTagNames;
|
||||
private readonly lowerCaseAttributeNames;
|
||||
private readonly tokenizer;
|
||||
constructor(cbs: Partial<Handler> | null, options?: ParserOptions);
|
||||
private updatePosition;
|
||||
ontext(data: string): void;
|
||||
onopentagname(name: string): void;
|
||||
onopentagend(): void;
|
||||
onclosetag(name: string): void;
|
||||
onselfclosingtag(): void;
|
||||
private closeCurrentTag;
|
||||
onattribname(name: string): void;
|
||||
onattribdata(value: string): void;
|
||||
onattribend(quote: string | undefined | null): void;
|
||||
private getInstructionName;
|
||||
ondeclaration(value: string): void;
|
||||
onprocessinginstruction(value: string): void;
|
||||
oncomment(value: string): void;
|
||||
oncdata(value: string): void;
|
||||
onerror(err: Error): void;
|
||||
onend(): void;
|
||||
/**
|
||||
* Resets the parser to a blank state, ready to parse a new HTML document
|
||||
*/
|
||||
reset(): void;
|
||||
/**
|
||||
* Resets the parser, then parses a complete document and
|
||||
* pushes it to the handler.
|
||||
*
|
||||
* @param data Document to parse.
|
||||
*/
|
||||
parseComplete(data: string): void;
|
||||
/**
|
||||
* Parses a chunk of data and calls the corresponding callbacks.
|
||||
*
|
||||
* @param chunk Chunk to parse.
|
||||
*/
|
||||
write(chunk: string): void;
|
||||
/**
|
||||
* Parses the end of the buffer and clears the stack, calls onend.
|
||||
*
|
||||
* @param chunk Optional final chunk to parse.
|
||||
*/
|
||||
end(chunk?: string): void;
|
||||
/**
|
||||
* Pauses parsing. The parser won't emit events until `resume` is called.
|
||||
*/
|
||||
pause(): void;
|
||||
/**
|
||||
* Resumes parsing after `pause` was called.
|
||||
*/
|
||||
resume(): void;
|
||||
/**
|
||||
* Alias of `write`, for backwards compatibility.
|
||||
*
|
||||
* @param chunk Chunk to parse.
|
||||
* @deprecated
|
||||
*/
|
||||
parseChunk(chunk: string): void;
|
||||
/**
|
||||
* Alias of `end`, for backwards compatibility.
|
||||
*
|
||||
* @param chunk Optional final chunk to parse.
|
||||
* @deprecated
|
||||
*/
|
||||
done(chunk?: string): void;
|
||||
}
|
||||
//# sourceMappingURL=Parser.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Parser.d.ts","sourceRoot":"","sources":["../src/Parser.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,aAAa,CAAC;AAoGpC,MAAM,WAAW,aAAa;IAC1B;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;;OAIG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAElC;;;;;OAKG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,SAAS,CAAC;CAChC;AAED,MAAM,WAAW,OAAO;IACpB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAEnC;;OAEG;IACH,OAAO,IAAI,IAAI,CAAC;IAEhB;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;IACd,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,IA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CAGpC"}
|
||||
+366
-367
@@ -1,382 +1,381 @@
|
||||
var Tokenizer = require("./Tokenizer.js");
|
||||
|
||||
/*
|
||||
Options:
|
||||
|
||||
xmlMode: Disables the special behavior for script/style tags (false by default)
|
||||
lowerCaseAttributeNames: call .toLowerCase for each attribute name (true if xmlMode is `false`)
|
||||
lowerCaseTags: call .toLowerCase for each tag name (true if xmlMode is `false`)
|
||||
*/
|
||||
|
||||
/*
|
||||
Callbacks:
|
||||
|
||||
oncdataend,
|
||||
oncdatastart,
|
||||
onclosetag,
|
||||
oncomment,
|
||||
oncommentend,
|
||||
onerror,
|
||||
onopentag,
|
||||
onprocessinginstruction,
|
||||
onreset,
|
||||
ontext
|
||||
*/
|
||||
|
||||
var formTags = {
|
||||
input: true,
|
||||
option: true,
|
||||
optgroup: true,
|
||||
select: true,
|
||||
button: true,
|
||||
datalist: true,
|
||||
textarea: true
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Parser = void 0;
|
||||
var Tokenizer_1 = __importDefault(require("./Tokenizer"));
|
||||
var formTags = new Set([
|
||||
"input",
|
||||
"option",
|
||||
"optgroup",
|
||||
"select",
|
||||
"button",
|
||||
"datalist",
|
||||
"textarea",
|
||||
]);
|
||||
var pTag = new Set(["p"]);
|
||||
var openImpliesClose = {
|
||||
tr: { tr: true, th: true, td: true },
|
||||
th: { th: true },
|
||||
td: { thead: true, th: true, td: true },
|
||||
body: { head: true, link: true, script: true },
|
||||
li: { li: true },
|
||||
p: { p: true },
|
||||
h1: { p: true },
|
||||
h2: { p: true },
|
||||
h3: { p: true },
|
||||
h4: { p: true },
|
||||
h5: { p: true },
|
||||
h6: { p: true },
|
||||
tr: new Set(["tr", "th", "td"]),
|
||||
th: new Set(["th"]),
|
||||
td: new Set(["thead", "th", "td"]),
|
||||
body: new Set(["head", "link", "script"]),
|
||||
li: new Set(["li"]),
|
||||
p: pTag,
|
||||
h1: pTag,
|
||||
h2: pTag,
|
||||
h3: pTag,
|
||||
h4: pTag,
|
||||
h5: pTag,
|
||||
h6: pTag,
|
||||
select: formTags,
|
||||
input: formTags,
|
||||
output: formTags,
|
||||
button: formTags,
|
||||
datalist: formTags,
|
||||
textarea: formTags,
|
||||
option: { option: true },
|
||||
optgroup: { optgroup: true }
|
||||
option: new Set(["option"]),
|
||||
optgroup: new Set(["optgroup", "option"]),
|
||||
dd: new Set(["dt", "dd"]),
|
||||
dt: new Set(["dt", "dd"]),
|
||||
address: pTag,
|
||||
article: pTag,
|
||||
aside: pTag,
|
||||
blockquote: pTag,
|
||||
details: pTag,
|
||||
div: pTag,
|
||||
dl: pTag,
|
||||
fieldset: pTag,
|
||||
figcaption: pTag,
|
||||
figure: pTag,
|
||||
footer: pTag,
|
||||
form: pTag,
|
||||
header: pTag,
|
||||
hr: pTag,
|
||||
main: pTag,
|
||||
nav: pTag,
|
||||
ol: pTag,
|
||||
pre: pTag,
|
||||
section: pTag,
|
||||
table: pTag,
|
||||
ul: pTag,
|
||||
rt: new Set(["rt", "rp"]),
|
||||
rp: new Set(["rt", "rp"]),
|
||||
tbody: new Set(["thead", "tbody"]),
|
||||
tfoot: new Set(["thead", "tbody"]),
|
||||
};
|
||||
|
||||
var voidElements = {
|
||||
__proto__: null,
|
||||
area: true,
|
||||
base: true,
|
||||
basefont: true,
|
||||
br: true,
|
||||
col: true,
|
||||
command: true,
|
||||
embed: true,
|
||||
frame: true,
|
||||
hr: true,
|
||||
img: true,
|
||||
input: true,
|
||||
isindex: true,
|
||||
keygen: true,
|
||||
link: true,
|
||||
meta: true,
|
||||
param: true,
|
||||
source: true,
|
||||
track: true,
|
||||
wbr: true
|
||||
};
|
||||
|
||||
var foreignContextElements = {
|
||||
__proto__: null,
|
||||
math: true,
|
||||
svg: true
|
||||
};
|
||||
var htmlIntegrationElements = {
|
||||
__proto__: null,
|
||||
mi: true,
|
||||
mo: true,
|
||||
mn: true,
|
||||
ms: true,
|
||||
mtext: true,
|
||||
"annotation-xml": true,
|
||||
foreignObject: true,
|
||||
desc: true,
|
||||
title: true
|
||||
};
|
||||
|
||||
var re_nameEnd = /\s|\//;
|
||||
|
||||
function Parser(cbs, options) {
|
||||
this._options = options || {};
|
||||
this._cbs = cbs || {};
|
||||
|
||||
this._tagname = "";
|
||||
this._attribname = "";
|
||||
this._attribvalue = "";
|
||||
this._attribs = null;
|
||||
this._stack = [];
|
||||
this._foreignContext = [];
|
||||
|
||||
this.startIndex = 0;
|
||||
this.endIndex = null;
|
||||
|
||||
this._lowerCaseTagNames =
|
||||
"lowerCaseTags" in this._options
|
||||
? !!this._options.lowerCaseTags
|
||||
: !this._options.xmlMode;
|
||||
this._lowerCaseAttributeNames =
|
||||
"lowerCaseAttributeNames" in this._options
|
||||
? !!this._options.lowerCaseAttributeNames
|
||||
: !this._options.xmlMode;
|
||||
|
||||
if (this._options.Tokenizer) {
|
||||
Tokenizer = this._options.Tokenizer;
|
||||
var voidElements = new Set([
|
||||
"area",
|
||||
"base",
|
||||
"basefont",
|
||||
"br",
|
||||
"col",
|
||||
"command",
|
||||
"embed",
|
||||
"frame",
|
||||
"hr",
|
||||
"img",
|
||||
"input",
|
||||
"isindex",
|
||||
"keygen",
|
||||
"link",
|
||||
"meta",
|
||||
"param",
|
||||
"source",
|
||||
"track",
|
||||
"wbr",
|
||||
]);
|
||||
var foreignContextElements = new Set(["math", "svg"]);
|
||||
var htmlIntegrationElements = new Set([
|
||||
"mi",
|
||||
"mo",
|
||||
"mn",
|
||||
"ms",
|
||||
"mtext",
|
||||
"annotation-xml",
|
||||
"foreignObject",
|
||||
"desc",
|
||||
"title",
|
||||
]);
|
||||
var reNameEnd = /\s|\//;
|
||||
var Parser = /** @class */ (function () {
|
||||
function Parser(cbs, options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
var _a, _b, _c, _d, _e;
|
||||
/** The start index of the last event. */
|
||||
this.startIndex = 0;
|
||||
/** The end index of the last event. */
|
||||
this.endIndex = null;
|
||||
this.tagname = "";
|
||||
this.attribname = "";
|
||||
this.attribvalue = "";
|
||||
this.attribs = null;
|
||||
this.stack = [];
|
||||
this.foreignContext = [];
|
||||
this.options = options;
|
||||
this.cbs = cbs !== null && cbs !== void 0 ? cbs : {};
|
||||
this.lowerCaseTagNames = (_a = options.lowerCaseTags) !== null && _a !== void 0 ? _a : !options.xmlMode;
|
||||
this.lowerCaseAttributeNames =
|
||||
(_b = options.lowerCaseAttributeNames) !== null && _b !== void 0 ? _b : !options.xmlMode;
|
||||
this.tokenizer = new ((_c = options.Tokenizer) !== null && _c !== void 0 ? _c : Tokenizer_1.default)(this.options, this);
|
||||
(_e = (_d = this.cbs).onparserinit) === null || _e === void 0 ? void 0 : _e.call(_d, this);
|
||||
}
|
||||
this._tokenizer = new Tokenizer(this._options, this);
|
||||
|
||||
if (this._cbs.onparserinit) this._cbs.onparserinit(this);
|
||||
}
|
||||
|
||||
require("inherits")(Parser, require("events").EventEmitter);
|
||||
|
||||
Parser.prototype._updatePosition = function(initialOffset) {
|
||||
if (this.endIndex === null) {
|
||||
if (this._tokenizer._sectionStart <= initialOffset) {
|
||||
this.startIndex = 0;
|
||||
} else {
|
||||
this.startIndex = this._tokenizer._sectionStart - initialOffset;
|
||||
Parser.prototype.updatePosition = function (initialOffset) {
|
||||
if (this.endIndex === null) {
|
||||
if (this.tokenizer.sectionStart <= initialOffset) {
|
||||
this.startIndex = 0;
|
||||
}
|
||||
else {
|
||||
this.startIndex = this.tokenizer.sectionStart - initialOffset;
|
||||
}
|
||||
}
|
||||
} else this.startIndex = this.endIndex + 1;
|
||||
this.endIndex = this._tokenizer.getAbsoluteIndex();
|
||||
};
|
||||
|
||||
//Tokenizer event handlers
|
||||
Parser.prototype.ontext = function(data) {
|
||||
this._updatePosition(1);
|
||||
this.endIndex--;
|
||||
|
||||
if (this._cbs.ontext) this._cbs.ontext(data);
|
||||
};
|
||||
|
||||
Parser.prototype.onopentagname = function(name) {
|
||||
if (this._lowerCaseTagNames) {
|
||||
name = name.toLowerCase();
|
||||
}
|
||||
|
||||
this._tagname = name;
|
||||
|
||||
if (!this._options.xmlMode && name in openImpliesClose) {
|
||||
for (
|
||||
var el;
|
||||
(el = this._stack[this._stack.length - 1]) in
|
||||
openImpliesClose[name];
|
||||
this.onclosetag(el)
|
||||
);
|
||||
}
|
||||
|
||||
if (this._options.xmlMode || !(name in voidElements)) {
|
||||
this._stack.push(name);
|
||||
if (name in foreignContextElements) this._foreignContext.push(true);
|
||||
else if (name in htmlIntegrationElements)
|
||||
this._foreignContext.push(false);
|
||||
}
|
||||
|
||||
if (this._cbs.onopentagname) this._cbs.onopentagname(name);
|
||||
if (this._cbs.onopentag) this._attribs = {};
|
||||
};
|
||||
|
||||
Parser.prototype.onopentagend = function() {
|
||||
this._updatePosition(1);
|
||||
|
||||
if (this._attribs) {
|
||||
if (this._cbs.onopentag)
|
||||
this._cbs.onopentag(this._tagname, this._attribs);
|
||||
this._attribs = null;
|
||||
}
|
||||
|
||||
if (
|
||||
!this._options.xmlMode &&
|
||||
this._cbs.onclosetag &&
|
||||
this._tagname in voidElements
|
||||
) {
|
||||
this._cbs.onclosetag(this._tagname);
|
||||
}
|
||||
|
||||
this._tagname = "";
|
||||
};
|
||||
|
||||
Parser.prototype.onclosetag = function(name) {
|
||||
this._updatePosition(1);
|
||||
|
||||
if (this._lowerCaseTagNames) {
|
||||
name = name.toLowerCase();
|
||||
}
|
||||
|
||||
if (name in foreignContextElements || name in htmlIntegrationElements) {
|
||||
this._foreignContext.pop();
|
||||
}
|
||||
|
||||
if (
|
||||
this._stack.length &&
|
||||
(!(name in voidElements) || this._options.xmlMode)
|
||||
) {
|
||||
var pos = this._stack.lastIndexOf(name);
|
||||
if (pos !== -1) {
|
||||
if (this._cbs.onclosetag) {
|
||||
pos = this._stack.length - pos;
|
||||
while (pos--) this._cbs.onclosetag(this._stack.pop());
|
||||
} else this._stack.length = pos;
|
||||
} else if (name === "p" && !this._options.xmlMode) {
|
||||
else {
|
||||
this.startIndex = this.endIndex + 1;
|
||||
}
|
||||
this.endIndex = this.tokenizer.getAbsoluteIndex();
|
||||
};
|
||||
// Tokenizer event handlers
|
||||
Parser.prototype.ontext = function (data) {
|
||||
var _a, _b;
|
||||
this.updatePosition(1);
|
||||
this.endIndex--;
|
||||
(_b = (_a = this.cbs).ontext) === null || _b === void 0 ? void 0 : _b.call(_a, data);
|
||||
};
|
||||
Parser.prototype.onopentagname = function (name) {
|
||||
var _a, _b;
|
||||
if (this.lowerCaseTagNames) {
|
||||
name = name.toLowerCase();
|
||||
}
|
||||
this.tagname = name;
|
||||
if (!this.options.xmlMode &&
|
||||
Object.prototype.hasOwnProperty.call(openImpliesClose, name)) {
|
||||
var el = void 0;
|
||||
while (this.stack.length > 0 &&
|
||||
openImpliesClose[name].has((el = this.stack[this.stack.length - 1]))) {
|
||||
this.onclosetag(el);
|
||||
}
|
||||
}
|
||||
if (this.options.xmlMode || !voidElements.has(name)) {
|
||||
this.stack.push(name);
|
||||
if (foreignContextElements.has(name)) {
|
||||
this.foreignContext.push(true);
|
||||
}
|
||||
else if (htmlIntegrationElements.has(name)) {
|
||||
this.foreignContext.push(false);
|
||||
}
|
||||
}
|
||||
(_b = (_a = this.cbs).onopentagname) === null || _b === void 0 ? void 0 : _b.call(_a, name);
|
||||
if (this.cbs.onopentag)
|
||||
this.attribs = {};
|
||||
};
|
||||
Parser.prototype.onopentagend = function () {
|
||||
var _a, _b;
|
||||
this.updatePosition(1);
|
||||
if (this.attribs) {
|
||||
(_b = (_a = this.cbs).onopentag) === null || _b === void 0 ? void 0 : _b.call(_a, this.tagname, this.attribs);
|
||||
this.attribs = null;
|
||||
}
|
||||
if (!this.options.xmlMode &&
|
||||
this.cbs.onclosetag &&
|
||||
voidElements.has(this.tagname)) {
|
||||
this.cbs.onclosetag(this.tagname);
|
||||
}
|
||||
this.tagname = "";
|
||||
};
|
||||
Parser.prototype.onclosetag = function (name) {
|
||||
this.updatePosition(1);
|
||||
if (this.lowerCaseTagNames) {
|
||||
name = name.toLowerCase();
|
||||
}
|
||||
if (foreignContextElements.has(name) ||
|
||||
htmlIntegrationElements.has(name)) {
|
||||
this.foreignContext.pop();
|
||||
}
|
||||
if (this.stack.length &&
|
||||
(this.options.xmlMode || !voidElements.has(name))) {
|
||||
var pos = this.stack.lastIndexOf(name);
|
||||
if (pos !== -1) {
|
||||
if (this.cbs.onclosetag) {
|
||||
pos = this.stack.length - pos;
|
||||
while (pos--) {
|
||||
// We know the stack has sufficient elements.
|
||||
this.cbs.onclosetag(this.stack.pop());
|
||||
}
|
||||
}
|
||||
else
|
||||
this.stack.length = pos;
|
||||
}
|
||||
else if (name === "p" && !this.options.xmlMode) {
|
||||
this.onopentagname(name);
|
||||
this.closeCurrentTag();
|
||||
}
|
||||
}
|
||||
else if (!this.options.xmlMode && (name === "br" || name === "p")) {
|
||||
this.onopentagname(name);
|
||||
this._closeCurrentTag();
|
||||
this.closeCurrentTag();
|
||||
}
|
||||
} else if (!this._options.xmlMode && (name === "br" || name === "p")) {
|
||||
this.onopentagname(name);
|
||||
this._closeCurrentTag();
|
||||
}
|
||||
};
|
||||
|
||||
Parser.prototype.onselfclosingtag = function() {
|
||||
if (
|
||||
this._options.xmlMode ||
|
||||
this._options.recognizeSelfClosing ||
|
||||
this._foreignContext[this._foreignContext.length - 1]
|
||||
) {
|
||||
this._closeCurrentTag();
|
||||
} else {
|
||||
};
|
||||
Parser.prototype.onselfclosingtag = function () {
|
||||
if (this.options.xmlMode ||
|
||||
this.options.recognizeSelfClosing ||
|
||||
this.foreignContext[this.foreignContext.length - 1]) {
|
||||
this.closeCurrentTag();
|
||||
}
|
||||
else {
|
||||
this.onopentagend();
|
||||
}
|
||||
};
|
||||
Parser.prototype.closeCurrentTag = function () {
|
||||
var _a, _b;
|
||||
var name = this.tagname;
|
||||
this.onopentagend();
|
||||
}
|
||||
};
|
||||
|
||||
Parser.prototype._closeCurrentTag = function() {
|
||||
var name = this._tagname;
|
||||
|
||||
this.onopentagend();
|
||||
|
||||
//self-closing tags will be on the top of the stack
|
||||
//(cheaper check than in onclosetag)
|
||||
if (this._stack[this._stack.length - 1] === name) {
|
||||
if (this._cbs.onclosetag) {
|
||||
this._cbs.onclosetag(name);
|
||||
/*
|
||||
* Self-closing tags will be on the top of the stack
|
||||
* (cheaper check than in onclosetag)
|
||||
*/
|
||||
if (this.stack[this.stack.length - 1] === name) {
|
||||
(_b = (_a = this.cbs).onclosetag) === null || _b === void 0 ? void 0 : _b.call(_a, name);
|
||||
this.stack.pop();
|
||||
}
|
||||
this._stack.pop();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
Parser.prototype.onattribname = function(name) {
|
||||
if (this._lowerCaseAttributeNames) {
|
||||
name = name.toLowerCase();
|
||||
}
|
||||
this._attribname = name;
|
||||
};
|
||||
|
||||
Parser.prototype.onattribdata = function(value) {
|
||||
this._attribvalue += value;
|
||||
};
|
||||
|
||||
Parser.prototype.onattribend = function() {
|
||||
if (this._cbs.onattribute)
|
||||
this._cbs.onattribute(this._attribname, this._attribvalue);
|
||||
if (
|
||||
this._attribs &&
|
||||
!Object.prototype.hasOwnProperty.call(this._attribs, this._attribname)
|
||||
) {
|
||||
this._attribs[this._attribname] = this._attribvalue;
|
||||
}
|
||||
this._attribname = "";
|
||||
this._attribvalue = "";
|
||||
};
|
||||
|
||||
Parser.prototype._getInstructionName = function(value) {
|
||||
var idx = value.search(re_nameEnd),
|
||||
name = idx < 0 ? value : value.substr(0, idx);
|
||||
|
||||
if (this._lowerCaseTagNames) {
|
||||
name = name.toLowerCase();
|
||||
}
|
||||
|
||||
return name;
|
||||
};
|
||||
|
||||
Parser.prototype.ondeclaration = function(value) {
|
||||
if (this._cbs.onprocessinginstruction) {
|
||||
var name = this._getInstructionName(value);
|
||||
this._cbs.onprocessinginstruction("!" + name, "!" + value);
|
||||
}
|
||||
};
|
||||
|
||||
Parser.prototype.onprocessinginstruction = function(value) {
|
||||
if (this._cbs.onprocessinginstruction) {
|
||||
var name = this._getInstructionName(value);
|
||||
this._cbs.onprocessinginstruction("?" + name, "?" + value);
|
||||
}
|
||||
};
|
||||
|
||||
Parser.prototype.oncomment = function(value) {
|
||||
this._updatePosition(4);
|
||||
|
||||
if (this._cbs.oncomment) this._cbs.oncomment(value);
|
||||
if (this._cbs.oncommentend) this._cbs.oncommentend();
|
||||
};
|
||||
|
||||
Parser.prototype.oncdata = function(value) {
|
||||
this._updatePosition(1);
|
||||
|
||||
if (this._options.xmlMode || this._options.recognizeCDATA) {
|
||||
if (this._cbs.oncdatastart) this._cbs.oncdatastart();
|
||||
if (this._cbs.ontext) this._cbs.ontext(value);
|
||||
if (this._cbs.oncdataend) this._cbs.oncdataend();
|
||||
} else {
|
||||
this.oncomment("[CDATA[" + value + "]]");
|
||||
}
|
||||
};
|
||||
|
||||
Parser.prototype.onerror = function(err) {
|
||||
if (this._cbs.onerror) this._cbs.onerror(err);
|
||||
};
|
||||
|
||||
Parser.prototype.onend = function() {
|
||||
if (this._cbs.onclosetag) {
|
||||
for (
|
||||
var i = this._stack.length;
|
||||
i > 0;
|
||||
this._cbs.onclosetag(this._stack[--i])
|
||||
);
|
||||
}
|
||||
if (this._cbs.onend) this._cbs.onend();
|
||||
};
|
||||
|
||||
//Resets the parser to a blank state, ready to parse a new HTML document
|
||||
Parser.prototype.reset = function() {
|
||||
if (this._cbs.onreset) this._cbs.onreset();
|
||||
this._tokenizer.reset();
|
||||
|
||||
this._tagname = "";
|
||||
this._attribname = "";
|
||||
this._attribs = null;
|
||||
this._stack = [];
|
||||
|
||||
if (this._cbs.onparserinit) this._cbs.onparserinit(this);
|
||||
};
|
||||
|
||||
//Parses a complete HTML document and pushes it to the handler
|
||||
Parser.prototype.parseComplete = function(data) {
|
||||
this.reset();
|
||||
this.end(data);
|
||||
};
|
||||
|
||||
Parser.prototype.write = function(chunk) {
|
||||
this._tokenizer.write(chunk);
|
||||
};
|
||||
|
||||
Parser.prototype.end = function(chunk) {
|
||||
this._tokenizer.end(chunk);
|
||||
};
|
||||
|
||||
Parser.prototype.pause = function() {
|
||||
this._tokenizer.pause();
|
||||
};
|
||||
|
||||
Parser.prototype.resume = function() {
|
||||
this._tokenizer.resume();
|
||||
};
|
||||
|
||||
//alias for backwards compat
|
||||
Parser.prototype.parseChunk = Parser.prototype.write;
|
||||
Parser.prototype.done = Parser.prototype.end;
|
||||
|
||||
module.exports = Parser;
|
||||
};
|
||||
Parser.prototype.onattribname = function (name) {
|
||||
if (this.lowerCaseAttributeNames) {
|
||||
name = name.toLowerCase();
|
||||
}
|
||||
this.attribname = name;
|
||||
};
|
||||
Parser.prototype.onattribdata = function (value) {
|
||||
this.attribvalue += value;
|
||||
};
|
||||
Parser.prototype.onattribend = function (quote) {
|
||||
var _a, _b;
|
||||
(_b = (_a = this.cbs).onattribute) === null || _b === void 0 ? void 0 : _b.call(_a, this.attribname, this.attribvalue, quote);
|
||||
if (this.attribs &&
|
||||
!Object.prototype.hasOwnProperty.call(this.attribs, this.attribname)) {
|
||||
this.attribs[this.attribname] = this.attribvalue;
|
||||
}
|
||||
this.attribname = "";
|
||||
this.attribvalue = "";
|
||||
};
|
||||
Parser.prototype.getInstructionName = function (value) {
|
||||
var idx = value.search(reNameEnd);
|
||||
var name = idx < 0 ? value : value.substr(0, idx);
|
||||
if (this.lowerCaseTagNames) {
|
||||
name = name.toLowerCase();
|
||||
}
|
||||
return name;
|
||||
};
|
||||
Parser.prototype.ondeclaration = function (value) {
|
||||
if (this.cbs.onprocessinginstruction) {
|
||||
var name_1 = this.getInstructionName(value);
|
||||
this.cbs.onprocessinginstruction("!" + name_1, "!" + value);
|
||||
}
|
||||
};
|
||||
Parser.prototype.onprocessinginstruction = function (value) {
|
||||
if (this.cbs.onprocessinginstruction) {
|
||||
var name_2 = this.getInstructionName(value);
|
||||
this.cbs.onprocessinginstruction("?" + name_2, "?" + value);
|
||||
}
|
||||
};
|
||||
Parser.prototype.oncomment = function (value) {
|
||||
var _a, _b, _c, _d;
|
||||
this.updatePosition(4);
|
||||
(_b = (_a = this.cbs).oncomment) === null || _b === void 0 ? void 0 : _b.call(_a, value);
|
||||
(_d = (_c = this.cbs).oncommentend) === null || _d === void 0 ? void 0 : _d.call(_c);
|
||||
};
|
||||
Parser.prototype.oncdata = function (value) {
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
this.updatePosition(1);
|
||||
if (this.options.xmlMode || this.options.recognizeCDATA) {
|
||||
(_b = (_a = this.cbs).oncdatastart) === null || _b === void 0 ? void 0 : _b.call(_a);
|
||||
(_d = (_c = this.cbs).ontext) === null || _d === void 0 ? void 0 : _d.call(_c, value);
|
||||
(_f = (_e = this.cbs).oncdataend) === null || _f === void 0 ? void 0 : _f.call(_e);
|
||||
}
|
||||
else {
|
||||
this.oncomment("[CDATA[" + value + "]]");
|
||||
}
|
||||
};
|
||||
Parser.prototype.onerror = function (err) {
|
||||
var _a, _b;
|
||||
(_b = (_a = this.cbs).onerror) === null || _b === void 0 ? void 0 : _b.call(_a, err);
|
||||
};
|
||||
Parser.prototype.onend = function () {
|
||||
var _a, _b;
|
||||
if (this.cbs.onclosetag) {
|
||||
for (var i = this.stack.length; i > 0; this.cbs.onclosetag(this.stack[--i]))
|
||||
;
|
||||
}
|
||||
(_b = (_a = this.cbs).onend) === null || _b === void 0 ? void 0 : _b.call(_a);
|
||||
};
|
||||
/**
|
||||
* Resets the parser to a blank state, ready to parse a new HTML document
|
||||
*/
|
||||
Parser.prototype.reset = function () {
|
||||
var _a, _b, _c, _d;
|
||||
(_b = (_a = this.cbs).onreset) === null || _b === void 0 ? void 0 : _b.call(_a);
|
||||
this.tokenizer.reset();
|
||||
this.tagname = "";
|
||||
this.attribname = "";
|
||||
this.attribs = null;
|
||||
this.stack = [];
|
||||
(_d = (_c = this.cbs).onparserinit) === null || _d === void 0 ? void 0 : _d.call(_c, this);
|
||||
};
|
||||
/**
|
||||
* Resets the parser, then parses a complete document and
|
||||
* pushes it to the handler.
|
||||
*
|
||||
* @param data Document to parse.
|
||||
*/
|
||||
Parser.prototype.parseComplete = function (data) {
|
||||
this.reset();
|
||||
this.end(data);
|
||||
};
|
||||
/**
|
||||
* Parses a chunk of data and calls the corresponding callbacks.
|
||||
*
|
||||
* @param chunk Chunk to parse.
|
||||
*/
|
||||
Parser.prototype.write = function (chunk) {
|
||||
this.tokenizer.write(chunk);
|
||||
};
|
||||
/**
|
||||
* Parses the end of the buffer and clears the stack, calls onend.
|
||||
*
|
||||
* @param chunk Optional final chunk to parse.
|
||||
*/
|
||||
Parser.prototype.end = function (chunk) {
|
||||
this.tokenizer.end(chunk);
|
||||
};
|
||||
/**
|
||||
* Pauses parsing. The parser won't emit events until `resume` is called.
|
||||
*/
|
||||
Parser.prototype.pause = function () {
|
||||
this.tokenizer.pause();
|
||||
};
|
||||
/**
|
||||
* Resumes parsing after `pause` was called.
|
||||
*/
|
||||
Parser.prototype.resume = function () {
|
||||
this.tokenizer.resume();
|
||||
};
|
||||
/**
|
||||
* Alias of `write`, for backwards compatibility.
|
||||
*
|
||||
* @param chunk Chunk to parse.
|
||||
* @deprecated
|
||||
*/
|
||||
Parser.prototype.parseChunk = function (chunk) {
|
||||
this.write(chunk);
|
||||
};
|
||||
/**
|
||||
* Alias of `end`, for backwards compatibility.
|
||||
*
|
||||
* @param chunk Optional final chunk to parse.
|
||||
* @deprecated
|
||||
*/
|
||||
Parser.prototype.done = function (chunk) {
|
||||
this.end(chunk);
|
||||
};
|
||||
return Parser;
|
||||
}());
|
||||
exports.Parser = Parser;
|
||||
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
/** All the states the tokenizer can be in. */
|
||||
declare const enum State {
|
||||
Text = 1,
|
||||
BeforeTagName = 2,
|
||||
InTagName = 3,
|
||||
InSelfClosingTag = 4,
|
||||
BeforeClosingTagName = 5,
|
||||
InClosingTagName = 6,
|
||||
AfterClosingTagName = 7,
|
||||
BeforeAttributeName = 8,
|
||||
InAttributeName = 9,
|
||||
AfterAttributeName = 10,
|
||||
BeforeAttributeValue = 11,
|
||||
InAttributeValueDq = 12,
|
||||
InAttributeValueSq = 13,
|
||||
InAttributeValueNq = 14,
|
||||
BeforeDeclaration = 15,
|
||||
InDeclaration = 16,
|
||||
InProcessingInstruction = 17,
|
||||
BeforeComment = 18,
|
||||
InComment = 19,
|
||||
InSpecialComment = 20,
|
||||
AfterComment1 = 21,
|
||||
AfterComment2 = 22,
|
||||
BeforeCdata1 = 23,
|
||||
BeforeCdata2 = 24,
|
||||
BeforeCdata3 = 25,
|
||||
BeforeCdata4 = 26,
|
||||
BeforeCdata5 = 27,
|
||||
BeforeCdata6 = 28,
|
||||
InCdata = 29,
|
||||
AfterCdata1 = 30,
|
||||
AfterCdata2 = 31,
|
||||
BeforeSpecialS = 32,
|
||||
BeforeSpecialSEnd = 33,
|
||||
BeforeScript1 = 34,
|
||||
BeforeScript2 = 35,
|
||||
BeforeScript3 = 36,
|
||||
BeforeScript4 = 37,
|
||||
BeforeScript5 = 38,
|
||||
AfterScript1 = 39,
|
||||
AfterScript2 = 40,
|
||||
AfterScript3 = 41,
|
||||
AfterScript4 = 42,
|
||||
AfterScript5 = 43,
|
||||
BeforeStyle1 = 44,
|
||||
BeforeStyle2 = 45,
|
||||
BeforeStyle3 = 46,
|
||||
BeforeStyle4 = 47,
|
||||
AfterStyle1 = 48,
|
||||
AfterStyle2 = 49,
|
||||
AfterStyle3 = 50,
|
||||
AfterStyle4 = 51,
|
||||
BeforeSpecialT = 52,
|
||||
BeforeSpecialTEnd = 53,
|
||||
BeforeTitle1 = 54,
|
||||
BeforeTitle2 = 55,
|
||||
BeforeTitle3 = 56,
|
||||
BeforeTitle4 = 57,
|
||||
AfterTitle1 = 58,
|
||||
AfterTitle2 = 59,
|
||||
AfterTitle3 = 60,
|
||||
AfterTitle4 = 61,
|
||||
BeforeEntity = 62,
|
||||
BeforeNumericEntity = 63,
|
||||
InNamedEntity = 64,
|
||||
InNumericEntity = 65,
|
||||
InHexEntity = 66
|
||||
}
|
||||
export interface Callbacks {
|
||||
onattribdata(value: string): void;
|
||||
onattribend(quote: string | undefined | null): void;
|
||||
onattribname(name: string): void;
|
||||
oncdata(data: string): void;
|
||||
onclosetag(name: string): void;
|
||||
oncomment(data: string): void;
|
||||
ondeclaration(content: string): void;
|
||||
onend(): void;
|
||||
onerror(error: Error, state?: State): void;
|
||||
onopentagend(): void;
|
||||
onopentagname(name: string): void;
|
||||
onprocessinginstruction(instruction: string): void;
|
||||
onselfclosingtag(): void;
|
||||
ontext(value: string): void;
|
||||
}
|
||||
export default class Tokenizer {
|
||||
/** The current state the tokenizer is in. */
|
||||
_state: State;
|
||||
/** The read buffer. */
|
||||
private buffer;
|
||||
/** The beginning of the section that is currently being read. */
|
||||
sectionStart: number;
|
||||
/** The index within the buffer that we are currently looking at. */
|
||||
_index: number;
|
||||
/**
|
||||
* Data that has already been processed will be removed from the buffer occasionally.
|
||||
* `_bufferOffset` keeps track of how many characters have been removed, to make sure position information is accurate.
|
||||
*/
|
||||
private bufferOffset;
|
||||
/** Some behavior, eg. when decoding entities, is done while we are in another state. This keeps track of the other state type. */
|
||||
private baseState;
|
||||
/** For special parsing behavior inside of script and style tags. */
|
||||
private special;
|
||||
/** Indicates whether the tokenizer has been paused. */
|
||||
private running;
|
||||
/** Indicates whether the tokenizer has finished running / `.end` has been called. */
|
||||
private ended;
|
||||
private readonly cbs;
|
||||
private readonly xmlMode;
|
||||
private readonly decodeEntities;
|
||||
constructor(options: {
|
||||
xmlMode?: boolean;
|
||||
decodeEntities?: boolean;
|
||||
} | null, cbs: Callbacks);
|
||||
reset(): void;
|
||||
write(chunk: string): void;
|
||||
end(chunk?: string): void;
|
||||
pause(): void;
|
||||
resume(): void;
|
||||
/**
|
||||
* The current index within all of the written data.
|
||||
*/
|
||||
getAbsoluteIndex(): number;
|
||||
private stateText;
|
||||
/**
|
||||
* HTML only allows ASCII alpha characters (a-z and A-Z) at the beginning of a tag name.
|
||||
*
|
||||
* XML allows a lot more characters here (@see https://www.w3.org/TR/REC-xml/#NT-NameStartChar).
|
||||
* We allow anything that wouldn't end the tag.
|
||||
*/
|
||||
private isTagStartChar;
|
||||
private stateBeforeTagName;
|
||||
private stateInTagName;
|
||||
private stateBeforeClosingTagName;
|
||||
private stateInClosingTagName;
|
||||
private stateAfterClosingTagName;
|
||||
private stateBeforeAttributeName;
|
||||
private stateInSelfClosingTag;
|
||||
private stateInAttributeName;
|
||||
private stateAfterAttributeName;
|
||||
private stateBeforeAttributeValue;
|
||||
private handleInAttributeValue;
|
||||
private stateInAttributeValueDoubleQuotes;
|
||||
private stateInAttributeValueSingleQuotes;
|
||||
private stateInAttributeValueNoQuotes;
|
||||
private stateBeforeDeclaration;
|
||||
private stateInDeclaration;
|
||||
private stateInProcessingInstruction;
|
||||
private stateBeforeComment;
|
||||
private stateInComment;
|
||||
private stateInSpecialComment;
|
||||
private stateAfterComment1;
|
||||
private stateAfterComment2;
|
||||
private stateBeforeCdata6;
|
||||
private stateInCdata;
|
||||
private stateAfterCdata1;
|
||||
private stateAfterCdata2;
|
||||
private stateBeforeSpecialS;
|
||||
private stateBeforeSpecialSEnd;
|
||||
private stateBeforeSpecialLast;
|
||||
private stateAfterSpecialLast;
|
||||
private parseFixedEntity;
|
||||
private parseLegacyEntity;
|
||||
private stateInNamedEntity;
|
||||
private decodeNumericEntity;
|
||||
private stateInNumericEntity;
|
||||
private stateInHexEntity;
|
||||
private cleanup;
|
||||
/**
|
||||
* Iterates through the buffer, calling the function corresponding to the current state.
|
||||
*
|
||||
* States that are more likely to be hit are higher up, as a performance improvement.
|
||||
*/
|
||||
private parse;
|
||||
private finish;
|
||||
private handleTrailingData;
|
||||
private getSection;
|
||||
private emitToken;
|
||||
private emitPartial;
|
||||
}
|
||||
export {};
|
||||
//# sourceMappingURL=Tokenizer.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Tokenizer.d.ts","sourceRoot":"","sources":["../src/Tokenizer.ts"],"names":[],"mappings":"AAK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;IAaxB,OAAO,CAAC,mBAAmB;IAU3B,OAAO,CAAC,sBAAsB;IAO9B,OAAO,CAAC,sBAAsB;IAO9B,OAAO,CAAC,qBAAqB;IAS7B,OAAO,CAAC,gBAAgB;IAgBxB,OAAO,CAAC,iBAAiB;IAezB,OAAO,CAAC,kBAAkB;IA2B1B,OAAO,CAAC,mBAAmB;IAW3B,OAAO,CAAC,oBAAoB;IAY5B,OAAO,CAAC,gBAAgB;IAiBxB,OAAO,CAAC,OAAO;IA4Bf;;;;OAIG;IACH,OAAO,CAAC,KAAK;IAgJb,OAAO,CAAC,MAAM;IAQd,OAAO,CAAC,kBAAkB;IAmD1B,OAAO,CAAC,UAAU;IAGlB,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,WAAW;CAOtB"}
|
||||
+877
-938
File diff suppressed because it is too large
Load Diff
+16
@@ -0,0 +1,16 @@
|
||||
/// <reference types="node" />
|
||||
import { Handler, ParserOptions } from "./Parser";
|
||||
import { Writable } from "stream";
|
||||
/**
|
||||
* WritableStream makes the `Parser` interface available as a NodeJS stream.
|
||||
*
|
||||
* @see Parser
|
||||
*/
|
||||
export declare class WritableStream extends Writable {
|
||||
private readonly _parser;
|
||||
private readonly _decoder;
|
||||
constructor(cbs: Partial<Handler>, options?: ParserOptions);
|
||||
_write(chunk: string | Buffer, encoding: string, cb: () => void): void;
|
||||
_final(cb: () => void): void;
|
||||
}
|
||||
//# sourceMappingURL=WritableStream.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"WritableStream.d.ts","sourceRoot":"","sources":["../src/WritableStream.ts"],"names":[],"mappings":";AAAA,OAAO,EAAU,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAK1D,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAQlC;;;;GAIG;AACH,qBAAa,cAAe,SAAQ,QAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuB;gBAEpC,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,aAAa;IAK1D,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI;IAOtE,MAAM,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI;CAI/B"}
|
||||
+52
-24
@@ -1,25 +1,53 @@
|
||||
module.exports = Stream;
|
||||
|
||||
var Parser = require("./Parser.js");
|
||||
var WritableStream = require("readable-stream").Writable;
|
||||
var StringDecoder = require("string_decoder").StringDecoder;
|
||||
var Buffer = require("buffer").Buffer;
|
||||
|
||||
function Stream(cbs, options) {
|
||||
var parser = (this._parser = new Parser(cbs, options));
|
||||
var decoder = (this._decoder = new StringDecoder());
|
||||
|
||||
WritableStream.call(this, { decodeStrings: false });
|
||||
|
||||
this.once("finish", function() {
|
||||
parser.end(decoder.end());
|
||||
});
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.WritableStream = void 0;
|
||||
var Parser_1 = require("./Parser");
|
||||
/*
|
||||
* NOTE: If either of these two imports produces a type error,
|
||||
* please update your @types/node dependency!
|
||||
*/
|
||||
var stream_1 = require("stream");
|
||||
var string_decoder_1 = require("string_decoder");
|
||||
// Following the example in https://nodejs.org/api/stream.html#stream_decoding_buffers_in_a_writable_stream
|
||||
function isBuffer(_chunk, encoding) {
|
||||
return encoding === "buffer";
|
||||
}
|
||||
|
||||
require("inherits")(Stream, WritableStream);
|
||||
|
||||
Stream.prototype._write = function(chunk, encoding, cb) {
|
||||
if (chunk instanceof Buffer) chunk = this._decoder.write(chunk);
|
||||
this._parser.write(chunk);
|
||||
cb();
|
||||
};
|
||||
/**
|
||||
* WritableStream makes the `Parser` interface available as a NodeJS stream.
|
||||
*
|
||||
* @see Parser
|
||||
*/
|
||||
var WritableStream = /** @class */ (function (_super) {
|
||||
__extends(WritableStream, _super);
|
||||
function WritableStream(cbs, options) {
|
||||
var _this = _super.call(this, { decodeStrings: false }) || this;
|
||||
_this._decoder = new string_decoder_1.StringDecoder();
|
||||
_this._parser = new Parser_1.Parser(cbs, options);
|
||||
return _this;
|
||||
}
|
||||
WritableStream.prototype._write = function (chunk, encoding, cb) {
|
||||
this._parser.write(isBuffer(chunk, encoding) ? this._decoder.write(chunk) : chunk);
|
||||
cb();
|
||||
};
|
||||
WritableStream.prototype._final = function (cb) {
|
||||
this._parser.end(this._decoder.end());
|
||||
cb();
|
||||
};
|
||||
return WritableStream;
|
||||
}(stream_1.Writable));
|
||||
exports.WritableStream = WritableStream;
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
import { Parser, ParserOptions } from "./Parser";
|
||||
export { Parser, ParserOptions };
|
||||
import { DomHandler, DomHandlerOptions, Node, Element, Document } from "domhandler";
|
||||
export { DomHandler, DomHandlerOptions };
|
||||
declare type Options = ParserOptions & DomHandlerOptions;
|
||||
/**
|
||||
* Parses the data, returns the resulting document.
|
||||
*
|
||||
* @param data The data that should be parsed.
|
||||
* @param options Optional options for the parser and DOM builder.
|
||||
*/
|
||||
export declare function parseDocument(data: string, options?: Options): Document;
|
||||
/**
|
||||
* Parses data, returns an array of the root nodes.
|
||||
*
|
||||
* Note that the root nodes still have a `Document` node as their parent.
|
||||
* Use `parseDocument` to get the `Document` node instead.
|
||||
*
|
||||
* @param data The data that should be parsed.
|
||||
* @param options Optional options for the parser and DOM builder.
|
||||
* @deprecated Use `parseDocument` instead.
|
||||
*/
|
||||
export declare function parseDOM(data: string, options?: Options): Node[];
|
||||
/**
|
||||
* Creates a parser instance, with an attached DOM handler.
|
||||
*
|
||||
* @param cb A callback that will be called once parsing has been completed.
|
||||
* @param options Optional options for the parser and DOM builder.
|
||||
* @param elementCb An optional callback that will be called every time a tag has been completed inside of the DOM.
|
||||
*/
|
||||
export declare function createDomStream(cb: (error: Error | null, dom: Node[]) => void, options?: Options, elementCb?: (element: Element) => void): Parser;
|
||||
export { default as Tokenizer, Callbacks as TokenizerCallbacks, } from "./Tokenizer";
|
||||
import * as ElementType from "domelementtype";
|
||||
export { ElementType };
|
||||
export * from "./FeedHandler";
|
||||
export * as DomUtils from "domutils";
|
||||
export { DomHandler as DefaultHandler };
|
||||
export { FeedHandler as RssHandler } from "./FeedHandler";
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;AAEjC,OAAO,EACH,UAAU,EACV,iBAAiB,EACjB,IAAI,EACJ,OAAO,EACP,QAAQ,EACX,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAC;AAEzC,aAAK,OAAO,GAAG,aAAa,GAAG,iBAAiB,CAAC;AAIjD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,QAAQ,CAIvE;AACD;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,EAAE,CAEhE;AACD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC3B,EAAE,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,IAAI,EAC9C,OAAO,CAAC,EAAE,OAAO,EACjB,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,GACvC,MAAM,CAGR;AAED,OAAO,EACH,OAAO,IAAI,SAAS,EACpB,SAAS,IAAI,kBAAkB,GAClC,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,WAAW,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,CAAC;AAOvB,cAAc,eAAe,CAAC;AAC9B,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AAGrC,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,CAAC;AACxC,OAAO,EAAE,WAAW,IAAI,UAAU,EAAE,MAAM,eAAe,CAAC"}
|
||||
+83
-71
@@ -1,72 +1,84 @@
|
||||
var Parser = require("./Parser.js");
|
||||
var DomHandler = require("domhandler");
|
||||
|
||||
function defineProp(name, value) {
|
||||
delete module.exports[name];
|
||||
module.exports[name] = value;
|
||||
return value;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Parser: Parser,
|
||||
Tokenizer: require("./Tokenizer.js"),
|
||||
ElementType: require("domelementtype"),
|
||||
DomHandler: DomHandler,
|
||||
get FeedHandler() {
|
||||
return defineProp("FeedHandler", require("./FeedHandler.js"));
|
||||
},
|
||||
get Stream() {
|
||||
return defineProp("Stream", require("./Stream.js"));
|
||||
},
|
||||
get WritableStream() {
|
||||
return defineProp("WritableStream", require("./WritableStream.js"));
|
||||
},
|
||||
get ProxyHandler() {
|
||||
return defineProp("ProxyHandler", require("./ProxyHandler.js"));
|
||||
},
|
||||
get DomUtils() {
|
||||
return defineProp("DomUtils", require("domutils"));
|
||||
},
|
||||
get CollectingHandler() {
|
||||
return defineProp(
|
||||
"CollectingHandler",
|
||||
require("./CollectingHandler.js")
|
||||
);
|
||||
},
|
||||
// For legacy support
|
||||
DefaultHandler: DomHandler,
|
||||
get RssHandler() {
|
||||
return defineProp("RssHandler", this.FeedHandler);
|
||||
},
|
||||
//helper methods
|
||||
parseDOM: function(data, options) {
|
||||
var handler = new DomHandler(options);
|
||||
new Parser(handler, options).end(data);
|
||||
return handler.dom;
|
||||
},
|
||||
parseFeed: function(feed, options) {
|
||||
var handler = new module.exports.FeedHandler(options);
|
||||
new Parser(handler, options).end(feed);
|
||||
return handler.dom;
|
||||
},
|
||||
createDomStream: function(cb, options, elementCb) {
|
||||
var handler = new DomHandler(cb, options, elementCb);
|
||||
return new Parser(handler, options);
|
||||
},
|
||||
// List of all events that the parser emits
|
||||
EVENTS: {
|
||||
/* Format: eventname: number of arguments */
|
||||
attribute: 2,
|
||||
cdatastart: 0,
|
||||
cdataend: 0,
|
||||
text: 1,
|
||||
processinginstruction: 2,
|
||||
comment: 1,
|
||||
commentend: 0,
|
||||
closetag: 1,
|
||||
opentag: 2,
|
||||
opentagname: 1,
|
||||
error: 1,
|
||||
end: 0
|
||||
}
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.RssHandler = exports.DefaultHandler = exports.DomUtils = exports.ElementType = exports.Tokenizer = exports.createDomStream = exports.parseDOM = exports.parseDocument = exports.DomHandler = exports.Parser = void 0;
|
||||
var Parser_1 = require("./Parser");
|
||||
Object.defineProperty(exports, "Parser", { enumerable: true, get: function () { return Parser_1.Parser; } });
|
||||
var domhandler_1 = require("domhandler");
|
||||
Object.defineProperty(exports, "DomHandler", { enumerable: true, get: function () { return domhandler_1.DomHandler; } });
|
||||
Object.defineProperty(exports, "DefaultHandler", { enumerable: true, get: function () { return domhandler_1.DomHandler; } });
|
||||
// Helper methods
|
||||
/**
|
||||
* Parses the data, returns the resulting document.
|
||||
*
|
||||
* @param data The data that should be parsed.
|
||||
* @param options Optional options for the parser and DOM builder.
|
||||
*/
|
||||
function parseDocument(data, options) {
|
||||
var handler = new domhandler_1.DomHandler(undefined, options);
|
||||
new Parser_1.Parser(handler, options).end(data);
|
||||
return handler.root;
|
||||
}
|
||||
exports.parseDocument = parseDocument;
|
||||
/**
|
||||
* Parses data, returns an array of the root nodes.
|
||||
*
|
||||
* Note that the root nodes still have a `Document` node as their parent.
|
||||
* Use `parseDocument` to get the `Document` node instead.
|
||||
*
|
||||
* @param data The data that should be parsed.
|
||||
* @param options Optional options for the parser and DOM builder.
|
||||
* @deprecated Use `parseDocument` instead.
|
||||
*/
|
||||
function parseDOM(data, options) {
|
||||
return parseDocument(data, options).children;
|
||||
}
|
||||
exports.parseDOM = parseDOM;
|
||||
/**
|
||||
* Creates a parser instance, with an attached DOM handler.
|
||||
*
|
||||
* @param cb A callback that will be called once parsing has been completed.
|
||||
* @param options Optional options for the parser and DOM builder.
|
||||
* @param elementCb An optional callback that will be called every time a tag has been completed inside of the DOM.
|
||||
*/
|
||||
function createDomStream(cb, options, elementCb) {
|
||||
var handler = new domhandler_1.DomHandler(cb, options, elementCb);
|
||||
return new Parser_1.Parser(handler, options);
|
||||
}
|
||||
exports.createDomStream = createDomStream;
|
||||
var Tokenizer_1 = require("./Tokenizer");
|
||||
Object.defineProperty(exports, "Tokenizer", { enumerable: true, get: function () { return __importDefault(Tokenizer_1).default; } });
|
||||
var ElementType = __importStar(require("domelementtype"));
|
||||
exports.ElementType = ElementType;
|
||||
/*
|
||||
* All of the following exports exist for backwards-compatibility.
|
||||
* They should probably be removed eventually.
|
||||
*/
|
||||
__exportStar(require("./FeedHandler"), exports);
|
||||
exports.DomUtils = __importStar(require("domutils"));
|
||||
var FeedHandler_1 = require("./FeedHandler");
|
||||
Object.defineProperty(exports, "RssHandler", { enumerable: true, get: function () { return FeedHandler_1.FeedHandler; } });
|
||||
|
||||
+52
-33
@@ -1,65 +1,76 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"htmlparser2@3.10.1",
|
||||
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
|
||||
"htmlparser2@6.1.0",
|
||||
"/home/node/nuxt"
|
||||
]
|
||||
],
|
||||
"_from": "htmlparser2@3.10.1",
|
||||
"_id": "htmlparser2@3.10.1",
|
||||
"_from": "htmlparser2@6.1.0",
|
||||
"_id": "htmlparser2@6.1.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-IgieNijUMbkDovyoKObU1DUhm1iwNYE/fuifEoEHfd1oZKZDaONBSkal7Y01shxsM49R4XaMdGez3WnF9UfiCQ==",
|
||||
"_integrity": "sha512-gyyPk6rgonLFEDGoeRgQNaEUvdJ4ktTmmUh/h2t7s+M8oPpIPxgNACWa+6ESR57kXstwqPiCut0V8NRpcwgU7A==",
|
||||
"_location": "/htmlparser2",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "htmlparser2@3.10.1",
|
||||
"raw": "htmlparser2@6.1.0",
|
||||
"name": "htmlparser2",
|
||||
"escapedName": "htmlparser2",
|
||||
"rawSpec": "3.10.1",
|
||||
"rawSpec": "6.1.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "3.10.1"
|
||||
"fetchSpec": "6.1.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/renderkid"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.10.1.tgz",
|
||||
"_spec": "3.10.1",
|
||||
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
|
||||
"_resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-6.1.0.tgz",
|
||||
"_spec": "6.1.0",
|
||||
"_where": "/home/node/nuxt",
|
||||
"author": {
|
||||
"name": "Felix Boehm",
|
||||
"email": "me@feedic.com"
|
||||
},
|
||||
"browser": {
|
||||
"readable-stream": false
|
||||
},
|
||||
"bugs": {
|
||||
"url": "http://github.com/fb55/htmlparser2/issues"
|
||||
"url": "https://github.com/fb55/htmlparser2/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"domelementtype": "^1.3.1",
|
||||
"domhandler": "^2.3.0",
|
||||
"domutils": "^1.5.1",
|
||||
"entities": "^1.1.1",
|
||||
"inherits": "^2.0.1",
|
||||
"readable-stream": "^3.1.1"
|
||||
"domelementtype": "^2.0.1",
|
||||
"domhandler": "^4.0.0",
|
||||
"domutils": "^2.5.2",
|
||||
"entities": "^2.0.0"
|
||||
},
|
||||
"description": "Fast & forgiving HTML/XML/RSS parser",
|
||||
"description": "Fast & forgiving HTML/XML parser",
|
||||
"devDependencies": {
|
||||
"coveralls": "^3.0.1",
|
||||
"eslint": "^5.13.0",
|
||||
"istanbul": "^0.4.3",
|
||||
"mocha": "^5.2.0",
|
||||
"mocha-lcov-reporter": "^1.2.0"
|
||||
"@types/jest": "^26.0.0",
|
||||
"@types/node": "^14.0.5",
|
||||
"@typescript-eslint/eslint-plugin": "^4.9.1",
|
||||
"@typescript-eslint/parser": "^4.9.1",
|
||||
"eslint": "^7.15.0",
|
||||
"eslint-config-prettier": "^8.1.0",
|
||||
"jest": "^26.0.1",
|
||||
"prettier": "^2.1.1",
|
||||
"ts-jest": "^26.0.0",
|
||||
"typescript": "^4.0.2"
|
||||
},
|
||||
"directories": {
|
||||
"lib": "lib/"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
"lib/**/*"
|
||||
],
|
||||
"funding": [
|
||||
"https://github.com/fb55/htmlparser2?sponsor=1",
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/fb55"
|
||||
}
|
||||
],
|
||||
"homepage": "https://github.com/fb55/htmlparser2#readme",
|
||||
"jest": {
|
||||
"preset": "ts-jest",
|
||||
"testEnvironment": "node"
|
||||
},
|
||||
"keywords": [
|
||||
"html",
|
||||
"parser",
|
||||
@@ -81,10 +92,18 @@
|
||||
"url": "git://github.com/fb55/htmlparser2.git"
|
||||
},
|
||||
"scripts": {
|
||||
"coveralls": "npm run lint && npm run lcov && (cat coverage/lcov.info | coveralls || exit 0)",
|
||||
"lcov": "istanbul cover _mocha --report lcovonly -- -R spec",
|
||||
"lint": "eslint lib test",
|
||||
"test": "mocha && npm run lint"
|
||||
"build": "tsc",
|
||||
"format": "npm run format:es && npm run format:prettier",
|
||||
"format:es": "npm run lint:es -- --fix",
|
||||
"format:prettier": "npm run format:prettier:raw -- --write",
|
||||
"format:prettier:raw": "prettier '**/*.{ts,md,json,yml}'",
|
||||
"lint": "npm run lint:es && npm run lint:prettier",
|
||||
"lint:es": "eslint src",
|
||||
"lint:prettier": "npm run format:prettier:raw -- --check",
|
||||
"prepare": "npm run build",
|
||||
"test": "jest --coverage"
|
||||
},
|
||||
"version": "3.10.1"
|
||||
"sideEffects": false,
|
||||
"types": "lib/index.d.ts",
|
||||
"version": "6.1.0"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user