Format to add standard code blocks within Markdown

2019-08-11 05:32发布

问题:

I've found that I can't get code blocks within numbered lists.

For example, when I add a code block by indenting by four spaces normally like below:

1. Do the first thing

    $ git stuff
    $ git other stuff 

2. second thing:

    $ git more stuff

it comes out like this, where the $ git lines are normal text and are not formatted as code:

  1. Do the first thing

    $ git stuff $ git other stuff

  2. second thing:

    $ git more stuff

I can use the backticks to do it, i.e.

1. Do the first things

    `$ git stuff`  
    `$ git other stuff` 

2. second thing:

    `$ git more stuff`

but I would like to do the blocks 'normally' (4 space indent) if I can.

回答1:

Per the documentation you need to do extra indentation; +4 spaces or +1 tab (8/2, respectively, from column 0).

1. Item 1

        $git stuff
        $git other stuff

2. Item 2

        $git more stuff

Those newlines are necessary.