-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add rawContentTags options #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
yeonjuan
commented
Jul 20, 2025
- [FEATURE] Add support for ignoring children of arbitrary tags html-eslint#381
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds customTags options to the HTML tokenizer, allowing users to specify custom HTML tags that should have their content treated as raw text (similar to script/style tags). This feature addresses issue #381 by enabling custom tag handling with configurable behavior.
Key changes:
- Introduces
CustomTagOptions
andCustomTagOptionsConfig
types for configuration - Adds custom tag raw content handling with a new tokenizer context
- Updates the tokenize function API to accept options object instead of separate parameters
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
src/types/parse.ts | Defines new types for custom tag configuration options |
src/types/tokenizer-state.ts | Adds custom tag support to tokenizer state and context parameters |
src/constants/tokenizer-context-types.ts | Adds new CustomTagRawContent context type enum |
src/tokenizer/tokenize.ts | Updates tokenize function signature to accept options object |
src/tokenizer/handlers/open-tag-end.ts | Implements custom tag detection and context switching logic |
src/tokenizer/handlers/custom-tag-raw-content.ts | New handler for processing custom tag raw content |
src/tokenizer/handlers/index.ts | Exports the new custom tag raw content handler |
src/parser/parse.ts | Updates parse function to pass through options object |
src/tokenizer/tests/tokenize.spec.ts | Updates test cases to use new options object format |
src/tokenizer/tests/input/custom-tag-raw-content.html | Test input file for custom tag functionality |
src/tokenizer/tests/output/custom-tag-raw-content.ts | Expected test output for custom tag functionality |
state.sourceCode.next(); | ||
return; | ||
} | ||
const regex = new RegExp( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating a new RegExp instance on every parse call is inefficient. Consider creating the regex once and reusing it, or use a more efficient string matching approach for the closing tag detection.
Copilot uses AI. Check for mistakes.
const regex = new RegExp( | ||
"</" + | ||
state.contextParams[TokenizerContextTypes.CustomTagRawContent]?.tagName + | ||
"\\s*>" | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tag name is directly interpolated into a regex without escaping. This could lead to regex injection if the tag name contains special regex characters. Use a regex escape function or string-based matching instead.
const regex = new RegExp( | |
"</" + | |
state.contextParams[TokenizerContextTypes.CustomTagRawContent]?.tagName + | |
"\\s*>" | |
); | |
const escapeRegExp = (string: string) => | |
string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); | |
const tagName = state.contextParams[TokenizerContextTypes.CustomTagRawContent]?.tagName; | |
const regex = new RegExp("</" + escapeRegExp(tagName) + "\\s*>"); |
Copilot uses AI. Check for mistakes.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #32 +/- ##
==========================================
+ Coverage 94.91% 95.05% +0.13%
==========================================
Files 56 57 +1
Lines 1140 1172 +32
Branches 163 172 +9
==========================================
+ Hits 1082 1114 +32
Misses 58 58
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|