Search code examples
javamarkdownprettier

Prettier format java in markdown code block


```java
class AppClass {
public static void main(String[] args) {
NewClass newClass = new NewClass();
// Perform operations on newClass
}
}
```

How do you format java code within markdown?

Script: prettier --write **/*.{md}

It works pretty well for web languages (js,jsx, html....) in markdown.

I tried installing prettier-plugin-java also doesn't help inside markdown.


Solution

  • prettier --write ./java.md --plugin="./node_modules/prettier-plugin-java"
    

    This amazingly works, may work with other languages too within markdown, Here is the list of plugins https://prettier.io/docs/en/plugins.html have only tried java community plugin.

    Do try other language formatting support in markdown if interested.