Folding applied on code block lines starting with "#"

Steps to reproduce

In Live Preview :

  • Create headings (H1, H2, etc…)
  • Create some code blocks containing some lines starting with a “#”
  • Fold all headings then unfold manually

Take note that you will need to fold/unfold headings multiple times in order to reproduce the bug. These steps have been reproduced in the Sandbox vault.

Expected result

  • Folding should not be applied on code block lines.

Actual result

  • You will see that folding is applied on the code block lines starting with a “#”


  • Operating system: Debian 11 bullseye
  • Debug info:
    Obsidian version: v0.14.15
    Installer version: v0.13.19
    Operating system: #1 SMP Debian 5.10.113-1 (2022-04-29) 5.10.0-14-amd64
    Login status: logged in
    Catalyst license: supporter
    Insider build toggle: off
    Live preview: on
    Legacy editor: off
    Base theme: dark
    Community theme: Atom
    Snippets enabled: 4
    Safe mode: off
    Plugins installed: 5
    Plugins enabled: 1
    1: Collapse All

Additional information


Please, post a screen recording of this happening in the sandbox vault and attach a copy of the document where this happens.

Here is a document : (13.0 KB)

Here is a screencast :

Take note that the document differ from the screencast.
Also I was not able to reproduce the bug at first with only a small part of the document. So my guess is that this bug is probably related to long markdown notes.

Just let me know if you need something else.


I confirm. There is a bug with the # symbol in the code block after folding.
Especially arbitrary unfolding after switching between tabs.

Hello, I also confirm the bug. It appears when using “fold all headings and list”, but if you click on a faulty header again to unfold/fold, it is then correct.

Confirm on 1.1.16.
Reproduce in Sandbox in Live Preview.

  • Create note, paste next content: (14.5 KB)
  • Close note
  • Open note
  • Run command: Fold all headings and lists

Result: folding comments in python code blocks.