vschroeter / obsidian-virtual-linker

Plugin for obsidian that automatically generates virtual links for text within your notes that match with the titles or aliases of other notes in your vault.
Other
134 stars 5 forks source link

Support for linking headers #64

Open vschroeter opened 1 month ago

vschroeter commented 1 month ago

What do you guys think about adding virtual links for headings in notes?

I sometimes have the case where I have a higher-level note that explains several sub-concepts, each with its own subheader, under the same main concept. But I still want these subheadings to be automatically linked without having to define aliases for each of them.

Maybe this could be an option, globally in the settings and per note by adding a tag?

Salamander230 commented 1 month ago

A global settings option to link to headers and a per note option by adding tags like linker-include-headers and linker-exclude-headers is a good idea.

However, there are ways in which it can go wrong, so I would suggest other more granular options to have as well.

For example, if two different files have the same named headings or if a heading is in a concise form that only makes sense to use in a specific note. Take these two notes for example:

Skin cancer.md

# Etiology
Ultraviolet radiation.
Lung cancer.md

# Etiology
Chronic smoking.

For the above examples, Etiology by itself is ambiguous, as it can refer to Etiology of skin cancer or Etiology of lung cancer. You would only know which it's referring to if you're in those notes, but not if you're virtually linking to Etiology from another note.

Because of this, it's really Etiology of skin cancer/Skin cancer etiology or Etiology of lung cancer/Lung cancer etiology that I would want virtual links for, not Etiology by itself, even though in the notes themselves it makes perfect sense to just write Etiology. This also presents the need for aliases for each header.

The solution for this can be to allow the user to add a little bit of commented text below each header that would allow for:

For the above examples, this is how it may look:

Skin cancer.md

# Etiology of skin cancer
%% #linker-include-header
Skin cancer etiology | Skin cancer etiologies
%%
Ultraviolet radiation.
Lung cancer.md

# Etiology
%% #linker-include-header/aliases-only
Etiology of Lung cancer | Etiologies of lung cancer | Lung cancer etiology | Lung cancer etiologies %%
Chronic smoking.

All in all, I believe this would be a good approach to this idea, but I don't know if the implementation would be straightforward. Another cool thing this would allow is a note that acts as a glossary of definitions, not requiring a person to make a note for each term in the glossary:

Glossary.md

# Heart attack
%%
Heart attacks | MI | Myocardial infarction 
%%
A medical condition characterized by lack of blood flow to a region of the heart.

# Cancer
%%
Cancers | Malignancy | Malignancies
%%
An abnormal, uncontrollable growth of cells.

Interestingly, this would provide similar functionality to the Note Definitions plugin, but in a different manner that's more flexible since the virtual linking in this plugin is faster and less constrained.

Thanks, and looking forward to hear your thoughts :)

jiajiala commented 1 month ago

I want this feature I've also been creating aliases for the subheadings in the file, if I really want obsidian to set the method to make the subheadings a topic directly at the subheadings