Skip to content

Commit

Permalink
Merge pull request #2105 from alixander/import-link
Browse files Browse the repository at this point in the history
d2ir: fix import url link
  • Loading branch information
alixander authored Sep 17, 2024
2 parents e7896e7 + 61bd169 commit e3952ca
Show file tree
Hide file tree
Showing 7 changed files with 288 additions and 155 deletions.
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@
- CLI: fixes theme flag not being passed to GIF outputs [#2071](https://github.com/terrastruct/d2/pull/2071)
- CLI: fixes scale flag not being passed to animated SVG outputs [#2071](https://github.com/terrastruct/d2/pull/2071)
- CLI: pptx exports use theme flags correctly [#2099](https://github.com/terrastruct/d2/pull/2099)
- Imports: importing files with url links is fixed [#2105](https://github.com/terrastruct/d2/pull/2105)
19 changes: 19 additions & 0 deletions d2compiler/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,25 @@ x -> y: {
}
},
},
{
name: "import_url_link",

text: `...@test
`,
files: map[string]string{
"test.d2": `elem: elem {
link: https://google.com
}`,
},
assertions: func(t *testing.T, g *d2graph.Graph) {
if len(g.Objects) != 1 {
t.Fatal(g.Objects)
}
if g.Objects[0].Link.Value != "https://google.com" {
t.Fatal(g.Objects[0].Link.Value)
}
},
},
{
name: "url_tooltip",
text: `x: {tooltip: https://google.com}`,
Expand Down
7 changes: 7 additions & 0 deletions d2ir/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,13 @@ func (c *compiler) extendLinks(m *Map, importF *Field, importDir string) {
continue
}
val := f.Primary().Value.ScalarString()

u, err := url.Parse(html.UnescapeString(val))
isRemote := err == nil && strings.HasPrefix(u.Scheme, "http")
if isRemote {
continue
}

link, err := d2parser.ParseKey(val)
if err != nil {
continue
Expand Down
154 changes: 77 additions & 77 deletions e2etests-cli/testdata/TestCLI_E2E/layer-link/index.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
156 changes: 78 additions & 78 deletions e2etests-cli/testdata/TestCLI_E2E/layer-link/test2.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified e2etests-cli/testdata/TestCLI_E2E/pptx-theme-overrides.exp.pptx
Binary file not shown.
106 changes: 106 additions & 0 deletions testdata/d2compiler/TestCompile/import_url_link.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e3952ca

Please sign in to comment.