Format code blocks
Proposal
A command like Markdown All in One: Format code blocks would find code blocks in the current document and format them.
Note about Prettier
I personally use Prettier and one would think that with it, the problem is solved and this feature is not necessary. However, Prettier does some controversial things when formatting .md file as a whole, for example, it messes up lists, see https://github.com/prettier/prettier/issues/5019.
So I'm looking for ways to format code blocks only, without affecting the rest of the Markdown.
Plus, of course, not everyone has Prettier installed to VSCode and for them, I think that this feature request makes sense as well – VSCode's standard formatting would be applied instead.
Thanks. An interesting feature request.
To do this we need to make use of language services from other extensions. AFAIK, VS Code can format JS inside HTML.
I have been looking for a (somehow) related feature https://github.com/microsoft/vscode/issues/49805 a long time ago, but I'm not sure whether it becomes easier now.
If I was doing this manually, I'd probably copy each snippet to a new file with the correct extension and then run "Format document" on it. For example, a ```js code block would become a temporary .js file.
Could the extension do something like this, just in-memory / without creating the files?
I cannot recall precisely, but LaTeX Workshop has been using this trick to implement some features.
It seems that's exactly what https://github.com/ame-neko/md-code-formatter does. It would be nice however to include it on the default format action instead on a custom context menu one.