node-html-parser
Advanced tools
Comparing version 6.1.0 to 6.1.1
@@ -5,2 +5,9 @@ # Changelog | ||
### [6.1.1](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.0...v6.1.1) (2022-09-24) | ||
### Bug Fixes | ||
* parse comments ([82b68ff](https://github.com/taoqf/node-fast-html-parser/commit/82b68ff9eb944e0c55ca2e0ea13fb714e2004803)) | ||
## [6.1.0](https://github.com/taoqf/node-fast-html-parser/compare/v6.0.0...v6.1.0) (2022-09-19) | ||
@@ -7,0 +14,0 @@ |
@@ -21,6 +21,3 @@ "use strict"; | ||
function parse(data, options) { | ||
if (options === void 0) { options = { | ||
lowerCaseTagName: false, | ||
comment: false | ||
}; } | ||
if (options === void 0) { options = {}; } | ||
return (0, parse_1.default)(data, options); | ||
@@ -27,0 +24,0 @@ } |
@@ -44,2 +44,3 @@ import VoidTag from '../void-tag'; | ||
private _rawAttrs; | ||
private _parseOptions; | ||
rawTagName: string; | ||
@@ -65,3 +66,3 @@ id: string; | ||
*/ | ||
constructor(tagName: string, keyAttrs: KeyAttributes, rawAttrs: string, parentNode: HTMLElement | null, range: [number, number], voidTag?: VoidTag); | ||
constructor(tagName: string, keyAttrs: KeyAttributes, rawAttrs: string, parentNode: HTMLElement | null, range: [number, number], voidTag?: VoidTag, _parseOptions?: Partial<Options>); | ||
/** | ||
@@ -206,4 +207,4 @@ * Remove Child element from childNodes array | ||
export interface Options { | ||
lowerCaseTagName: boolean; | ||
comment: boolean; | ||
lowerCaseTagName?: boolean; | ||
comment?: boolean; | ||
/** | ||
@@ -210,0 +211,0 @@ * @see PR #215 for explanation |
@@ -157,5 +157,6 @@ "use strict"; | ||
*/ | ||
function HTMLElement(tagName, keyAttrs, rawAttrs, parentNode, range, voidTag) { | ||
function HTMLElement(tagName, keyAttrs, rawAttrs, parentNode, range, voidTag, _parseOptions) { | ||
if (rawAttrs === void 0) { rawAttrs = ''; } | ||
if (voidTag === void 0) { voidTag = new void_tag_1.default(); } | ||
if (_parseOptions === void 0) { _parseOptions = {}; } | ||
var _this = _super.call(this, parentNode, range) || this; | ||
@@ -172,2 +173,3 @@ _this.rawAttrs = rawAttrs; | ||
_this.childNodes = []; | ||
_this._parseOptions = _parseOptions; | ||
_this.classList = new DOMTokenList(keyAttrs.class ? keyAttrs.class.split(/\s+/) : [], function (classList) { return _this.setAttribute('class', classList.toString()); } // eslint-disable-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call | ||
@@ -354,4 +356,3 @@ ); | ||
set: function (content) { | ||
//const r = parse(content, global.options); // TODO global.options ? | ||
var r = parse(content); | ||
var r = parse(content, this._parseOptions); | ||
var nodes = r.childNodes.length ? r.childNodes : [new text_1.default(content, this)]; | ||
@@ -371,4 +372,5 @@ resetParent(nodes, this); | ||
else if (typeof content == 'string') { | ||
options = __assign(__assign({}, this._parseOptions), options); | ||
var r = parse(content, options); | ||
content = r.childNodes.length ? r.childNodes : [new text_1.default(content, this)]; | ||
content = r.childNodes.length ? r.childNodes : [new text_1.default(r.innerHTML, this)]; | ||
} | ||
@@ -393,4 +395,3 @@ resetParent(this.childNodes, null); | ||
else if (typeof node == 'string') { | ||
// const r = parse(content, global.options); // TODO global.options ? | ||
var r = parse(node); | ||
var r = parse(node, _this._parseOptions); | ||
return r.childNodes.length ? r.childNodes : [new text_1.default(node, _this)]; | ||
@@ -836,3 +837,3 @@ } | ||
} | ||
var p = parse(html); | ||
var p = parse(html, this._parseOptions); | ||
if (where === 'afterend') { | ||
@@ -958,3 +959,3 @@ var idx = this.parentNode.childNodes.findIndex(function (child) { | ||
HTMLElement.prototype.clone = function () { | ||
return parse(this.toString()).firstChild; | ||
return parse(this.toString(), this._parseOptions).firstChild; | ||
}; | ||
@@ -1046,3 +1047,3 @@ return HTMLElement; | ||
var _a, _b; | ||
if (options === void 0) { options = { lowerCaseTagName: false, comment: false }; } | ||
if (options === void 0) { options = {}; } | ||
var voidTag = new void_tag_1.default((_a = options === null || options === void 0 ? void 0 : options.voidTag) === null || _a === void 0 ? void 0 : _a.closingSlash, (_b = options === null || options === void 0 ? void 0 : options.voidTag) === null || _b === void 0 ? void 0 : _b.tags); | ||
@@ -1065,3 +1066,3 @@ var elements = options.blockTextElements || { | ||
var createRange = function (startPos, endPos) { return [startPos - frameFlagOffset, endPos - frameFlagOffset]; }; | ||
var root = new HTMLElement(null, {}, '', null, [0, data.length], voidTag); | ||
var root = new HTMLElement(null, {}, '', null, [0, data.length], voidTag, options); | ||
var currentParent = root; | ||
@@ -1137,3 +1138,3 @@ var stack = [root]; | ||
// Initialize range (end position updated later for closed tags) | ||
new HTMLElement(tagName, attrs, attributes.slice(1), null, createRange(tagStartPos_1, tagEndPos_1), voidTag)); | ||
new HTMLElement(tagName, attrs, attributes.slice(1), null, createRange(tagStartPos_1, tagEndPos_1), voidTag, options)); | ||
stack.push(currentParent); | ||
@@ -1199,3 +1200,3 @@ if (is_block_text_element(tagName)) { | ||
function parse(data, options) { | ||
if (options === void 0) { options = { lowerCaseTagName: false, comment: false }; } | ||
if (options === void 0) { options = {}; } | ||
var stack = base_parse(data, options); | ||
@@ -1202,0 +1203,0 @@ var root = stack[0]; |
@@ -9,3 +9,3 @@ "use strict"; | ||
function valid(data, options) { | ||
if (options === void 0) { options = { lowerCaseTagName: false, comment: false }; } | ||
if (options === void 0) { options = {}; } | ||
var stack = (0, html_1.base_parse)(data, options); | ||
@@ -12,0 +12,0 @@ return Boolean(stack.length === 1); |
{ | ||
"name": "node-html-parser", | ||
"version": "6.1.0", | ||
"version": "6.1.1", | ||
"description": "A very fast HTML parser, generating a simplified DOM, with basic element query support.", | ||
@@ -11,2 +11,3 @@ "main": "dist/index.js", | ||
"compile:cjs": "tsc -m commonjs", | ||
"watch": "npx tsc -m commonjs --watch --preserveWatchOutput", | ||
"compile:amd": "tsc -t es5 -m amd -d false --outFile ./dist/main.js", | ||
@@ -51,3 +52,3 @@ "lint": "eslint ./src/*.ts ./src/**/*.ts", | ||
"dependencies": { | ||
"css-select": "^4.2.1", | ||
"css-select": "^5.1.0", | ||
"he": "1.2.0" | ||
@@ -63,15 +64,15 @@ }, | ||
"blanket": "latest", | ||
"cheerio": "^1.0.0-rc.5", | ||
"cheerio": "^1.0.0-rc.12", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^7.32.0", | ||
"eslint": "^8.23.1", | ||
"eslint-config-prettier": "latest", | ||
"eslint-plugin-import": "latest", | ||
"high5": "^1.0.0", | ||
"html-dom-parser": "^1.0.4", | ||
"html-dom-parser": "^3.1.2", | ||
"html-parser": "^0.11.0", | ||
"html5parser": "^2.0.2", | ||
"htmljs-parser": "^2.11.1", | ||
"htmljs-parser": "^5.1.4", | ||
"htmlparser": "^1.7.7", | ||
"htmlparser-benchmark": "^1.1.3", | ||
"htmlparser2": "^6.0.0", | ||
"htmlparser2": "^8.0.1", | ||
"mocha": "latest", | ||
@@ -81,3 +82,3 @@ "mocha-each": "^2.0.1", | ||
"np": "latest", | ||
"parse5": "^6.0.1", | ||
"parse5": "^7.1.1", | ||
"rimraf": "^3.0.2", | ||
@@ -87,5 +88,5 @@ "saxes": "^6.0.0", | ||
"spec": "latest", | ||
"standard-version": "^9.3.1", | ||
"standard-version": "^9.5.0", | ||
"travis-cov": "latest", | ||
"ts-node": "^10.2.1", | ||
"ts-node": "^10.9.1", | ||
"typescript": "latest" | ||
@@ -92,0 +93,0 @@ }, |
Sorry, the diff of this file is too big to display
158371
3725
+ Addedcss-select@5.1.0(transitive)
+ Addeddom-serializer@2.0.0(transitive)
+ Addeddomhandler@5.0.3(transitive)
+ Addeddomutils@3.1.0(transitive)
+ Addedentities@4.5.0(transitive)
- Removedcss-select@4.3.0(transitive)
- Removeddom-serializer@1.4.1(transitive)
- Removeddomhandler@4.3.1(transitive)
- Removeddomutils@2.8.0(transitive)
- Removedentities@2.2.0(transitive)
Updatedcss-select@^5.1.0