oleeskild / digitalgarden

275 stars 159 forks source link

Wikilinks display names and sizes not implemented #1

Closed ThatOtherAndrew closed 2 years ago

ThatOtherAndrew commented 2 years ago

Problem

If you have a link such as ![[cat.jpg|500]] or [[A very long file name|myfile]], they do not display the same as in Obsidian.

Proposed Solution

  1. Check if the link contains an unescaped pipe character - if yes, get the string after it
  2. If the link is embedded (prefixed by !) and the string is numeric, set the width HTML attribute
  3. If the link is a regular anchor tag, set the tag contents to the string, instead of matching the href attribute

I'd submit a pull request, but I don't have a very good understanding of how the templating engine works 😅

oleeskild commented 2 years ago

Thanks for showing an interest in the project!

Great input, I didn't even know about the image width property. I've implemented the changes. (Was not able to take into account that the pipe character is escaped, it seems the template engine removes it before I can access it)

You can use the "Create PR"-button in the plugin setting to add the changes to your own site. Let me know if it works for you.

ThatOtherAndrew commented 2 years ago

The new feature appears to function correctly with links, however I've noticed an edge case with embedded images with the following syntax: [|500](https://image.url/) In Obsidian, this would set the image width to 500 pixels, however Digital Garden sets <img alt="|500">.

This is a very minor detail though - thank you for the implemented feature so far and the very quick updates!

oleeskild commented 2 years ago

Hmm, this should be working. As a a test i published this note: https://github.com/oleeskild/notathage/blob/main/src/site/notes/Image%20Test.md

Which resulted in this page, setting the correct width: https://ole.dev/notes/image-test

Do you have a concrete example where this doesn't work as you expected?

ThatOtherAndrew commented 2 years ago

Ah, I'm a doofus - I think I didn't update and rebuild the site properly. I re-published the page, and all is functioning as intended now. Thanks for your help!

(Closing)