Skip to content
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

Muliple NBSPs in code secontion in markdown string are collapsed #13485

Closed
nschonni opened this issue Sep 16, 2022 · 8 comments · Fixed by #13590
Closed

Muliple NBSPs in code secontion in markdown string are collapsed #13485

nschonni opened this issue Sep 16, 2022 · 8 comments · Fixed by #13590
Assignees
Labels
lang:markdown Issues affecting Markdown type:bug Issues identifying ugly output, or a defect in the program

Comments

@nschonni
Copy link

Prettier 2.7.1
Playground link

--parser markdown

Input:

For example, the string `"a   b"` (three spaces between _a_ and _b_) separates _a_ and _b_ more than `"a b"` (one space between _a_ and _b_).

Output:

For example, the string `"a b"` (three spaces between _a_ and _b_) separates _a_ and _b_ more than `"a b"` (one space between _a_ and _b_).

Expected behavior:
I replaced regular spaces with Non-breaking spaces to prevent the collapsing of the spaces that occurs with regular spaces, but if you look at "a   b" it shouldn't be collapsed as it renders correctly.

@fisker fisker added type:bug Issues identifying ugly output, or a defect in the program lang:markdown Issues affecting Markdown labels Sep 16, 2022
@fisker
Copy link
Member

fisker commented Sep 16, 2022

function transformInlineCode(ast) {
return mapAst(ast, (node) => {
if (node.type !== "inlineCode") {
return node;
}
return { ...node, value: node.value.replace(/\s+/g, " ") };
});
}

@kachkaev
Copy link
Member

This replace logic dates back to #2943 (line). I agree that it’s best not to touch the contents of ``, just sharing the origin for historical context.

@nschonni
Copy link
Author

nschonni commented Sep 16, 2022

Yeah, and original the doc had 3 regular spaces "a b" that does collapse down, so Prettier is doing the right thing in that case. This appears to just be an odd edge case, and could always be prettier-ignore'd

@thorn0
Copy link
Member

thorn0 commented Sep 22, 2022

original the doc had 3 regular spaces "a b" that does collapse down

It's collapsed by the browser. In the HTML markup, it's still 3 spaces. I'd vote for removing this replace unless there really is a case when it's doing the right thing.

Actually, according to the CommonMark spec, the only correct replacement would be to replace line endings with spaces.

@mrienstra
Copy link

Just ran into this while editing a .md file, this regex search:
^( )+(?![ \n]) (two spaces between first pair of parentheses)
... became:
^( )+(?![ \n]) (one space between first pair of parentheses)

Another vote for dropping this behavior.

@kachkaev
Copy link
Member

kachkaev commented Oct 5, 2022

You are right @thorn0: interior spaces should not be collapsed, according to CommonMark.

`foo   bar 
baz`

<p><code>foo   bar  baz</code></p>

I can create a PR with the fix (hopefully by the end of this week).

@kachkaev
Copy link
Member

kachkaev commented Oct 8, 2022

Potential fix: #13590

@thorn0
Copy link
Member

thorn0 commented Oct 14, 2022

Fixed by #13590 in next

@thorn0 thorn0 closed this as completed Oct 14, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang:markdown Issues affecting Markdown type:bug Issues identifying ugly output, or a defect in the program
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants