FlorianWoelki / obsidian-iconize

Simply add icons to anything you want in Obsidian.
https://florianwoelki.github.io/obsidian-iconize/
MIT License
777 stars 53 forks source link

Icons are printed twice, when the link has a display text identical to the linked base filename #519

Closed stroiman closed 2 weeks ago

stroiman commented 2 weeks ago

Describe the bug

In a medialink, if it has a display text identical to the filename (without the .md), and the linked note has an icon, the icon is rendered twice.

This scenario is relevant when the link has a path component that you don't wish to show.

The issue is observed both when the icon has been changed directly in the frontmatter with the icon property, and also when using the "Change Icon" menu item.

To Reproduce

In the file, journals/2024-07-07.md, I added an icon in the frontmatter (the first day I tried out iconize):

---
icon: "LiCalendarDays"
---
# Diary - Monday ...

Today, in the file, journals/2024-07-08.md, I have the following markdown

- Yesterday: [[journals/2024-07-07|2024-07-07]]

The calendar icon is rendered twice in that link:

image

Placing the cursor on the link, it's apparent that it's probably the link text is the source of the extra icon render.

image

Additional note

If I change the link text, e.g. the link becomes: [[journals/2024-07-07|x2024-07-07]], the double icon disappears. If I change it back to what it was, the double icon reappears.

Expected behavior

The icon should only be rendered once ;)

Additional context

I did not try this in a minimal sandbox vault, but I did try using a few different themes, just to eliminate it wasn't a theme issue. The issue exists in all the themes I tried (Default, Things, Typomagical, Molecule).

If the bug is not immediately reproducible, I'll gladly make a minimal vault that shows the issue.

p.s. I haven't looked at your code yet, but I've been doing plugins recently relying heavily on metadata, and also detecting content in the page. So I wouldn't mind giving it a look, and see if I can identify the issue if you want input.

FlorianWoelki commented 2 weeks ago

Thank you for the report!

I think this issue is related to #445 as it is describing the same issue.

Feel free to give the mentioned issue a thumbs up, to upvote the issue.