Search code examples
markdownatom-editorgithub-flavored-markdown

Markdown: Confusion about empty lines in editor


I'm a bit confused about how a markdown file is rendered (tried different editors, so I suppose the reason lies within MD / GFM itself). So, if I write a list followed by a code block, the code is not rendered as such, but rather as a part of the last list item (at least it seems like that), even if I seperate the list and the code block with a blank line:

  • Item 1
  • Item 2
  • Item 3

    Some code line 1 Some code line 2 Some code line 3

(notice that a normal linebreak in the code block is ignored either)

However, if I use two blank lines instead of one, within the atom editor, it works as intended. It does not work in the stackoverflow editor itself though, the input is rendered as seen above, no matter how many empty lines I use to seperate them. The only way to make it work is to use a blank line with   or something like that.

Can somebody explain to me why within the atom editor (and markdownpad, for that matter), I have to use two empty lines to seperate the list and the code and why this does not work here?


Solution

  • There are many flavours of Markdown and Stackoverflow uses a different one from GitHub. However, there was just a standardization effort launched called CommonMark.

    Besides using fenced instead of indented code blocks (using ```), a trick that also works quite consistently is to put a comment in between:

    - Item 1
    - Item 2
    - Item 3
    
    <!-- -->
    
        Some code line 1
        Some code line 2
        Some code line 3