Skip to content

Fix markdown inserts unexpected newline in lists#16637

Merged
sosukesuzuki merged 9 commits intoprettier:mainfrom
byplayer:bugfix/markdown_unexpected_newline
May 31, 2025
Merged

Fix markdown inserts unexpected newline in lists#16637
sosukesuzuki merged 9 commits intoprettier:mainfrom
byplayer:bugfix/markdown_unexpected_newline

Conversation

@byplayer
Copy link
Contributor

@byplayer byplayer commented Sep 7, 2024

Description

I fix markdown inserts unexpected newline in lists.

This issue is reported the below link.
#8004

Fixes #8004

Checklist

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory)(not change).
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md(not change).
  • I’ve read the contributing guidelines.

Try the playground for this PR

I fix markdown inserts unexpected newline in lists.

This issue is reported the below link.
prettier#8004
There is lint error for  changelog_unreleased/markdown/16637.md,
threfore I fix it with 'prettier --write' command.
I remove 'markdown:' from change log title.
@barcell1
Copy link

  • 1 on this

Copy link
Contributor

@jacksteamdev jacksteamdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, one minor observation.

Comment on lines +678 to +680
parent.type === "listItem" &&
(node.type === "list" ||
(node.type !== "list" && !isLooseListItem(parent, options)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    parent.type === "listItem" &&
      (node.type === "list" ||
        (node.type !== "list" && // is always true
           !isLooseListItem(parent, options)));

The condition can be simplified since the node.type !== "list" check is redundant - if the first part of the OR (node.type === "list") is false, then node.type !== "list" will always be true. Due to short-circuit evaluation, we can remove this redundant check while maintaining the same logic.

Suggested change
parent.type === "listItem" &&
(node.type === "list" ||
(node.type !== "list" && !isLooseListItem(parent, options)));
parent.type === "listItem" &&
(node.type === "list" || !isLooseListItem(parent, options));

I hope this PR can be reviewed and merged soon! 🤞

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fix it.
Thank you.

The suggested condition of the bellow URL is better than current one.
I fix it.

prettier#16637 (comment)
@jacksteamdev
Copy link
Contributor

@thorn0 Thanks for helping maintain this project! I noticed that you triaged #8004, is there any possibility this high-quality PR could get reviewed by a Prettier maintainer?

@fisker fisker changed the title markdown: fix markdown inserts unexpected newline in lists Fix markdown inserts unexpected newline in lists May 21, 2025
@netlify
Copy link

netlify bot commented May 21, 2025

Deploy Preview for prettier ready!

Name Link
🔨 Latest commit b7fd2dc
🔍 Latest deploy log https://app.netlify.com/projects/prettier/deploys/683b3c13c942b30008d5a1f6
😎 Deploy Preview https://deploy-preview-16637--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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented May 21, 2025

Open in StackBlitz

yarn add https://pkg.pr.new/prettier/prettier/@prettier/[email protected]
yarn add https://pkg.pr.new/prettier/prettier/@prettier/[email protected]
yarn add https://pkg.pr.new/prettier/[email protected]

commit: b7fd2dc

@fisker fisker added this to the 3.6 milestone May 21, 2025
@sosukesuzuki sosukesuzuki merged commit 4bb0568 into prettier:main May 31, 2025
32 of 33 checks passed
@mikaello
Copy link

It may be a regression when combined with fenced code blocks and nested lists:

Before this PR:

1. Some text, and code block below

   ```yaml
   ---
   foo: bar
   ```

   1. Another
   2. List

After this PR, notice removed newline after code block:

1. Some text, and code block below

   ```yaml
   ---
   foo: bar
   ```
   1. Another
   2. List

This is at least in conflict with MD031 for those using markdownlint.

@fisker
Copy link
Member

fisker commented Jun 23, 2025

Can you open a new issue?

wincent added a commit to wincent/command-t that referenced this pull request Jun 23, 2025
Because a Prettier update (v3.6.0) came out 7 hours ago, containing
changes that alter the way Markdown is formatted:

- https://prettier.io/blog/2025/06/23/3.6.0#markdown

Notably:

- prettier/prettier#16637

Locally, I'm running prettier with `npx`, so I get those changes
immediately.

In CI, runs are failing:

```
2025-06-23T09:16:20.1272956Z ##[group]Run actionsx/prettier@3d9f7c3
2025-06-23T09:16:20.1273344Z with:
2025-06-23T09:16:20.1273543Z   args: --list-different "**/*.md"
2025-06-23T09:16:20.1274004Z ##[endgroup]
2025-06-23T09:16:20.5373798Z lua/wincent/commandt/README.md
```

- https://github.com/wincent/command-t/actions/runs/15820236003

Given that `actionsx/prettier` was last updated two years ago:

- https://github.com/actionsx/prettier/releases/tag/v3

And there has been a request to bump Prettier to v3.0.3 that has gone
ignored since October 2023:

- actionsx/prettier#117

I am not optimistic that this will be resolved quickly, although I
recognize that I might be pleasantly surprised.

Whatever. Enough idle speculation. I'm using dprint quite happily in
other projects, so let's use it here too.
@mikaello
Copy link

Can you open a new issue?

Sure: #17652

dvanoni added a commit to dvanoni/notero that referenced this pull request Jul 5, 2025
dvanoni added a commit to dvanoni/notero that referenced this pull request Jul 5, 2025
* build(deps-dev): Bump the dev-dependencies group with 11 updates

---
updated-dependencies:
- dependency-name: "@eslint/js"
  dependency-version: 9.30.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: "@vitest/eslint-plugin"
  dependency-version: 1.3.4
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: concurrently
  dependency-version: 9.2.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: eslint
  dependency-version: 9.30.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: eslint-import-resolver-typescript
  dependency-version: 4.4.4
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: dev-dependencies
- dependency-name: eslint-plugin-import
  dependency-version: 2.32.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: globals
  dependency-version: 16.3.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: prettier
  dependency-version: 3.6.2
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: tsx
  dependency-version: 4.20.3
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: typescript-eslint
  dependency-version: 8.35.1
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: vitest
  dependency-version: 3.2.4
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore: Fix new Prettier issue

Change introduced in prettier/prettier#16637

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: David Hoff-Vanoni <[email protected]>
pokusew added a commit to pokusew/lionkey that referenced this pull request Sep 6, 2025
Fix formatting in the docs/content/development/getting-started.md (caused by the Prettier upgrade from 3.5.x to 3.6.x, Fix markdown inserts unexpected newline in lists prettier/prettier#16637).
dataymeric pushed a commit to dataymeric/anytero that referenced this pull request Feb 5, 2026
…noni#699)

* build(deps-dev): Bump the dev-dependencies group with 11 updates

---
updated-dependencies:
- dependency-name: "@eslint/js"
  dependency-version: 9.30.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: "@vitest/eslint-plugin"
  dependency-version: 1.3.4
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: concurrently
  dependency-version: 9.2.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: eslint
  dependency-version: 9.30.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: eslint-import-resolver-typescript
  dependency-version: 4.4.4
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: dev-dependencies
- dependency-name: eslint-plugin-import
  dependency-version: 2.32.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: globals
  dependency-version: 16.3.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: prettier
  dependency-version: 3.6.2
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: tsx
  dependency-version: 4.20.3
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: typescript-eslint
  dependency-version: 8.35.1
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: vitest
  dependency-version: 3.2.4
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore: Fix new Prettier issue

Change introduced in prettier/prettier#16637

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: David Hoff-Vanoni <[email protected]>
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.

Markdown inserts unexpected newline in lists

6 participants