Closed junaga closed 2 months ago
Hi! Thank you for submitting this issue. I am happy to review a PR if you want to take a shot at this. My preference would be separate PRs, one each for Markdown support and Astro support. Here's a quick sketch of what I think needs to happen to add support for additional languages:
The languages
export needs additional entries for each language you want to add support for (Markdown and Astro).
Each of those need a corresponding entry in the parsers
export. As you can see, this plugin is currently reusing the built-in HTML parser from Prettier. We should continue to reuse parsers for each language being supported (I don't want to be in the business of implementing our own parsers). This introduces a couple of challenges for Astro in particular, since it's not natively supported by Prettier and will require a peer dependency on the Astro plugin:
peerDependenciesMeta
to mark it as optional.The hardest part will be the printers
. Each of those languages will probably need their own implementation (perhaps not Markdown, I'm not totally sure how Prettier handles embedded language formatting — something to look into!).
Please refer to the Prettier documentation for help!
I am interested in supporting this, and so eventually I could also add support myself. This is a project I work on in my limited free time, so I won't estimate any timeline. Feel free to use this issue or PRs if you have further questions.
Adding another comment here to clarify my response to this part of your request:
Maybe it's possible to support all languages with a simple config change?
This may be possible for embedded languages, such as your first example of HTML code blocks within Markdown. I am not sure offhand whether this plugin needs to change in order to support that. You can look here for clues: https://prettier.io/docs/en/plugins.html#optional-embed
I don't think this is possible in general for arbitrary languages. The parser is language-specific, the printer is language-specific, and even the void syntax rules are language-specific (this plugin would generate invalid JSX, for example). So in order to support Astro, we need specific language support, not a config change to "support all languages".
As requests for more language support have been coming in, I've decided for now that this plugin will be limited to HTML only. I will keep thinking about how to support additional languages and might expand this someday. No promises 😄
If you're willing to hack around and find out, you might have some success following the steps described in #19 .
We have
./hello.md
with HTML codeblocks.Input
Output
Expected output
Generic usage
Maybe it's possible to support all languages with a simple config change? My frontend framework astro.build
.astro
single-file-components markup is also ignored bynpm:@awmottaz/prettier-plugin-void-html
.If i can help, help me help you.