terrastruct / d2-obsidian

The official D2 plugin for Obsidian. D2 is a modern diagram scripting language thats turns text to diagrams.
https://d2lang.com
Mozilla Public License 2.0
217 stars 12 forks source link

Internal Links #6

Closed Friedolito closed 11 months ago

Friedolito commented 1 year ago

Hey, thank you for developing this plug-in!! Have you planned to integrate obsidian links into the diagrams?

I currently use mermaid, what is great but integrating obsidian links is cumbersome and the layout options are more limited. Having fast internal link options to integrate with diagrams would open up new workflows currently not possible, at least for me. Best regards!

alixander commented 1 year ago

wdym by "integrating obsidian links"? can u give a screenshot or clip? just wanna make sure we support this the way you have in mind! @FriedrichStein

Paracelsus-Rose commented 1 year ago

The ability to link to other notes inside a D2 graph easily. IE a flowchart of components in a system, and each item in the chart links to a MD note of said item. Currently it is kind of possible with mermaid, but clunky to say the least.

wiltaylor commented 1 year ago

Basically a lot of add ins for Obsidian give you the ability to create links to other notes in the vault and expect Obsidian to navigate to that note when you click the link.

Would be awesome if d2 allowed this. It would allow us to export lots of different graphs and jump between them like we can on the web interface.

An example of how this could work is as follows:

x: I'm a Mac {  

  link: https://apple.com  

}  

y: And I'm a PC {  

  link: [[Obsidan Link]]

}  

x -> y: gazoontite

I even tried using a link to an obsidian url which doesn't work currently (uses the OS URL handler in windows and linux).

x: I'm a Mac {  

  link: https://apple.com  

}  

y: And I'm a PC {  

  link: obsidian://open?vault=Codex&file=01%20-%20%F0%9F%8C%B2%20Notes%2FaddMetaAttrs%2C%20Nixpkgs 

}  

x -> y: gazoontite

image

alixander commented 1 year ago

oh interesting. does it work if you wrap that link in quotes?

this definitely looks like a killer feature for d2's obsidian integration. we have too many high priority items right now but hopefully towards end of this week or sometime next, we can do this.

wiltaylor commented 1 year ago

No wrapping them in quotes doesn't seem to work.

If I do the link like "[[test]]" it shows up but clicking the link doesn't do anything.

If I put a full obsidian url that goes via the os url handler i get the attached error above still.

Portevent commented 1 year ago

Obsidian seems to correctly recognize which note you are referencing when creating link.

MyNote {
    link: MyOtherNote   
}

Would be enough to link toward B note. If you inspect the resulting D2 diagram, the link shows up :

<a href="MyNote" xlink:href="MyNote">[...]</a

The target is correct, however Obsidian require a little more. You can inspect a "native" link to see the right attributes

<a data-href="WorkingLink" class="internal-link" [other attributes...]>...</a>

These two are enough to make a functional link (at least on my side, by manually adding them, it works).

However, I don't see a pretty solution to this. The only one seems to be :

  • Add theses attributes to the D2 lib eventho they are related to Obsidian
  • Add a step inside D2Obsidian plugin to process link and add theses attributes
korniychuk commented 1 year ago

As a temporary solution:

obsidian://open?vault=Obsidian%20Main%20Vault&file=Base%2FBooks%20Library%20%E2%80%A2%20Obsidian%20%2B%20Notion