Code blocks can break file heading detection

Copy paste this into a markdown file and open it in Obsidian.

# Heading 1
# Stuff

# Heading 2
Can not link two Heading 2 via `[[#` syntax.

You will not be able to link to Heading 2 via the [[# syntax. The problem is caused by the indentation of the “```” that closes the code block. The problem is specific to code blocks.

Debug info

Obsidian version: v1.0.3
Installer version: v0.14.15
Operating system: Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:54 PST 2021; root:xnu-8019.61.5~1/RELEASE_X86_64 21.2.0
Login status: not logged in
Insider build toggle: off
Live preview: on
Legacy editor: off
Base theme: dark
Community theme: none
Snippets enabled: 0
Restricted mode: on


No, this is not the right interpretation of this issue.
You cannot have different indentations for the beginning and end of codeblock.

This is not true. You CAN have different indentations for the beginning and end of a codeblock. You maybe SHOULD not have, because it breaks things, but it is possible and renders fine! Note that it only possible for code blocks with syntax highlighting (that is opening backticks have to be succeeded by a language name e.g. ```python). And if you accidently do so you’ll end up being confused about why file heading detection is broke. This is a bad user experience!


will render to this

This is the reference implementation: ```Python %23%20Stuff ``` %23%20Heading%202 Can%20not%20link%20two%20Heading%202%20via%20`[[%23`%20syntax.

Reader is correct. Live preview is wrong.

I see. In this case I would consider this as a bug in the live preview.

1 Like