Fenced code block under numbered list items

I would like to create a numbered list where some items contain code blocks. My understanding is that fenced code blocks are “preferred” to indented code blocks so I tried:

1. Give `foo` one or more CRUD-like functions:

    * add
    * remove

2. Patch `foo` so that there are no hardcoded external sources:

    ```
    $ sudo apt install foo
    $ foo install bar
    - Package "bar" not found
    ```

3. (Optional) Create packages for maintainer-vouched sources

    ```
    $ sudo apt install foo
    $ sudo apt install foo-vouched-source
    $ foo install bar
    - Package "bar" installed
    ```

But item 3 was rendered as a numeral one. So instead I did this:

1. Give `foo` one or more...

2. Patch `foo` so that...

    > `$ sudo apt install foo`!!
    > `$ foo install bar`!!
    > `- Package "bar" not found`

3. (Optional) Create packages...

…with !! indicating two trailing spaces. This solution worked but is not very readable in unrendered plaintext.

Is there any other way I can include code blocks under numbered list items? Or is there an error (a CommonMark implementation error) in the renderer I’m using (in other words, the first method should have worked)?

As a broader question, when writing technical instructions I tend to use numbered lists with lengthy list items. I’d like them to be able to include images, multiple paragraphs, tables and code blocks. Does CommonMark, as envisioned, support this writing style/approach, or am I better off switching to numbered headings?

The first list looks correct in the dingus.

What implementation are you using?
Your example works fine with commonmark.js (see the dingus) and with cmark.

1 Like

I was using an editor that I have since discovered isn’t 100% CommonMark. I’ll test on the dingus in future! Thanks.