I found the solution in this Meta Stack Overflow question:
For example, if it is a numbered (or bulleted) section which should be like this:
- [LINE 1]
[LINE 2]
Normal [LINE 2] text
CODE LINE 1
CODE LINE 2
CODE LINE 3
[LINE 3]
Using Proper Markdown (Preferred Method)
It can be done by indenting the code an extra 4 spaces. Indenting it just 4 spaces will only make it part of the list as normal text. The example for above would be:
1. [LINE 1]
2. [LINE 2]
Normal [LINE 2] text
CODE LINE 1
CODE LINE 2
CODE LINE 3
3. [LINE 3]
Using HTML <tags>
(Alternative Method)
Alternatively, it can also be done using HTML tags like so:
1. [LINE 1]
2. [LINE 2]
Normal [LINE 2] text
<pre><code>CODE LINE 1
CODE LINE 2
CODE LINE 3
</code></pre>
3. [LINE 3]
Using HTML <tags>
should be avoided as much as possible since it becomes difficult to read and comprehend the text when reading from source. Markdown was born to get rid of this weakness by removing all the clutter.