BUG: generateMarkdownLink doesn't properly handle aliases

My plugin (AutoMOC) heavily utilizes the generateMarkdownLink() function to create links to other notes. It is supposed to account for user link preferences (Wikilinks vs Markdown Links). It works fine normally, but breaks in the case where a user is using Markdown Links and has an alias in the note. For markdown links, [Alias](Filename.md) would be the correct link. However, it seems like generateMarkdownLink() always appends the alias to the end of the link regardless of using Wikilinks for MarkdownLinks, making the output in this case [Filename](Filename.mdAlias). This results in a broken link.

Additionally, even in the case of Wikilinks (which should have the format [Filename](Filename.md|Alias)), the | separator is not automatically added. In my code I have to make the alias I want to add | + Alias instead of just Alias.

It’s possible I’m using this function incorrectly (and if I am, let me know), but I think this is a bug that needs to be resolved.

You are using it incorrectly obsidian-auto-moc/main.ts at 69872fba822f7b2e1b43855dcce1049b4bf74424 · dalcantara7/obsidian-auto-moc · GitHub

You are passing alias as 3rd argument which is subpath

Here is the correct version

this.app.fileManager.generateMarkdownLink(
  file,
  activeFileView.file.path,
  undefined,
  alias
)
2 Likes

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.