Skip to content

Commit 62524b8

Browse files
authored
refactor(*): migrate to parse5 to reduce dependency (#318)
This pull request refactors the HTML parsing logic in the `textlint-rule-allowed-uris` rule to use the `parse5` library instead of `cheerio`, improving standards compliance and reliability. The main changes include updating dependencies, rewriting the HTML node handler, and adding new helper functions and tests. **Dependency update:** * Replaced the `cheerio` dependency with `parse5` in `package.json` to use a more robust HTML parser. **Refactoring HTML parsing:** * Rewrote the import statements and added type imports for `parse5` in `src/textlint-rule-allowed-uris.js`. [[1]](diffhunk://#diff-7da72e1e0d5c49a43b94f9d928d3157918c0bdcc3121c5ed14e0bc459b3f26f9L10-R10) [[2]](diffhunk://#diff-7da72e1e0d5c49a43b94f9d928d3157918c0bdcc3121c5ed14e0bc459b3f26f9R19) * Added a new helper function `getElementsByTagName` to recursively find elements by tag name in HTML fragments using `parse5`. * Refactored the `Html` node handler to use `getElementsByTagName` for extracting `href` and `src` attributes from `<a>` and `<img>` tags, replacing the previous cheerio-based approach. **Testing improvements:** * Added new test cases to ensure correct handling of HTML nodes with various tag and attribute casing, improving coverage for the new parsing logic.
1 parent 19ac24e commit 62524b8

File tree

4 files changed

+189
-25
lines changed

4 files changed

+189
-25
lines changed

package-lock.json

Lines changed: 109 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,6 @@
9696
"typescript": "^5.9.2"
9797
},
9898
"dependencies": {
99-
"cheerio": "^1.1.2"
99+
"parse5": "^8.0.0"
100100
}
101101
}

0 commit comments

Comments
 (0)