Prettier insert blank line after list item in Markdown file

38 Views Asked by At

Currently the Prettier will format a Markdown file like this:

1. Example
```bash
$ cat dummy.txt
```

and insert a blank line after the list item like this:

1. Example

```bash
$ cat dummy.txt
```

I want the code block to align to the indentation same as the list item. Do you have any idea of how to configure Prettier NOT to insert a blank line after the list item?

1

There are 1 best solutions below

0
Timothy G. On BEST ANSWER

If you are on version 1.12.0 and up, you can use a range ignore:

This type of ignore is only allowed to be used in top-level and aimed to disable formatting for auto-generated content, e.g. all-contributors, markdown-toc, etc.

While its meant for protecting auto generated content from being formatted, (like a markdown table of contents), it works for this as well:

<!-- prettier-ignore-start -->
1. Example
```bash
$ cat dummy.txt
```
<!-- prettier-ignore-end -->

In my tests, this seems to work. You are suppose to be able to use a one line disable comment as specified here, but my tests indicate that doesn't work for this scenario. I am guessing something with the numbered list being adjacent to the code block causes it not to work.