5

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)?

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

Wow! I missed that. Thank you for this :).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.