10BC0 Fix endless indentation of multi-line HTML comments in markdown lists… by Adarsh-code169 · Pull Request #18420 · prettier/prettier · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@Adarsh-code169
Copy link

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

  • I've added tests to confirm my change works.
  • I've added my changes to 18066.md.
  • I've read the contributing guidelines.

Copilot AI review requested due to automatic review settings December 3, 2025 16:23
@Adarsh-code169
Copy link
Author

Hii @fisker, can you please have a look at this, if any more changes required please let me know.

@netlify
Copy link
netlify bot commented Dec 3, 2025

Deploy Preview for prettier ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 863eb8d
🔍 Latest deploy log https://app.netlify.com/projects/prettier/deploys/693063f6951cc10008ce489b
😎 Deploy Preview https://deploy-preview-18420--prettier.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copilot AI left a 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
-->
Copy link
Copilot AI Dec 3, 2025

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.

Suggested change
-->
-->

Copilot uses AI. Check for mistakes.
@pkg-pr-new
Copy link
pkg-pr-new bot commented Dec 6, 2025

Open in StackBlitz

yarn add https://pkg.pr.new/prettier/prettier/@prettier/plugin-hermes@18420.tgz
yarn add https://pkg.pr.new/prettier/prettier/@prettier/plugin-oxc@18420.tgz
yarn add https://pkg.pr.new/prettier/prettier@18420.tgz

commit: 863eb8d

// 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

This regular expression does not match comments containing newlines.
@fisker fisker self-requested a review December 30, 2025 04:39
@fisker
Copy link
Member
fisker commented Dec 30, 2025

Tests are failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTML comments in markdown get endlessly indented

2 participants

0