Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ - Formatting Java code in Markdown

When a Java code snippet is added to Markdown, the indentation is not formatted correctly. For example, having the following code snippet:

```java
if(x==0){
    if(flag){
        return true;
    }else{
        return false;
    }
}
```

will render the following once the auto-formatter is complete

```java
if(x==0){
        if(flag){
        return true;
        }else{
        return false;
        }
        }
```

I am certain that this is a part of the language of Java's settings because replacing ```java with just ``` will keep the format as usual.

How can I ensure to have IntelliJ format Java code snippets appropriately in Markdown (or ignore autoformat and I would format them myself)?

like image 840
M. Al Jumaily Avatar asked Sep 11 '25 23:09

M. Al Jumaily


1 Answers

This is caused by the fact that partial code snippets are not supported yet. See https://youtrack.jetbrains.com/issue/IDEA-267081

As a workaround, uncheck the Preferences | Languages & Frameworks | Markdown | Inject languages in code fences option: enter image description here

like image 128
Konstantin Annikov Avatar answered Sep 14 '25 13:09

Konstantin Annikov