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 “#”

Environment

  • Operating system: Debian 11 bullseye
  • Debug info:
    SYSTEM 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

7 Likes

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 :
Covenant.md (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.
Regards.

thanks

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:
    FoldingCodeBlocks.md (14.5 KB)
  • Close note
  • Open note
  • Run command: Fold all headings and lists

Result: folding comments in python code blocks.

I can confirm this on the 1.3.5 AppImage for Linux (Ubuntu 22.04).

Obisidan wrongly identifies certain specific lines within code blocks (i.e., blocks bounded within pairs of three backticks) whose first non-whitespace character is a hash sign # as “fold points” (not sure what the proper term is). I’ll call these “bad fold lines.”

When I open a page, the headers will randomly decide whether to be collapsed/expanded (which is another problem that it would be great if it could be fixed). On the “collapsed” headers, the section below is folded only to the first bad fold line; the remainder of the section is visible.

If I expand the header, the section expands and appears normally. If I then re-collapse the header, the section then collapses only to the next bad fold line. If I expand and re-collapse again, the section collapses to the subsequent bad fold line, etc. That is, the process of expanding and re-collapsing the section header causes the current bad fold line to no longer be mistaken for a fold line.

I cannot reproduce the error at will because it seems to happen only when I load a page that I haven’t loaded recently. I assume that Obsidian has some sort of caching process when it loads pages from their source files, and I’m guessing that the bug in question occurs only when the file is first loaded and processed. Thus, there’s little I can do to set up a minimum repeatable example or capture a video because once the page I’m experimenting with has been worked with, the problem disappears.

Nevertheless, since I copy many code blocks into my Obsidian notes, I’ve noticed the following patterns:

  1. If the # is preceded by whitespace, the line is recognized as a bad fold line if that whitespace is four spaces, but not if that whitespace is a tab.

  2. A line otherwise fitting the above condition will not be recognized as a bad fold line if the line above it begins with # preceded by any number of spaces (including zero). That is, only the first bad fold line in a consecutive series of potential bad fold lines is recongnized.

The one concrete example I can provide is the output of Ubuntu’s apt upgrade command, which I routinely copy into Obsidian in the form of a code block. In these cases, the raw text

# Header 
```bash
me@me:~$ sudo apt upgrade
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
#
# News about significant security updates, features and services will
# appear here to raise awareness and perhaps tease /r/Linux ;)
# Use 'pro config set apt_news=false' to hide this and future APT news.
#
The following NEW packages will be installed:
...

will, when I revisit the page later, often be displayed as

> Header ...
#
# News about significant security updates, features and services will
# appear here to raise awareness and perhaps tease /r/Linux ;)
# Use 'pro config set apt_news=false' to hide this and future APT news.
#
The following NEW packages will be installed:

That is, the section is “collapsed” only to the first line beginning with #.

This error makes it difficult for me to use Obsidian. My notes tend to contain many code blocks with comment lines beginning with #. Under the current version, every time I load a new page, it presents as an organizational jumble that’s difficult to parse visually until I go through and manually expand/re-collapse each section to clear away the bad fold lines. That interrupts my workflow and my thoughts about what I was about to take notes on.

Any update to this bug? @WhiteNoise

3 Likes

can anyone pls tell how to fix this???

2 Likes

+1 (relevant for me as well).

1 Like

Didn’t realize someone already made a post for this. Would be super helpful to get fixed. I have to open and close the headers everyday to get it to stop breaking due to the # in the code blocks. This is especially noticeable for long notes with lots of headings and code blocks with comments in them.

For me this doesn’t happen when I initially fold the header. It only breaks when I close Obsidian and open it again. On a reboot, the folds are broken at each of the # inside the code blocks.

2 Likes

Same problem here, happens to me when I copy a codeblock from a webpage to obsidian.

1 Like

I just wanted to say that I’m also experiencing this and would love to see it fixed. I’m learning to code and have long documents with lessons, notes, code snippets and I really need to be able to fold things so I can focus on the next lesson/steps.