node-html-parser
Advanced tools
+13
-0
@@ -5,2 +5,15 @@ # Changelog | ||
| ## [7.1.0](https://github.com/taoqf/node-fast-html-parser/compare/v7.0.2...v7.1.0) (2026-03-03) | ||
| ### Features | ||
| * add option closeAllOnClosing ([44c900a](https://github.com/taoqf/node-fast-html-parser/commit/44c900acc01b8923eb9e45c7b13d6bd148a8e9cd)), closes [#294](https://github.com/taoqf/node-fast-html-parser/issues/294) | ||
| * add preserveTagNesting option to maintain invalid HTML nesting [#295](https://github.com/taoqf/node-fast-html-parser/issues/295) ([d604652](https://github.com/taoqf/node-fast-html-parser/commit/d604652cc7c963118ba16ec6bda1f4e01fb81c9e)) | ||
| ### Bug Fixes | ||
| * add missing dev dependency: yarn ([8679d32](https://github.com/taoqf/node-fast-html-parser/commit/8679d3231e6dc1c93f99921d16b728aa9a578ce5)) | ||
| ### [7.0.2](https://github.com/taoqf/node-fast-html-parser/compare/v7.0.1...v7.0.2) (2026-01-07) | ||
@@ -7,0 +20,0 @@ |
+11
-0
@@ -136,2 +136,8 @@ import VoidTag from '../void-tag'; | ||
| /** | ||
| * Tests whether the node matches a given CSS selector. | ||
| * @param {string} selector Simplified CSS selector | ||
| * @return {boolean} | ||
| */ | ||
| matches(selector: string): boolean; | ||
| /** | ||
| * find elements by their tagName | ||
@@ -237,2 +243,6 @@ * @param {string} tagName the tagName of the elements to select | ||
| parseNoneClosedTags?: boolean; | ||
| /** | ||
| * When true, preserves invalid HTML nesting (e.g., <p><p>bar</p></p>) instead of auto-closing tags | ||
| */ | ||
| preserveTagNesting?: boolean; | ||
| blockTextElements: { | ||
@@ -251,2 +261,3 @@ [tag: string]: boolean; | ||
| }; | ||
| closeAllByClosing?: boolean; | ||
| } | ||
@@ -253,0 +264,0 @@ /** |
+29
-1
@@ -431,2 +431,13 @@ "use strict"; | ||
| /** | ||
| * Tests whether the node matches a given CSS selector. | ||
| * @param {string} selector Simplified CSS selector | ||
| * @return {boolean} | ||
| */ | ||
| matches(selector) { | ||
| return (0, css_select_1.is)(this, selector, { | ||
| xmlMode: true, | ||
| adapter: matcher_1.default, | ||
| }); | ||
| } | ||
| /** | ||
| * find elements by their tagName | ||
@@ -1001,3 +1012,3 @@ * @param {string} tagName the tagName of the elements to select | ||
| const parentTagName = currentParent.rawTagName; | ||
| if (!closingSlash && kElementsClosedByOpening[parentTagName]) { | ||
| if (!closingSlash && !options.preserveTagNesting && kElementsClosedByOpening[parentTagName]) { | ||
| if (kElementsClosedByOpening[parentTagName][tagName]) { | ||
@@ -1086,2 +1097,19 @@ stack.pop(); | ||
| } | ||
| if (options.closeAllByClosing === true) { | ||
| // If tag was opened, close all nested tags | ||
| let i; | ||
| for (i = stack.length - 2; i >= 0; i--) { | ||
| if (stack[i].rawTagName === tagName) | ||
| break; | ||
| } | ||
| if (i >= 0) { | ||
| while (stack.length > i) { | ||
| // 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. | ||
@@ -1088,0 +1116,0 @@ break; |
+1
-1
| { | ||
| "name": "node-html-parser", | ||
| "version": "7.0.2", | ||
| "version": "7.1.0", | ||
| "description": "A very fast HTML parser, generating a simplified DOM, with basic element query support.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
+8
-1
@@ -89,2 +89,3 @@ # Fast HTML Parser [](http://badge.fury.io/js/node-html-parser) [](https://actions-badge.atrox.dev/taoqf/node-html-parser/goto?ref=main) | ||
| parseNoneClosedTags: false, // close none closed HTML tags instead of removing them | ||
| preserveTagNesting: false, // preserve invalid HTML nesting instead of auto-closing tags (e.g. <p><p>bar</p></p>) | ||
| voidTag: { | ||
@@ -99,3 +100,4 @@ tags: ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'], // optional and case insensitive, default value is ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'] | ||
| pre: true // keep text content when parsing | ||
| } | ||
| }, | ||
| closeAllOnClosing: false // Close all non-closed tags when containing element closes | ||
| } | ||
@@ -118,2 +120,3 @@ ``` | ||
| Node querySelector(string selector) | ||
| boolean matches(string selector) | ||
| HTMLElement[] getElementsByTagName(string tagName) | ||
@@ -213,2 +216,6 @@ Node closest(string selector) | ||
| ### matches(selector) | ||
| Tests whether the node matches a given CSS selector. | ||
| ### getElementsByTagName(tagName) | ||
@@ -215,0 +222,0 @@ |
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
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
172579
2.39%3781
1.8%413
1.72%