Skip to content

fix(multiparser): respect 0-indent markdown-in-js#3676

Merged
ikatyang merged 10 commits intoprettier:masterfrom
ikatyang:fix/markdown-in-js-0-indent
Jan 17, 2018
Merged

fix(multiparser): respect 0-indent markdown-in-js#3676
ikatyang merged 10 commits intoprettier:masterfrom
ikatyang:fix/markdown-in-js-0-indent

Conversation

@ikatyang
Copy link
Copy Markdown
Member

@ikatyang ikatyang commented Jan 8, 2018

Fixes #3670

playground

Prettier pr-3676
Playground link

Input:

md`
This line shouldn't be indented at all in the resulting output, but it is.
`

md(`
Prettier does the right thing on this line and preserves the indentation level.
`)

Output:

md`
This line shouldn't be indented at all in the resulting output, but it is.
`;

md(`
Prettier does the right thing on this line and preserves the indentation level.
`);

Fixes #3740

playground

Prettier pr-3676
Playground link

--parser markdown

Input:

- 1
  - 2
    - 3
      ```js
      something`
      asd

      asd

      asd
      `
      ```

Output:

* 1

  * 2

    * 3

      ```js
      something`
      asd
      
      asd
      
      asd
      `;
      ```

Comment thread src/language-js/embed.js Outdated
indent(
(hasIndent ? indent : identity)(
concat([
softline,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think you need to change this to literalline if no indent, see playground link

text2

text3
\`;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I was just gonna comment this too :)

I think we need to split and join with literallines, like in

case "TemplateElement":
return join(literalline, n.value.raw.split(/\r?\n/g));

Copy link
Copy Markdown
Member Author

@ikatyang ikatyang Jan 8, 2018

Choose a reason for hiding this comment

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

Do we have literal-line or literal-softline? The linebreaks in markdown are not static. 🤔

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I've made a zeroIndent primitive to print zero-indented docs. Do you want me to open a separate PR or push here?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'll open a PR refactoring the template literal printing

@ikatyang ikatyang added the status:wip Pull requests that are a work in progress and should not be merged label Jan 9, 2018
Comment thread src/language-js/embed.js Outdated
concat([
softline,
docUtils.stripTrailingHardline(escapeBackticks(doc))
hasIndent ? softline : literalline,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think all of these ternaries would be better replaced as an if (hasIndent)

Comment thread src/language-js/embed.js Outdated

function literalify(doc) {
return align(-Infinity, doc);
}
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.

Could you make this a “primitive” (like how conditionalGroup is actually a group) in the doc file?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not sure how should we name it, rootIndent?

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.

Sure. Or maybe dedentToRoot?

duailibe
duailibe previously approved these changes Jan 10, 2018
@ikatyang
Copy link
Copy Markdown
Member Author

I'd like to also fix that edge case in this PR, still WIP.

@ikatyang ikatyang removed the status:wip Pull requests that are a work in progress and should not be merged label Jan 13, 2018
@ikatyang
Copy link
Copy Markdown
Member Author

Ready for review.

Copy link
Copy Markdown
Collaborator

@duailibe duailibe left a comment

Choose a reason for hiding this comment

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

Nice job!

@ikatyang ikatyang merged commit de6bc44 into prettier:master Jan 17, 2018
@ikatyang ikatyang deleted the fix/markdown-in-js-0-indent branch January 17, 2018 04:52
robert-j-webb pushed a commit to robert-j-webb/prettier that referenced this pull request Jan 18, 2018
* 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...
@chrislloyd
Copy link
Copy Markdown

This is great, thank you very much! Would it be possible to get a point release cut with this commit?

@christianvuerings
Copy link
Copy Markdown

@duailibe @azz Do you know when we might get a next release which includes this fix?

@btraut
Copy link
Copy Markdown

btraut commented Feb 9, 2018

@duailibe @azz @ikatyang Checking up on this again. Is there any chance we could get a fresh point release published? Thanks!

@lydell
Copy link
Copy Markdown
Member

lydell commented Feb 9, 2018

@btraut 1.11 has started to form: #3931

@lock lock Bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 18, 2019
@lock lock Bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants