9

I was writing a question in which I used a list to indicate the steps my code takes, immediately followed by the code. Like this:

  • Foo the bar
  • bar the foo

    Foo = bar / 12 bar = 6 / Foo

Albeit being properly indented with four spaces and two newlines inbetween the list and the code this doesn't work. As a work around I can add a <br> tag in between like this:

  • Foo the bar
  • bar the foo


Foo = bar / 12
bar = 6 / Foo

But this requires three blank lines between the list and the codeblock. Can we please make markdown respect two new lines as being the end of the list?

ps. I know there are a lot of bug reports about this, but this is a feature-request.

2
  • Use the best text editor in the world: :se ts=4, Enter, V3j> Aug 7, 2019 at 8:41
  • The posted example uses a triple-newline, which actually makes more sense to end a list (double-newline and indent looks more like a new paragraph within a list item, which is also how it's currently parsed).
    – outis
    Jan 3, 2021 at 4:30

2 Answers 2

8

Treating a double newline specially is not how Markdown works.

To terminate a list or other indented Markdown content, you can use an empty comment instead. For example:

 -  foo
 -  bar

<!-- -->

    code { block }

which renders as:

  • foo
  • bar
code { block }
1
  • 1
    I know that it's not how it works, hence the [feature-request] as IMO it should work like that.
    – Luuklag
    Aug 7, 2019 at 8:09
5

Use fences rather than indenting code blocks:

- Foo the bar
- bar the foo

```
Foo = bar / 12 bar = 6 / Foo
```
  • Foo the bar
  • bar the foo

Foo = bar / 12 bar = 6 / Foo

2
  • That certainly can be an option, but if I copy already indented code it becomes a horrible mess of double indention.
    – Luuklag
    Aug 7, 2019 at 7:48
  • 3
    The {} editor button (or Ctrl+K) can also un-indent selected blocks if each line is already consistently indented with 4 spaces. @Luuklag Aug 7, 2019 at 12:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .