Search code examples
commonmark

Why does CommonMark consider this 7 space indent a code block?


I'm storing some notes with CommonMark and I noticed that this snippet seems to render differently on SO (echo is indented 7 spaces).

1. Print Windows folder path

       echo %windir%

Here it is interpreted as a code block on http://spec.commonmark.org/dingus/:

enter image description here

And here it is on Stack Overflow:

enter image description here

If I indent echo by 8 spaces instead, it will now show as a code block on Stack Overflow:

enter image description here

But on http://spec.commonmark.org/dingus/ it now has a leading space (I've selected it to show):

enter image description here

Is this because SO isn't actually using the full CommonMark spec (yet?)?

Or is there a CommonMark setting to make it render the way SO does?

This is a little annoying because many of my notes are indeed text that could find their way into a question or answer somewhere on Stack Exchange. So I'm just hoping to figure out what's going on here.


Solution

  • Turns out this was answered by @balpha in this June 2015 post:

    https://meta.stackexchange.com/a/258587/879

    List items

    Currently, this will create a list item with two paragraphs:

    1. This is the first paragraph
    
     And this is the second one.
    

    With CommonMark (and even in a significant number of other Markdown implementations), the "second one" will not be part of the list item, but a stand-alone paragraph after the list. To make it part of the list item, you have to indent it to the same margin as the first paragraph like this:

    1. This is the first paragraph
    
       And this is the second one.
    

    I was confused by what seemed like a somewhat arbitrary "7 spaces" but now I realize it's in fact 3 spaces to bring it under alignment with the list item, and then the standard 4 spaces which identifies it as a code block.

    Confirmed by this little test:

    enter image description here

    This actually makes good sense to me, I think I like it.

    So that answers that, I guess SE still uses its own variant that doesn't involve this type of alignment.