terrastruct / d2-vscode

VSCode extension for D2 files.
https://d2lang.com
BSD 3-Clause "New" or "Revised" License
240 stars 11 forks source link

rendered href links to local .md files do not work #129

Closed Matt-Sim closed 9 months ago

Matt-Sim commented 11 months ago

Need

It is very valuable to navigate to the local .md file of the linked item. Also, this desired behaviour would be consistent with the normal behaviour of local .md links.

Example

x.md:

normal [link to y](y), works normally

```d2
y: y: d2 link does not work {
  link: y
}

y.md:
````md
normal [link to x](x), works normally

```d2
x: x: d2 link does not work {
  link: x
}


Now preview.

# Result
<img width="520" alt="image" src="https://github.com/terrastruct/d2-vscode/assets/98189551/28b01cc7-9eee-44fa-8f4a-cd032bcd8423">

# Expected behaviour
Clicking on the D2 link should behave the same as the normal markdown link, ie: navigate to the other local file

# Actual behaviour
The hover cursor appears but clicking has no noticeable effect.

# Environment
macOS Sonoma 14.1.2
VS Code 1.84
D2 version 0.6.1
D2 VS Code extension v0.8.8
Matt-Sim commented 11 months ago

fyi: the Obsidian D2 plugin does follow internal links as expected.

For comparison, the svg anchors are rendered as follows:

<!-- Obsidian, D2 plugin -->
<a
  href="y"
  xlink:href="y"
  class="internal-link"
  data-href="y"
  target="_blank"
  rel="noopener"
  ><g id="y"
    ><g class="shape"
      ><rect
        x="0.000000"
        y="0.000000"
        width="245.000000"
        height="66.000000"
        class="stroke-B1 fill-B6"
        style="stroke-width: 2"
      ></rect></g
    ><text
      x="122.500000"
      y="38.500000"
      class="text-bold fill-N1"
      style="text-anchor: middle; font-size: 16px"
      >y: d2 link does not work</text
    ></g
  ></a
>

<!-- VS Code, D2 extension -->
<a href="y" xlink:href="y"
  ><g id="y"
    ><g class="shape"
      ><rect
        x="0.000000"
        y="0.000000"
        width="245.000000"
        height="66.000000"
        class="stroke-B1 fill-B6"
        style="stroke-width: 2"
      ></rect></g
    ><text
      x="122.500000"
      y="38.500000"
      class="text-bold fill-N1"
      style="text-anchor: middle; font-size: 16px"
      >y: d2 link does not work</text
    ></g
  ></a
>
BarryNolte commented 11 months ago

The markdown extension is actively denying this. These are the allowed link types, according to the markdown extension:

const passThroughLinkSchemes = ['http:', 'https:', 'mailto:', 'vscode:', 'vscode-insiders:'];

Unfortunately, once we pass the fragment to the markdown extension, we have no control, unlike when we do our own preview, we can do just about anything. I even tried inserting some code to get around this and it was completely rejected by the security model.