Code fences in list items

I have been struggling with code blocks within list items.

The combination may seem most natural to represent as in the following:

- One
  
  ```
  foo
  ```
​
- Two
​
  ```
  bar
  ```

Indeed, it appears with most renderers, the results are favorable.

However, the case is strong that the contents of a code block may be added simply by copying the contents of an existing document.

In contrast, the form illustrated above requires control over the indentation of every line. In fact, I have understood that avoiding such a difficulty was among the principle motives for code fences to have been introduced into the grammar, originally, as an alternative to code blocks being demarcated by every line leading with four unprinted space characters.

Is there any means to express code fences in lists while while exploiting the intended convenience of the fences?

I seem to recall that the following form has been allowed by some engines:

- One
  
  ```
foo
```
​
- Two
​
  ```
bar
```

However, I am failing to reproduce favorable results in any engines I have immediately available.

There is no standard syntax that keeps the pasted source completely unindented while nesting it inside the list item. An editor command that indents all selected lines is the usual solution. Otherwise, the code block must be moved outside the list and referenced from the item.

See the CommonMark specification sections on list-item indentation and lazy continuation and fenced code blocks.

Carve solved this by the way - and handles this case more directly with its + continuation marker. A + on its own line attaches the next flush-left block to the preceding list item:

- Config example:
+
```
services:
  app:
    image: example/app
```

Or directly as only list item

- +
```
services:
  app:
    image: example/app
```

The code and its fences remain at the left margin, so pasted content needs no indentation. The + records the structural relationship explicitly instead of encoding it through leading spaces.
The flush-left helps to keep the indentation “sane” :slight_smile:

Could be ported to Markdown (or commonMark for that matter) maybe.
But with the + being also a list element, a different character might be needed then.