fix(multiparser): respect 0-indent markdown-in-js#3676
fix(multiparser): respect 0-indent markdown-in-js#3676ikatyang merged 10 commits intoprettier:masterfrom
Conversation
| indent( | ||
| (hasIndent ? indent : identity)( | ||
| concat([ | ||
| softline, |
There was a problem hiding this comment.
I think you need to change this to literalline if no indent, see playground link
| text2 | ||
|
|
||
| text3 | ||
| \`; |
There was a problem hiding this comment.
I was just gonna comment this too :)
I think we need to split and join with literallines, like in
prettier/src/language-js/printer-estree.js
Lines 1917 to 1918 in dc4e449
There was a problem hiding this comment.
Do we have literal-line or literal-softline? The linebreaks in markdown are not static. 🤔
There was a problem hiding this comment.
I've made a zeroIndent primitive to print zero-indented docs. Do you want me to open a separate PR or push here?
There was a problem hiding this comment.
I'll open a PR refactoring the template literal printing
| concat([ | ||
| softline, | ||
| docUtils.stripTrailingHardline(escapeBackticks(doc)) | ||
| hasIndent ? softline : literalline, |
There was a problem hiding this comment.
I think all of these ternaries would be better replaced as an if (hasIndent)
|
|
||
| function literalify(doc) { | ||
| return align(-Infinity, doc); | ||
| } |
There was a problem hiding this comment.
Could you make this a “primitive” (like how conditionalGroup is actually a group) in the doc file?
There was a problem hiding this comment.
Not sure how should we name it, rootIndent?
|
I'd like to also fix that edge case in this PR, still WIP. |
|
Ready for review. |
* fix(multiparser): respect 0-indent markdown-in-js * fix: use literalline for 0-indent * test: add unexpected case * fix: 0-indent * test: add failing test * refactor: simplify * fix(doc): literallines respect `ind.root` * docs: update commands * fix: what a magic...
|
This is great, thank you very much! Would it be possible to get a point release cut with this commit? |
Fixes #3670
playground
Prettier pr-3676
Playground link
Input:
Output:
Fixes #3740
playground
Prettier pr-3676
Playground link
Input:
Output: