[Bug] generateMarkdownLink behaves unexpectedly for markdown links (i.e. non-wikilinks) to heading/block

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

  1. Open the sandbox vault. In the settings, turn off Use [[Wikilinks]]. Then, the Files & Links settings will look like this:

  1. Open Start Here.md. In the editor, type [[#. Select the first heading I'm interested in Obsidian.
  2. Next, type [[^. Select the first block (i.e. the paragraph “Hi, welcome to Obsidian!”)
  3. The resulting link will look like the following (block ID will vary):
[I’m interested in Obsidian](#I’m%20interested%20in%20Obsidian)


  1. Open the sandbox vault and enter the developer console.
  2. Run this:
const file = app.vault.getAbstractFileByPath('Start Here.md');
    '#I’m interested in Obsidian'
  1. Run this:
  1. 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.


	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


Another issue reported regarding generateMarkdownLink: