obsidianmd/obsidian-api

Bug: `generateMarkdown`'s `alias` parameter has no effect for non-markdown files

RyotaUshio opened this issue · 2 comments

Steps to reproduce:

  • In the sandbox vault, turn off "use [[wikilinks]]".
  • Add an attachment file such as PNG or PDF, say file.png.
  • Open the dev console and run the following:
    const file = app.vault.getAbstractFileByPath('file.png');
    console.log(app.fileManager.generateMarkdownLink(file, '', undefined, 'Display text'));

Expected result:

![Display text](file.png)

Actual result:

![](file.png)

The alias parameter has no effect.

Now I read the source code from the dev tool, and it seems like it's intended.

I guess this design is because generateMarkdownLink generates an embed link for attachment files and display text is not important for embeds.

However, generateMarkdownLink is also used to generate a non-embed link like so:

app.fileManager.generateMarkdownLink(...).slice(1)

I do this for generating links for PDF files, and even Obsidian itself does the same thing in many places.

So I believe it will be beneficial to let alias work for attachments as well. If you choose not to do so, it should be clarified in the documentation.

For example, if I turn on "Use [[Wikilinks]]" and copy a link to a PDF annotation, this becomes problematic:

Screen.Recording.2024-01-31.at.12.29.25.mov