Skip to content

[Micromark] resolve unnecessary newline before inline html tag#18501

Merged
fisker merged 15 commits intoprettier:remark-11-markdownfrom
seiyab:remark-11-markdown-linebreak-before-html
Dec 21, 2025
Merged

[Micromark] resolve unnecessary newline before inline html tag#18501
fisker merged 15 commits intoprettier:remark-11-markdownfrom
seiyab:remark-11-markdown-linebreak-before-html

Conversation

@seiyab
Copy link
Copy Markdown
Collaborator

@seiyab seiyab commented Dec 19, 2025

Description

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).
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Dec 19, 2025

Open in StackBlitz

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

commit: 44f917c

@netlify
Copy link
Copy Markdown

netlify Bot commented Dec 19, 2025

Deploy Preview for prettier ready!

Name Link
🔨 Latest commit 44f917c
🔍 Latest deploy log https://app.netlify.com/projects/prettier/deploys/6947373ac9f91d0007e069ff
😎 Deploy Preview https://deploy-preview-18501--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.

Comment thread tests/format/markdown/link/__snapshots__/format.test.js.snap Outdated
Comment on lines +228 to +230
text
<em>text</em>
text
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Technically saying, it's better to be formatted as following:

text <em>text</em> text

But it's hard to be consistent with html-flow hack.

Comment thread src/language-markdown/print/children.js Outdated
) {
const tagName = node.value.match(/^<\/?([a-z0-9-]+)/iu)?.[1].toLowerCase();
const isInlineTag =
tagName && ![...htmlBlockNames, ...htmlRawNames].includes(tagName);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What will be broken if we don't check tagName?

Copy link
Copy Markdown
Collaborator Author

@seiyab seiyab Dec 20, 2025

Choose a reason for hiding this comment

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

I guess HTML block tags (like tables) will get able to follow paragraph without a blank line. But I haven't experimented. I'll get it sure later.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

9b16f65 (currently it's reverted.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's expected?

44f917c

Otherwise, we add blank line to both

Foo
<div>
bar
</div>

and

Foo

<div>
bar
</div>

Copy link
Copy Markdown
Collaborator Author

@seiyab seiyab Dec 21, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Make sense.

But this case

<table><tr><td>
<pre>
**Hello**,

_world_.
</pre>
</td></tr></table>

Should we consider inserting a new line after </pre> a bug?

I think it's fine to simply respect the existing line break?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Should we consider inserting a new line after </pre> a bug?
I think it's fine to simply respect the existing line break?

Ah I understand. </pre> problem is more serious so respecting the input makes sense.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Or an intermediate idea: only check tagName for opening tag

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's keep it this way for now. We can improve if necessary.

@fisker
Copy link
Copy Markdown
Member

fisker commented Dec 20, 2025

Is this expected?

Prettier pr-18501
Playground link

--parser markdown

Input:

text 
<em>text</em>

text
 <em>text</em>

Output:

text
<em>text</em>

text

 <em>text</em>

@seiyab
Copy link
Copy Markdown
Collaborator Author

seiyab commented Dec 20, 2025

Unintentional. I missed the case...

@seiyab
Copy link
Copy Markdown
Collaborator Author

seiyab commented Dec 20, 2025

I found the following case reports AST change. But I leave it because it's neither caused nor tackled by this PR but caused by html-flow hack.

Prettier pr-18501
Playground link

--parser markdown

Input:

text
    <em>text</em>

Output:

text
<em>text</em>

@fisker fisker merged commit de7bad0 into prettier:remark-11-markdown Dec 21, 2025
47 of 48 checks passed
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.

2 participants