prettier
prettier copied to clipboard
Muliple NBSPs in code secontion in markdown string are collapsed
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.
https://github.com/prettier/prettier/blob/cd3e530c2e51fb8296c0fb7738a9afdd3a3a4410/src/language-markdown/print-preprocess.js#L31-L39
This replace logic dates back to https://github.com/prettier/prettier/pull/2943 (line). I agree that it’s best not to touch the contents of ``, just sharing the origin for historical context.
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
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.
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.
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).
Potential fix: https://github.com/prettier/prettier/pull/13590
Fixed by #13590 in next