Insert precise heading links when there are duplicate headings in a note

Steps to reproduce

note.md
# headerA
content 1

## headerB
content 2

# headerB
content 3

Expected result

Expect use [[note#headerB]] to refer 1st-level headerB with content3,

Actual result

Link to 2nd-level headerB above content 2.

Environment

  • Operating system: Win 10
  • Debug info:
    SYSTEM INFO:
    Obsidian version: v1.1.9
    Installer version: v1.1.9
    Operating system: Windows 10 Pro 10.0.19045
    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

    RECOMMENDATIONS:
    none


Additional information

I think should use Level-Header Path to refer 2nd-level “headerB” like [note#headerA#headerB].
In OS file system, same file/folder name on different path won’t be treated as duplicate.

1 Like

This is not a bug — you should use [[#header A#header B]] to specifically target redundant subheadings (or strive not to use redundant headings if you’re creating links to them).

2 Likes

Yes, I want to create links to both headings and subheadings, but when which name is duplicated in other heading path, will get the wrong target.

# a
1
## b
2
# b
3

![[#b]]
![[#a#b]]

will get two #b 2, not #b 3 and #b 2.

I’m seeing what you mean now, and can reproduce. [[#b]] gives a dropdown to let me choose either the H1 or the H2, but no matter which I select, I get the H2.

2 Likes

Okay, so in other words, selecting a nested heading when there are duplicate headings should insert a precise “pathed” link to the heading, rather than a single #heading link.

This is akin to how “shortest path to note” currently works when there are multiple notes with the same name.

I’ll rename the thread to be more specific and move it to feature requests.

2 Likes

I would like to add an example to this problem. Suppose I am documenting a study note on microkernel architecture. The outline of the file might be something like this:

# Definition
xxx

# Composition
## Core System
### Definition
### Example

## Plug-in Components
### Definition
### Example

# Example

So different “Example” refers to various level of abstraction. Sometime I want to reference the example of the “microkernel architecture” while sometime I want to reference the example of “core system”…

For sure the workaround can fix such problem

# Definition
xxx

# Composition
## Core System
### Definition of Core System
### Example of Core System

## Plug-in Components
### Definition of Plug-in Components
### Example of Plug-in Components

# Example

Maybe is not “clean code”… Just like putting a full-qualified name under some using namespace…