node-html-parser
Advanced tools
+10
-0
@@ -5,2 +5,12 @@ # Changelog | ||
| ### [7.0.2](https://github.com/taoqf/node-fast-html-parser/compare/v7.0.1...v7.0.2) (2026-01-07) | ||
| ### Bug Fixes | ||
| * [#227](https://github.com/taoqf/node-fast-html-parser/issues/227) ([51528c4](https://github.com/taoqf/node-fast-html-parser/commit/51528c41ef2648d6c4dc1aecd14ee9d2b0083c4f)) | ||
| * [#294](https://github.com/taoqf/node-fast-html-parser/issues/294) Closing tag is missing but valid HTML is still not parseable ([950865f](https://github.com/taoqf/node-fast-html-parser/commit/950865fab5f4df7853b36712869b71c90f4d3a1b)) | ||
| * add missing dev dependency: yarn ([6d73ea3](https://github.com/taoqf/node-fast-html-parser/commit/6d73ea37c48f4170c35907869ba410c5122a9a1f)) | ||
| * test valid.js ([a81fc46](https://github.com/taoqf/node-fast-html-parser/commit/a81fc46fab2507615b0362150d62568a6f52ee4e)) | ||
| ### [7.0.1](https://github.com/taoqf/node-fast-html-parser/compare/v7.0.0...v7.0.1) (2024-12-26) | ||
@@ -7,0 +17,0 @@ |
@@ -46,4 +46,4 @@ import VoidTag from '../void-tag'; | ||
| private _parseOptions; | ||
| private _id; | ||
| rawTagName: string; | ||
| id: string; | ||
| classList: DOMTokenList; | ||
@@ -83,2 +83,4 @@ /** | ||
| get isVoidElement(): boolean; | ||
| get id(): string; | ||
| set id(newid: string); | ||
| /** | ||
@@ -85,0 +87,0 @@ * Get escpaed (as-it) text value of current node and its children. |
+39
-7
@@ -129,3 +129,3 @@ "use strict"; | ||
| this.rawAttrs = rawAttrs || ''; | ||
| this.id = keyAttrs.id || ''; | ||
| this._id = keyAttrs.id || ''; | ||
| this.childNodes = []; | ||
@@ -189,2 +189,8 @@ this._parseOptions = _parseOptions; | ||
| } | ||
| get id() { | ||
| return this._id; | ||
| } | ||
| set id(newid) { | ||
| this.setAttribute('id', newid); | ||
| } | ||
| /** | ||
@@ -355,3 +361,3 @@ * Get escpaed (as-it) text value of current node and its children. | ||
| function dfs(node) { | ||
| const idStr = node.id ? `#${node.id}` : ''; | ||
| const idStr = node._id ? `#${node._id}` : ''; | ||
| const classStr = node.classList.length ? `.${node.classList.value.join('.')}` : ''; // eslint-disable-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-call | ||
@@ -489,3 +495,3 @@ write(`${node.rawTagName}${idStr}${classStr}`); | ||
| if (child.nodeType === type_1.default.ELEMENT_NODE) { | ||
| if (child.id === id) { | ||
| if (child._id === id) { | ||
| return child; | ||
@@ -630,5 +636,5 @@ } | ||
| .join(' '); | ||
| // Update this.id | ||
| // Update this._id | ||
| if (key === 'id') { | ||
| this.id = ''; | ||
| this._id = ''; | ||
| } | ||
@@ -678,5 +684,5 @@ return this; | ||
| .join(' '); | ||
| // Update this.id | ||
| // Update this._id | ||
| if (key === 'id') { | ||
| this.id = value; | ||
| this._id = value; | ||
| } | ||
@@ -707,2 +713,6 @@ return this; | ||
| .join(' '); | ||
| // Update this._id | ||
| if ('id' in attributes) { | ||
| this._id = attributes['id']; | ||
| } | ||
| return this; | ||
@@ -915,2 +925,5 @@ } | ||
| }; | ||
| const kElementsClosedByClosingExcept = { | ||
| p: { a: true, audio: true, del: true, ins: true, map: true, noscript: true, video: true }, | ||
| }; | ||
| const frameflag = 'documentfragmentcontainer'; | ||
@@ -1060,2 +1073,21 @@ /** | ||
| } | ||
| const openTag = currentParent.rawTagName ? | ||
| currentParent.rawTagName.toLowerCase() : | ||
| ''; | ||
| if (kElementsClosedByClosingExcept[openTag]) { | ||
| const closingTag = tagName.toLowerCase(); | ||
| if (stack.length > 1) { | ||
| const possibleContainer = stack[stack.length - 2]; | ||
| if (possibleContainer && | ||
| possibleContainer.rawTagName && | ||
| possibleContainer.rawTagName.toLowerCase() === closingTag && | ||
| !kElementsClosedByClosingExcept[openTag][closingTag]) { | ||
| // Update range end for closed tag | ||
| currentParent.range[1] = createRange(-1, Math.max(lastTextPos, tagEndPos))[1]; | ||
| stack.pop(); | ||
| currentParent = (0, back_1.default)(stack); | ||
| continue; | ||
| } | ||
| } | ||
| } | ||
| // Use aggressive strategy to handle unmatching markups. | ||
@@ -1062,0 +1094,0 @@ break; |
+3
-2
| { | ||
| "name": "node-html-parser", | ||
| "version": "7.0.1", | ||
| "version": "7.0.2", | ||
| "description": "A very fast HTML parser, generating a simplified DOM, with basic element query support.", | ||
@@ -90,3 +90,4 @@ "main": "dist/index.js", | ||
| "ts-node": "^10.9.1", | ||
| "typescript": "latest" | ||
| "typescript": "latest", | ||
| "yarn": "^1.22.22" | ||
| }, | ||
@@ -93,0 +94,0 @@ "config": { |
+4
-3
@@ -46,2 +46,3 @@ # Fast HTML Parser [](http://badge.fury.io/js/node-html-parser) [](https://actions-badge.atrox.dev/taoqf/node-html-parser/goto?ref=main) | ||
| // parse() adds a wrapper node, so the input data's first node is the root's first child node | ||
| console.log(root.firstChild.structure); | ||
@@ -78,3 +79,3 @@ // ul#list | ||
| Parse the data provided, and return the root of the generated DOM. | ||
| Parse the data provided, wrap the result in a new node, and return the root of the generated DOM. | ||
@@ -354,7 +355,7 @@ - **data**, data to parse | ||
| Get first child node. `undefined` if the node has no children. | ||
| Get first child node of the wrapper node added by `parse()`. `undefined` if the node has no children. | ||
| ### lastChild | ||
| Get last child node. `undefined` if the node has no children. | ||
| Get last child node of the wrapper node added by `parse()`. `undefined` if the node has no children. | ||
@@ -361,0 +362,0 @@ ### firstElementChild |
Sorry, the diff of this file is too big to display
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
168552
2.66%3714
1.92%406
0.25%35
2.94%