Markdown: Preserve multiple spaces in inline code#13590
Markdown: Preserve multiple spaces in inline code#13590thorn0 merged 22 commits intoprettier:nextfrom kachkaev:inline-code-spacing
Conversation
| @@ -1,5 +1,162 @@ | |||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | |||
|
|
|||
| exports[`commonmark-0.30-example-328.md - {"proseWrap":"always"} format 1`] = ` | |||
|
Hmmm Example 331 fails second pass: [space][space]``[space][space]
↓
[space]``[space]
↓
``I don’t understand this because Example 331 after formatting is Example 330 (which works). Going to take a break now. Any thoughts? UPD: I reverted changes in |
|
example 331 & example 330 has different value, prettier/src/language-markdown/clean.js Line 36 in 62d95b3 |
|
Pressed the wrong button 😅 I included #11373. I still don’t fully understand the relationship between |
| return { | ||
| ...node, | ||
| value: | ||
| value.startsWith(" ") && value.endsWith(" ") && value.trim().length > 0 |
There was a problem hiding this comment.
Something doesn't look right here. Is this part really needed? Isn't this check and processing done by the parser already?
There was a problem hiding this comment.
Okay, I see why you did this. But this should be done in print, not in preprocess.
There was a problem hiding this comment.
I see, thanks for the fix! 🙌
Do you know why we still need newObj.value = ast.value.replace(/\n/g, " "); in clean.js? This transform is applied regardless of proseWrap. I vaguely remember trying to remove it but tests failed.
There was a problem hiding this comment.
Those tests are run only with proseWrap: "always", that's why it works. Need to think what to do.
There was a problem hiding this comment.
No, I was wrong. It's some other tests that fail if I add
run_spec(import.meta, ["markdown"], { proseWrap: "preserve" });
run_spec(import.meta, ["markdown"], { proseWrap: "never" });to jsfmt.spec.js, not related to code spans.
As for clean.js, see how the clean function (AKA massageAST) is used:
Lines 137 to 169 in 955553b
It's applied to both the original AST and to the AST built from Prettier's output, and then the ASTs are checked for deep equality. So it makes sense that this replacement is needed. After it, no matter what proseWrap is, the values in the two ASTs are equal.
Co-authored-by: Alexander Kachkaev <[email protected]>
fisker
left a comment
There was a problem hiding this comment.
Good job! Just a few unimportant questions.
| } | ||
|
|
||
| return { ...node, value: node.value.replace(/\s+/g, " ") }; | ||
| return { ...node, value: node.value.replace(/\n/g, " ") }; |
There was a problem hiding this comment.
Maybe we can move this to print? So we can reduce one mapAst call. Can be separate PR.
| =====================================output===================================== | ||
| markdown\` | ||
| const cssString = css\\\` background-color: \\$\\{color('base')\\}\\\`; | ||
| const cssString = css\\\` background-color: \\$\\{color('base')\\}\\\`; |
There was a problem hiding this comment.
Shouldn't this call markdown -> js -> css and remove the leading space? Because it's not valid css?
There was a problem hiding this comment.
This is a crazy test. const cssString = ... is Markdown here, not JS. The Markdown-in-JS embedder also includes logic for ignoring indentation (no idea what's the story behind that). That's why the output is like that.
There was a problem hiding this comment.
Ah, you explained before... forgot. Sorry.

Description
Fixes #13485
Checklist
(If changing the API or CLI) I’ve documented the changes I’ve made (in thedocs/directory).changelog_unreleased/*/XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md.✨Try the playground for this PR✨