Pre-folded headers unfold upon meeting codeblock # Comment ~3,000 characters into the section

Steps to reproduce

Happens in Live editing mode and in Source mode; it does not happen in Reading mode

  1. Create a file with a header (# Header)
  2. Paste at least 3,000 characters (such as a period, .) in any configuration, such as:
    • 3,000 periods on the first line below the header
    • 3,000 periods as the header
    • 3,000 periods spread over any number of lines below the header
    • 3,000 characters worth of typical code blocks, paragraphs etcetera
    • 3,000 characters including lists and tables
  3. Create a codeblock (``` ```) containing a series of “comments” (# Comment)
  4. Fold the header
  5. Close the file
  6. Re-open the file
  7. Your header section is folded, up until the point where it meets the comment (# Comment) after some 3,000 characters
    (Bonus steps: 8. Unfold the section; 9. Fold the section - the header section is now correctly folded)

I’ve found that it may take a larger number of # Comment lines or a larger number of periods to get the bug to happen, but the conditions for the bug happening occurred organically in a few of my codeblock-heavy, header-heavy files

Did you follow the troubleshooting guide? [Y]

This was all reproduced in a newly created sandbox vault, no snippets, default theme, restricted mode.

Expected result

I don’t want my folded header to turn unfolded upon file opening after it meets a header-like line a few thousand characters after the header. The whole folded header section should remain folded; comments in codeblocks shouldn’t be interpreted as a new header.

Actual result

Part of the header section is unfolded upon opening the file. You need to manually unfold-fold every section this happens to, and it reappears every time you open the file again.

Environment

SYSTEM INFO:
Obsidian version: v1.5.11
Installer version: v1.4.13
Operating system: Windows 10 Home 10.0.22631
Login status: logged in
Catalyst license: insider
Insider build toggle: on
Live preview: on
Base theme: dark
Community theme: none
Snippets enabled: 0
Restricted mode: on

RECOMMENDATIONS:
none


Additional information


(header folded)
image
(file closed and re-opened)

(header unfolded)

(header folded)
image

The comment can start with 0+ spaces, followed by 1+ # (possibly enough to be considered heading normally), followed by 1+ spaces and then a text. This catches a lot of comments