Skip to content

Comments

feat(markdown): respect tabWidth for list items#3990

Merged
azz merged 2 commits intoprettier:masterfrom
ikatyang:feat/markdown-list-item-respect-tab-width
Feb 24, 2018
Merged

feat(markdown): respect tabWidth for list items#3990
azz merged 2 commits intoprettier:masterfrom
ikatyang:feat/markdown-list-item-respect-tab-width

Conversation

@ikatyang
Copy link
Member

@ikatyang ikatyang commented Feb 17, 2018

Context: #3459 (comment)

This PR improves the indenting experience in VSCode (probably other editors as well) and also fixes #3459, I'm not sure if this is the proper fix but at least we can see the result and decide if it should be closed/merged.

  • align list prefix with tabWidth
  • it only affect ordered lists if tabWidth: 2, otherwise all lists.

vscode indent demo

cc @kachkaev


Prettier pr-3990
Playground link

--parser markdown

Input:

1. Change to your home directory:

        cd

2. List the contents:

        ls -l

Output:

1.  Change to your home directory:

        cd

2.  List the contents:

        ls -l

@kachkaev
Copy link
Member

kachkaev commented Feb 17, 2018

Thank you for this PR @ikatyang! I pasted a part of the document I had problems with into your playground and the output was much better! No three spaces any more! This means that the preview won't be broken on GitHub/GitHub and that my text editor won't go crazy when I select + tab!

One last thing I'm not sure how to configure is using --tab-width=4 for markdowns and --tab-width=2 for js/ts stuff in a single project. But that's minor compared to the problem with three spaces in ordered lists!

@ikatyang
Copy link
Member Author

One last thing I'm not sure how to configure is using --tab-width=4 for markdowns and --tab-width=2 for js/ts stuff. But that's minor compared to the problem with three spaces in ordered lists!

See https://prettier.io/docs/en/configuration.html#configuration-overrides, or if you're talking about js/ts code block in markdown, it's currently not supported.

@kachkaev
Copy link
Member

That's exactly what I needed, thanks! ❤️

@kachkaev
Copy link
Member

kachkaev commented Feb 17, 2018

Really looking forward to go for this prettier.config.js in my future TypeScript projects!

module.exports = {
  // tabWidth: 2, // default
  overrides: [
    {
      files: "*.md",
      options: {
        tabWidth: 4,
      },
    },
  ],
};

As mentioned in #3459 (comment), a huge bonus of having tabWidth: 4 in markdown is that unordered lists have the same indent as the ordered ones. This makes it possible to change the type of a list without getting a huge git diff!

@kachkaev
Copy link
Member

@ikatyang who would be the best people to review this? Shall we ping them?

@ikatyang
Copy link
Member Author

cc @azz

@j-f1 j-f1 requested a review from azz February 22, 2018 17:27
Copy link
Member

@azz azz left a comment

Choose a reason for hiding this comment

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

LGTM. Sorry for the delay in reviewing.

@azz azz merged commit c1107a8 into prettier:master Feb 24, 2018
@ikatyang ikatyang deleted the feat/markdown-list-item-respect-tab-width branch February 24, 2018 08:13
@kachkaev
Copy link
Member

kachkaev commented Feb 24, 2018

Perfect, thank you all! Are you planning to fit this change into the upcoming 1.11? That would be just awesome, I can't wait 🙌 😃

@azz
Copy link
Member

azz commented Feb 24, 2018

Yes it will be in 1.11.

@azz azz added this to the 1.11 milestone Feb 24, 2018
@suchipi
Copy link
Member

suchipi commented Feb 24, 2018

@azz could you add this to my changelog PR?

@kachkaev
Copy link
Member

kachkaev commented Feb 27, 2018

Just upgraded to 1.11 and all worked! Thank you so much @ikatyang for responding to my concerns in #3459 (comment) so quickly and to the rest of the team for such a great work on the new release! To be honest, when I saw three spaces in my markdown after prettier went through it, I thought I'd need to enter a long and hard debate because 2/4 spaces would be a breaking change. However, the ease and the speed with which the change went through ended up beyond my even most optimistic expectations!

You all rock! 🗿 😄

@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.

Markdown: Preserve code blocks within list items

4 participants