Live Preview: Better support of code blocks in lists


# test heading 1

- Test
	- Test
		- Test python
		```python
		print('hello')
		```

# test heading 2

- Test
	- Test
		- Test properties
		```properties
		test
		```

# test heading 3 

1 Like

This could maybe be added to:

Going through the same things here.

test.md (562 Bytes)

And I think it’s different from that post.

2 Likes

same here, use tab or space to indent code blocks with properties will result this issue.

2 Likes

I tried switching to Obsidian multiple times, but this has always been the dealbreaker that prevented me from using Obsidian in the first place… Even to the point where I implemented some features I was missing from Obsidian on top of a different proprietary Markdown editor by and only for myself.

5 Likes

Damn, looks like this is still an issue that need to be resolved!
I like Obsidian, but this inconvenience annoying.

I mean it works ok in “Reading mode”, but still an issue in “Live mode”

6 Likes

Hi, just want to add my vote for prioritizing this issue / bug fix. Being unable to nest code blocks inside lists is a major pain point for my workflow.

11 Likes

Hi everyone,

I’ve encountered a couple of issues while using Obsidian related to Markdown code blocks inside lists, and I wanted to share my findings and suggestions:

  1. Code block breaking list numbering :When inserting a code block inside a list item, the subsequent list numbering is often broken. After some investigation, I found the root cause is that Obsidian’s auto-completion of the closing triple backticks doesn’t take indentation into account. It simply inserts a top-level closing without matching the indentation level of the opening inside the list. This misalignment disrupts the Markdown structure and can lead to rendering issues—especially if the closing ends up on its own with no content between. A simple fix would be to make the auto-completion logic preserve the same indentation level as the opening ```.
    PixPin_2025-04-25_21-05-09_0
    The key points in the above demonstration gif are as follows:



    It can be solved by adding the corresponding space before the ending ’ ’ ’
  2. Improper rendering of indented code blocks :Currently, code blocks are always rendered at the top level (no indentation), regardless of their actual position within the document. This causes issues with visual alignment—guidelines and list structures no longer line up properly, and the start and end of the code block aren’t visually aligned with the surrounding content. Fixing this would be more complex, as it likely involves changes to the rendering engine to respect indentation levels for block elements.

    It can be seen that the starting ’ ’ ‘and the ending’ ’ 'cannot be aligned, but in fact, there are only the same three Spaces in front of them.Code blocks always start at the beginning and are not inside the list
5 Likes

I simply cannot believe this problem still is there, and it gets even worse. Now I cannot even keep the list number!


4 Likes

I’m experiencing the same issue in 2025: code blocks are not rendered correctly when using relative indentation in Live Preview mode. However, they display as expected in Reading mode.

Please look into this inconsistency—thanks!

2 Likes

Steps to reproduce

Indenting a code block under list level higher than 1.

  • hello

Did you follow the troubleshooting guide? [Y/N]

Y

Expected result

Expect that the line that is the end of the code block has the indentation class so that the indentation is shown.

Actual result

The class .cm-hmd-list-indent has been removed in v1.9.1. It works fine on v1.8.10.

Environment

SYSTEM INFO:
	Obsidian version: v1.9.1
	Installer version: v1.8.9
	Operating system: Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:49 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6000 24.5.0
	Login status: logged in
	Language: en
	Catalyst license: insider
	Insider build toggle: on
	Live preview: on
	Base theme: adapt to system
	Community theme: none
	Snippets enabled: 0
	Restricted mode: on

RECOMMENDATIONS:
	none
2 Likes

I have such an issue as well, and i have become frustrated to have to manually fight Obsidian’s non-sensical rules which don’t match how other software renders markdown. Please fix Obsidian’s markdown parsing.

For this code:

**0**
- 1
- 2 the following code SHOULD be nested under this list item, but it is not because pressing tab doesn't work correctly. if i press tab, it increases with 4 spaces
    ```kotlin
    routing {
        route("/tasks") {
            get("/byPrio/{prio}") { code }
    ```
**3**
- 4
- 5 the following code IS nested under this list item bcause i MANUALLY indented every line with 2 spaces
  ```kotlin
  routing {
      route("/tasks") {
          get("/byPrio/{prio}") { code }
  ```
**6**
- 7
- 8 there should be no indentation here
```kotlin
routing {
    route("/tasks") {
        get("/byPrio/{prio}") { code }
```
**9**

Here in discourse, the code is indented correctly:


0

  • 1
  • 2 the following code SHOULD be nested under this list item, but it is not because pressing tab doesn’t work correctly. if i press tab, it increases with 4 spaces
    routing {
        route("/tasks") {
            get("/byPrio/{prio}") { code }
    

3

  • 4
  • 5 the following code IS nested under this list item bcause i MANUALLY indented every line with 2 spaces
    routing {
        route("/tasks") {
            get("/byPrio/{prio}") { code }
    

6

  • 7
  • 8 there should be no indentation here
routing {
    route("/tasks") {
        get("/byPrio/{prio}") { code }

9


In github it also looks correct:
preview:


cooked:

Or in intelij’s markdown, or discord.


In Obsidian, code is not correctly indented:



I see the following issues:

  • obsidian should indent code blocks under the parent list item, if the code blocks are indented at least 2 spaces and at maximum 4 from the ‘beginning - character of the parent’
  • as obsidian’s Tab indents with 4 spaces, this should obviously work
  • both preview and reading should look the same. They don’t look the same even in the sandbox vault (different colors and different indentation)
4 Likes