Sec-ant / prettier-plugin-embed

A configurable Prettier plugin to format embedded languages in JS/TS Files.
https://www.npmjs.com/package/prettier-plugin-embed/v/latest
MIT License
58 stars 2 forks source link

Fix unstable code block indentation in markdown #91

Closed kelvinsjk closed 7 months ago

kelvinsjk commented 7 months ago

I was running into the same indentation problems when formatting embedded markdown as seen in #45.

Trying the dedent workaround in #50 in the markdown embeddder fixed the issue for me

changeset-bot[bot] commented 7 months ago

🦋 Changeset detected

Latest commit: 9ee49924341f732be46028beb2f0a76c71057d2f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | --------------------- | ----- | | prettier-plugin-embed | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

codesandbox-ci[bot] commented 7 months ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Sec-ant commented 7 months ago

Hi, @kelvinsjk

Thanks for the fix. Would you mind sharing a markdown snippet where the unstable code block indentation happens?

kelvinsjk commented 7 months ago

The minimal working example I was able to create was the following, with "use-tabs": true". Without prettier-plugin-embed enabled the indentation was stable, but after enabling it prettier started adding spaces for indentation after the leading tab.

markdown-indentation

Sec-ant commented 7 months ago

@kelvinsjk Good catch, I guess that's why prettier has this piece of code of same logic in its built-in embedded markdown formatter: https://github.com/prettier/prettier/blob/1079517b32e5bb145afa7acba448af51f8a7b6e6/src/language-js/embed/markdown.js#L15-L19

Another quick question, do you have any particular reason to also set the last arg of simpleRehydrateDoc to true? I actually was thinking about removing this argument and setting it true for all function calls. But I wonder if there's another specific failing case of embedded markdown to let you make this change?

kelvinsjk commented 7 months ago

Ah, I was blindly mimicking the function call in the sql embedder.ts file 😅

Sec-ant commented 7 months ago

Ah, I was blindly mimicking the function call in the sql embedder.ts file 😅

No worries, I'll keep it. I'll add some comments and a changeset note before merging this. Thanks for your work!

@all-contributors please add @kelvinsjk for code.

allcontributors[bot] commented 7 months ago

@Sec-ant

I couldn't determine any contributions to add, did you specify any contributions? Please make sure to use valid contribution names.

I've put up a pull request to add @kelvinsjk! :tada:

kelvinsjk commented 7 months ago

@Sec-ant Thank you!

A big shout out and thanks for all the work on this project!