-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Fix endless indentation of multi-line HTML comments in markdown lists… #18420
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
base: main
Are you sure you want to change the base?
Conversation
|
Hii @fisker, can you please have a look at this, if any more changes required please let me know. |
✅ Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
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 fixes an issue where multi-line HTML comments inside Markdown list items were getting progressively more indented with each format operation. The fix changes the regex pattern used to identify single-line HTML comments from /^<!--.*-->$/su to /^<!--.*-->$/u (removing the s flag), ensuring multi-line comments are treated differently and preserve their original formatting.
Key changes:
- Modified the HTML comment detection regex to exclude multi-line comments
- Added comprehensive test cases covering various list types and indentation settings
- Documented the fix in the changelog
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/language-markdown/printer-markdown.js | Changed regex flag from su to u and renamed variable for clarity; added explanatory comments |
| tests/format/markdown/list/issue-18066.md | Added test cases for multi-line HTML comments in unordered, ordered, and nested lists |
| tests/format/markdown/list/snapshots/format.test.js.snap | Added test snapshots with various tabWidth configurations |
| changelog_unreleased/markdown/18066.md | Documented the fix with before/after examples |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - [ ] Foo | ||
| - [ ] Bar <!-- | ||
| Something else | ||
| --> |
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 test snapshot shows inconsistent indentation for the multi-line comment. The comment content has 2 more spaces of indentation than the closing tag -->.
For example, in lines 2617-2619:
- "Something else" has 16 spaces of indentation
- "-->" has only 14 spaces of indentation
This inconsistency appears in all test cases and should be addressed.
| --> | |
| --> |
commit: |
| // Only match single-line HTML comments (no `s` flag). | ||
| // Multi-line comments should use `markAsRoot(literalline)` like other HTML | ||
| // to preserve original formatting and avoid double-indentation in lists. | ||
| const isSingleLineHtmlComment = /^<!--.*-->$/u.test(value); |
Check failure
Code scanning / CodeQL
Bad HTML filtering regexp High
|
Tests are failing. |
Fix endless indentation of multi-line HTML comments in markdown lists (#18066)
Description
Multi-line HTML comments in list items were getting additional indentation on each format. Fixed by changing the regex from
/^<!--.*-->$/su to /^<!--.*-->$/u(removed s flag) so multi-line comments use markAsRoot(literalline) like other HTML, preserving original formatting.Fixes #18066
Checklist