24

Currently, trying to put two code blocks one after the other results in one big code block.

CodeBlock1
{
   // Hey, look at me!
}

CodeBlock2
{
   // I'm different (but not really).
}

How do I separate these blocks without typing anything in between (as shown below)?

CodeBlock1
{
   // Hey, look at me!
}

You shall not pass!

CodeBlock2
{
   // I'm different (but not really).
}
43

You can use

a html comment
to separate them.

Source:

    a html comment

<!-- tsk -->

    to separate them.
  • 1
    That works, although I wish a simple newline would do. – Yawus Oct 23 '12 at 23:18
  • 4
    Well, that's difficult, how many empty lines signal a new code block? People often have a surprisingly large number of consecutive empty lines in their code. – Daniel Fischer Oct 23 '12 at 23:20
  • 1
    "how many empty lines signal a new code block?" just one if empty lines within the code also needed to be indented 4 spaces, which makes the most sense to me. – Jack Douglas Dec 21 '14 at 17:59
5

You can't. Markdown doesn't care how many lines you add in between. If there's nothing there, it's still the same code block. That's how Markdown works. If you don't want physical text between them, you can use something that Markdown will remove to make it break the code block thinking there's something there. Most commonly an empty HMTL comment: <!-- -->

CodeBlock1
{
   // Hey, look at me!
}
CodeBlock2
{
   // I'm different (but not really).
}

Since you're using an HTML comment, also consider if your code will be highlighted, and properly. If not, considering using that comment to specify the language so it does get highlighted properly. It will make the post look nicer while achieving your goal at the same time.

1

It is also possible to use HTML carriage return entity &#13; While not ideal, it allows for separation of two code blocks. However, current Stack Exchange interpreter requires a additional line break (unlike some other Markdown interkreters):

    code block 1
    &#13;

    code block 2

Results in:

code block 1

code block 2

UPDATE: The same can be achieved using a simpler soft hyphen entity: &shy;

You must log in to answer this question.

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