FileManager.generateMarkdownLinks
’s behavior is different from when we insert a link using Obsidian’s built-in link suggestions (i.e. the one that is triggered with[[
), when the Use [[Wikilinks]]
setting is turned off and the link points to a heading or a block.
Steps to reproduce
Built-in suggestion
- Open the sandbox vault. In the settings, turn off
Use [[Wikilinks]]
. Then, theFiles & Links
settings will look like this:
- Open
Start Here.md
. In the editor, type[[#
. Select the first headingI'm interested in Obsidian
. - Next, type
[[^
. Select the first block (i.e. the paragraph “Hi, welcome to Obsidian!”) - The resulting link will look like the following (block ID will vary):
[I’m interested in Obsidian](#I’m%20interested%20in%20Obsidian)
[](#^6311c7)
generateMarkdownLink
- Open the sandbox vault and enter the developer console.
- Run this:
const file = app.vault.getAbstractFileByPath('Start Here.md');
app.fileManager.generateMarkdownLink(
file,
file.path,
'#I’m interested in Obsidian'
)
- Run this:
app.fileManager.generateMarkdownLink(
file,
file.path,
'#^6311c7'
)
- The result will be
[Start Here](#I’m%20interested%20in%20Obsidian)
and'[Start Here](#^6311c7)'
, respectively.
Expected result
These two are expected to yield the same result, I guess.
Actual result
They differ. generateMarkdownLink
uses the note title as the alt text for both heading and block.
Environment
SYSTEM INFO:
Obsidian version: v1.4.11
Installer version: v1.3.5
Operating system: Darwin Kernel Version 22.3.0: Thu Jan 5 20:53:49 PST 2023; root:xnu-8792.81.2~2/RELEASE_X86_64 22.3.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: off
Plugins installed: 0
Plugins enabled: 0
RECOMMENDATIONS:
none