From 61bd169026dfb855de4c0d2d762b033096421afa Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 17 Sep 2024 13:27:01 -0600 Subject: [PATCH] d2ir: fix import url link --- ci/release/changelogs/next.md | 1 + d2compiler/compile_test.go | 19 +++ d2ir/compile.go | 7 + .../TestCLI_E2E/layer-link/index.exp.svg | 154 ++++++++--------- .../TestCLI_E2E/layer-link/test2.exp.svg | 156 +++++++++--------- .../TestCLI_E2E/pptx-theme-overrides.exp.pptx | Bin 35191 -> 35191 bytes .../TestCompile/import_url_link.exp.json | 106 ++++++++++++ 7 files changed, 288 insertions(+), 155 deletions(-) create mode 100644 testdata/d2compiler/TestCompile/import_url_link.exp.json diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index fcbba795f9..7a1f11e20d 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -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) diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 662fe1062b..fe842e2d96 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -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}`, diff --git a/d2ir/compile.go b/d2ir/compile.go index d1dd2e7341..8fb31aad95 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -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 diff --git a/e2etests-cli/testdata/TestCLI_E2E/layer-link/index.exp.svg b/e2etests-cli/testdata/TestCLI_E2E/layer-link/index.exp.svg index 8a89801bca..17d69272ef 100644 --- a/e2etests-cli/testdata/TestCLI_E2E/layer-link/index.exp.svg +++ b/e2etests-cli/testdata/TestCLI_E2E/layer-link/index.exp.svg @@ -1,12 +1,12 @@ -doh + .d2-2347425782 .fill-N1{fill:#0A0F25;} + .d2-2347425782 .fill-N2{fill:#676C7E;} + .d2-2347425782 .fill-N3{fill:#9499AB;} + .d2-2347425782 .fill-N4{fill:#CFD2DD;} + .d2-2347425782 .fill-N5{fill:#DEE1EB;} + .d2-2347425782 .fill-N6{fill:#EEF1F8;} + .d2-2347425782 .fill-N7{fill:#FFFFFF;} + .d2-2347425782 .fill-B1{fill:#0D32B2;} + .d2-2347425782 .fill-B2{fill:#0D32B2;} + .d2-2347425782 .fill-B3{fill:#E3E9FD;} + .d2-2347425782 .fill-B4{fill:#E3E9FD;} + .d2-2347425782 .fill-B5{fill:#EDF0FD;} + .d2-2347425782 .fill-B6{fill:#F7F8FE;} + .d2-2347425782 .fill-AA2{fill:#4A6FF3;} + .d2-2347425782 .fill-AA4{fill:#EDF0FD;} + .d2-2347425782 .fill-AA5{fill:#F7F8FE;} + .d2-2347425782 .fill-AB4{fill:#EDF0FD;} + .d2-2347425782 .fill-AB5{fill:#F7F8FE;} + .d2-2347425782 .stroke-N1{stroke:#0A0F25;} + .d2-2347425782 .stroke-N2{stroke:#676C7E;} + .d2-2347425782 .stroke-N3{stroke:#9499AB;} + .d2-2347425782 .stroke-N4{stroke:#CFD2DD;} + .d2-2347425782 .stroke-N5{stroke:#DEE1EB;} + .d2-2347425782 .stroke-N6{stroke:#EEF1F8;} + .d2-2347425782 .stroke-N7{stroke:#FFFFFF;} + .d2-2347425782 .stroke-B1{stroke:#0D32B2;} + .d2-2347425782 .stroke-B2{stroke:#0D32B2;} + .d2-2347425782 .stroke-B3{stroke:#E3E9FD;} + .d2-2347425782 .stroke-B4{stroke:#E3E9FD;} + .d2-2347425782 .stroke-B5{stroke:#EDF0FD;} + .d2-2347425782 .stroke-B6{stroke:#F7F8FE;} + .d2-2347425782 .stroke-AA2{stroke:#4A6FF3;} + .d2-2347425782 .stroke-AA4{stroke:#EDF0FD;} + .d2-2347425782 .stroke-AA5{stroke:#F7F8FE;} + .d2-2347425782 .stroke-AB4{stroke:#EDF0FD;} + .d2-2347425782 .stroke-AB5{stroke:#F7F8FE;} + .d2-2347425782 .background-color-N1{background-color:#0A0F25;} + .d2-2347425782 .background-color-N2{background-color:#676C7E;} + .d2-2347425782 .background-color-N3{background-color:#9499AB;} + .d2-2347425782 .background-color-N4{background-color:#CFD2DD;} + .d2-2347425782 .background-color-N5{background-color:#DEE1EB;} + .d2-2347425782 .background-color-N6{background-color:#EEF1F8;} + .d2-2347425782 .background-color-N7{background-color:#FFFFFF;} + .d2-2347425782 .background-color-B1{background-color:#0D32B2;} + .d2-2347425782 .background-color-B2{background-color:#0D32B2;} + .d2-2347425782 .background-color-B3{background-color:#E3E9FD;} + .d2-2347425782 .background-color-B4{background-color:#E3E9FD;} + .d2-2347425782 .background-color-B5{background-color:#EDF0FD;} + .d2-2347425782 .background-color-B6{background-color:#F7F8FE;} + .d2-2347425782 .background-color-AA2{background-color:#4A6FF3;} + .d2-2347425782 .background-color-AA4{background-color:#EDF0FD;} + .d2-2347425782 .background-color-AA5{background-color:#F7F8FE;} + .d2-2347425782 .background-color-AB4{background-color:#EDF0FD;} + .d2-2347425782 .background-color-AB5{background-color:#F7F8FE;} + .d2-2347425782 .color-N1{color:#0A0F25;} + .d2-2347425782 .color-N2{color:#676C7E;} + .d2-2347425782 .color-N3{color:#9499AB;} + .d2-2347425782 .color-N4{color:#CFD2DD;} + .d2-2347425782 .color-N5{color:#DEE1EB;} + .d2-2347425782 .color-N6{color:#EEF1F8;} + .d2-2347425782 .color-N7{color:#FFFFFF;} + .d2-2347425782 .color-B1{color:#0D32B2;} + .d2-2347425782 .color-B2{color:#0D32B2;} + .d2-2347425782 .color-B3{color:#E3E9FD;} + .d2-2347425782 .color-B4{color:#E3E9FD;} + .d2-2347425782 .color-B5{color:#EDF0FD;} + .d2-2347425782 .color-B6{color:#F7F8FE;} + .d2-2347425782 .color-AA2{color:#4A6FF3;} + .d2-2347425782 .color-AA4{color:#EDF0FD;} + .d2-2347425782 .color-AA5{color:#F7F8FE;} + .d2-2347425782 .color-AB4{color:#EDF0FD;} + .d2-2347425782 .color-AB5{color:#F7F8FE;}.appendix text.text{fill:#0A0F25}.md{--color-fg-default:#0A0F25;--color-fg-muted:#676C7E;--color-fg-subtle:#9499AB;--color-canvas-default:#FFFFFF;--color-canvas-subtle:#EEF1F8;--color-border-default:#0D32B2;--color-border-muted:#0D32B2;--color-neutral-muted:#EEF1F8;--color-accent-fg:#0D32B2;--color-accent-emphasis:#0D32B2;--color-attention-subtle:#676C7E;--color-danger-fg:red;}.sketch-overlay-B1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B2{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B3{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-AA4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-N2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-N3{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N4{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N7{fill:url(#streaks-bright);mix-blend-mode:darken}.light-code{display: block}.dark-code{display: none}]]>doh @@ -104,7 +104,7 @@ - + diff --git a/e2etests-cli/testdata/TestCLI_E2E/layer-link/test2.exp.svg b/e2etests-cli/testdata/TestCLI_E2E/layer-link/test2.exp.svg index 0947040d54..ad332e1211 100644 --- a/e2etests-cli/testdata/TestCLI_E2E/layer-link/test2.exp.svg +++ b/e2etests-cli/testdata/TestCLI_E2E/layer-link/test2.exp.svg @@ -1,13 +1,13 @@ -I'm a Mac + .d2-525054211 .fill-N1{fill:#0A0F25;} + .d2-525054211 .fill-N2{fill:#676C7E;} + .d2-525054211 .fill-N3{fill:#9499AB;} + .d2-525054211 .fill-N4{fill:#CFD2DD;} + .d2-525054211 .fill-N5{fill:#DEE1EB;} + .d2-525054211 .fill-N6{fill:#EEF1F8;} + .d2-525054211 .fill-N7{fill:#FFFFFF;} + .d2-525054211 .fill-B1{fill:#0D32B2;} + .d2-525054211 .fill-B2{fill:#0D32B2;} + .d2-525054211 .fill-B3{fill:#E3E9FD;} + .d2-525054211 .fill-B4{fill:#E3E9FD;} + .d2-525054211 .fill-B5{fill:#EDF0FD;} + .d2-525054211 .fill-B6{fill:#F7F8FE;} + .d2-525054211 .fill-AA2{fill:#4A6FF3;} + .d2-525054211 .fill-AA4{fill:#EDF0FD;} + .d2-525054211 .fill-AA5{fill:#F7F8FE;} + .d2-525054211 .fill-AB4{fill:#EDF0FD;} + .d2-525054211 .fill-AB5{fill:#F7F8FE;} + .d2-525054211 .stroke-N1{stroke:#0A0F25;} + .d2-525054211 .stroke-N2{stroke:#676C7E;} + .d2-525054211 .stroke-N3{stroke:#9499AB;} + .d2-525054211 .stroke-N4{stroke:#CFD2DD;} + .d2-525054211 .stroke-N5{stroke:#DEE1EB;} + .d2-525054211 .stroke-N6{stroke:#EEF1F8;} + .d2-525054211 .stroke-N7{stroke:#FFFFFF;} + .d2-525054211 .stroke-B1{stroke:#0D32B2;} + .d2-525054211 .stroke-B2{stroke:#0D32B2;} + .d2-525054211 .stroke-B3{stroke:#E3E9FD;} + .d2-525054211 .stroke-B4{stroke:#E3E9FD;} + .d2-525054211 .stroke-B5{stroke:#EDF0FD;} + .d2-525054211 .stroke-B6{stroke:#F7F8FE;} + .d2-525054211 .stroke-AA2{stroke:#4A6FF3;} + .d2-525054211 .stroke-AA4{stroke:#EDF0FD;} + .d2-525054211 .stroke-AA5{stroke:#F7F8FE;} + .d2-525054211 .stroke-AB4{stroke:#EDF0FD;} + .d2-525054211 .stroke-AB5{stroke:#F7F8FE;} + .d2-525054211 .background-color-N1{background-color:#0A0F25;} + .d2-525054211 .background-color-N2{background-color:#676C7E;} + .d2-525054211 .background-color-N3{background-color:#9499AB;} + .d2-525054211 .background-color-N4{background-color:#CFD2DD;} + .d2-525054211 .background-color-N5{background-color:#DEE1EB;} + .d2-525054211 .background-color-N6{background-color:#EEF1F8;} + .d2-525054211 .background-color-N7{background-color:#FFFFFF;} + .d2-525054211 .background-color-B1{background-color:#0D32B2;} + .d2-525054211 .background-color-B2{background-color:#0D32B2;} + .d2-525054211 .background-color-B3{background-color:#E3E9FD;} + .d2-525054211 .background-color-B4{background-color:#E3E9FD;} + .d2-525054211 .background-color-B5{background-color:#EDF0FD;} + .d2-525054211 .background-color-B6{background-color:#F7F8FE;} + .d2-525054211 .background-color-AA2{background-color:#4A6FF3;} + .d2-525054211 .background-color-AA4{background-color:#EDF0FD;} + .d2-525054211 .background-color-AA5{background-color:#F7F8FE;} + .d2-525054211 .background-color-AB4{background-color:#EDF0FD;} + .d2-525054211 .background-color-AB5{background-color:#F7F8FE;} + .d2-525054211 .color-N1{color:#0A0F25;} + .d2-525054211 .color-N2{color:#676C7E;} + .d2-525054211 .color-N3{color:#9499AB;} + .d2-525054211 .color-N4{color:#CFD2DD;} + .d2-525054211 .color-N5{color:#DEE1EB;} + .d2-525054211 .color-N6{color:#EEF1F8;} + .d2-525054211 .color-N7{color:#FFFFFF;} + .d2-525054211 .color-B1{color:#0D32B2;} + .d2-525054211 .color-B2{color:#0D32B2;} + .d2-525054211 .color-B3{color:#E3E9FD;} + .d2-525054211 .color-B4{color:#E3E9FD;} + .d2-525054211 .color-B5{color:#EDF0FD;} + .d2-525054211 .color-B6{color:#F7F8FE;} + .d2-525054211 .color-AA2{color:#4A6FF3;} + .d2-525054211 .color-AA4{color:#EDF0FD;} + .d2-525054211 .color-AA5{color:#F7F8FE;} + .d2-525054211 .color-AB4{color:#EDF0FD;} + .d2-525054211 .color-AB5{color:#F7F8FE;}.appendix text.text{fill:#0A0F25}.md{--color-fg-default:#0A0F25;--color-fg-muted:#676C7E;--color-fg-subtle:#9499AB;--color-canvas-default:#FFFFFF;--color-canvas-subtle:#EEF1F8;--color-border-default:#0D32B2;--color-border-muted:#0D32B2;--color-neutral-muted:#EEF1F8;--color-accent-fg:#0D32B2;--color-accent-emphasis:#0D32B2;--color-attention-subtle:#676C7E;--color-danger-fg:red;}.sketch-overlay-B1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B2{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B3{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-AA4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-N2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-N3{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N4{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N7{fill:url(#streaks-bright);mix-blend-mode:darken}.light-code{display: block}.dark-code{display: none}]]>I'm a Mac @@ -104,7 +104,7 @@ - + diff --git a/e2etests-cli/testdata/TestCLI_E2E/pptx-theme-overrides.exp.pptx b/e2etests-cli/testdata/TestCLI_E2E/pptx-theme-overrides.exp.pptx index 7719cdf0c58ea008381fd797c1a45a2d089c6dee..92f7a703a5c342d7411a28a577a6d7f00a0c1ae9 100644 GIT binary patch delta 449 zcmV;y0Y3isk^=XV0*}gz9586?gQ27zJZl9l*)lh6w)Xf9zvOPGW9D8d;R; zNshpJ&aapQlv<)>v$ToTO5bR;s@nLRY>{Ziz=8vhnRRW)Xk`(S%kMUn3R|0n|tyTgJS{S6Y-xKI9tCNh`@;>L4 zK$BxO;`}yC&Fbsh2eF{N$Te35xtB|#&ge?v%4Vs1kkS(NHg zj=*}(*USM*Em5*r+Qe$5ue4fKZG1|$NVH;L!GXujy0&AqvIxoLHycWYotvG(V}v*H zrFhnH$fm;6G_}*J;63LZ`*HW>YgxN7e!e;dbSSMGtppmhFi2~ECeRyJGZn~BzkY+l zGi1qCNF|UM(%_XWf4~x-02Rd}9H)?UChVn2LsrQ|G{Fz|2{L$;b3jJ$kR*a8lfgZ? z=}AN8-Lhaz_g4C`Rl${mUOVbxR%W~l+B_K0pN^-Y{!dpt!Lyk^x1lRo4VOX7`ycJmSh)+pjnllX{#f&Am- diff --git a/testdata/d2compiler/TestCompile/import_url_link.exp.json b/testdata/d2compiler/TestCompile/import_url_link.exp.json new file mode 100644 index 0000000000..66f878da6c --- /dev/null +++ b/testdata/d2compiler/TestCompile/import_url_link.exp.json @@ -0,0 +1,106 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/import_url_link.d2,0:0:0-1:0:9", + "nodes": [ + { + "import": { + "range": "d2/testdata/d2compiler/TestCompile/import_url_link.d2,0:0:0-0:8:8", + "spread": true, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import_url_link.d2,0:4:4-0:8:8", + "value": [ + { + "string": "test", + "raw_string": "test" + } + ] + } + } + ] + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "elem", + "id_val": "elem", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/test.d2,0:0:0-0:4:4", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/test.d2,0:0:0-0:4:4", + "value": [ + { + "string": "elem", + "raw_string": "elem" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "elem" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "link": { + "value": "https://google.com" + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": null +}