-
Notifications
You must be signed in to change notification settings - Fork 332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Table of Contents formatter can conflict with Prettier #1040
Comments
Have you tried to change |
This is a quite complex topic. Our TOC template is hard-coded
We code the template mainly for accuracy and reliability. Line 303 in cea94a7
Lines 279 to 283 in cea94a7
As for changing it, @yzhang-gh is hesitant, and I'm not motivated. The internal of the
|
workspace.onWillSaveTextDocument(onWillSave), |
I remember a maintainer of esbenp.prettier-vscode
opened an issue at VS Code to discuss the on-save behavior long time ago, but cannot find it now.
Ok, thanks for the detail. For now I will work around this by changing my indent width in Markdown files to 2 spaces, as that makes the ToC generator and Prettier agree. I agree that too much flexibility in the ToC format would be impractical. If I really want to get 4-space indentation working with this I'll start a discussion on the VSCode side about formatOnSave vs. onWillSaveTextDocument ordering (there might be other use cases for configuring the order of those events). |
This is somewhere between a bug and a feature request - I'll explain how to reproduce the issue before talking about possible solutions.
Problem
With certain settings (specifically, Prettier set to use 4-space indentation and toc.updateOnSave enabled), the Table of Contents formatter/updater and Prettier conflict and attempt to format the list in different ways.
How to reproduce
If I create the Markdown file below:
... and then save the file, Prettier will re-format the file as follows (which is my desired format):
... and the Table of Contents formatter will then immediately set it back to the original state.
Configuration
settings.json
:.prettierrc
:Proposal
I think in general, the Table of Contents updater is more concerned with the content (making the ToC correct) than the formatting, so it might make sense to move the update process before VSCode's formatOnSave runs, thereby allowing the user (through their choice of formatter) to control the format.
If this is not possible or practical, more configuration in the ToC formatting would allow me to generate a ToC that Prettier does not need to modify.
References
The text was updated successfully, but these errors were encountered: