36

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).
}
0

4 Answers 4

52
    Use an HTML comment

<!-- tsk -->

    to separate them.

Result:

Use an HTML comment
to separate them.
4
  • 1
    That works, although I wish a simple newline would do.
    – Yawus
    Commented Oct 23, 2012 at 23:18
  • 5
    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. Commented Oct 23, 2012 at 23:20
  • 3
    "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. Commented Dec 21, 2014 at 17:59
  • @JackDouglas you can't visually tell the difference between a line with 3 spaces and 4 spaces. Having trailing whitespace change the look of a document would be a disaster.
    – user357287
    Commented Sep 17, 2021 at 19:56
10
+50

Either use ``` for both blocks:

```
first block
```

```
second block
```

or for just one of the blocks

```
first block
```

    second block

Both options look like this:

first block
second block
1
  • 3
    Probably the preferred way now - code fences didn't exist when the question was asked, and this is so much more intuitive
    – Journeyman Geek Mod
    Commented Sep 18, 2021 at 1:08
6

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

You can use an HTML carriage return entity &#13; or an invisible character like the soft hyphen &shy;. While not ideal, it works

    code block 1
&#13;

    code block 2

Results in:

code block 1

code block 2

Note that Stack Exchange's interpreter requires an additional line break after the entity (unlike some other Markdown interpreters).

0

You must log in to answer this question.

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