Live Preview: Better support of code blocks in lists

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)
8 Likes