obsidianmd / obsidian-api

Type definitions for the latest Obsidian API.
https://docs.obsidian.md
MIT License
1.65k stars 192 forks source link

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

Open RyotaUshio opened 5 months ago

RyotaUshio commented 5 months ago

Steps to reproduce:

Expected result:

![Display text](file.png)

Actual result:

![](file.png)

The alias parameter has no effect.

RyotaUshio commented 5 months ago

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.

RyotaUshio commented 5 months ago

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

https://github.com/obsidianmd/obsidian-api/assets/72342591/736b51c0-8919-43f0-a17d-59d2a28f54dd