terrastruct / d2

D2 is a modern diagram scripting language that turns text to diagrams.
https://d2lang.com
Mozilla Public License 2.0
16.59k stars 417 forks source link

href missing svg file suffix in multi-layer SVG output #2117

Closed dangunter closed 3 days ago

dangunter commented 3 days ago

The multi-layer SVG output renders the link keyword as hyperlinks to new layers in separate SVG files using both -- I assume for some backwards compatibility reasons, though this seems overly conservative -- both href and xlink:href in an <a> element. Unfortunately the target of the links is missing the ".svg" suffix and therefore the links do not work.

minimal example to reproduce:

layers: {
    one: {
        ping: {
            link: two
        }
    }
    two: {
        pong: {
            link: one
        }
    }
}

Command: d2 filename.d2

Note: Manually adding ".svg" suffixes to the links will fix this example, but of course this is not how it should be done.

Fix: add ".svg" to the href (the xlink:href should be removed imho) generated in response to the link element, when rendering as SVG.

alixander commented 3 days ago

You should use the underscore the target layer above

layers: {
    one: {
        ping: {
            link: _.layers.two
        }
    }
    two: {
        pong: {
            link: _.layers.one
        }
    }
}

But as for why it's linking to new SVGs that don't exist -- I'll look into. Thank you

dangunter commented 3 days ago

that seems besides the point? the path is ok, it just doesn't append a suffix. maybe this is really a core error in how links are done with layers, though, and not related to tala

alixander commented 3 days ago

the path being close is just coincidence. if you link correctly, it gives the correct url.

but yes this is a D2 issue in general -- I've transferred it over. Thanks