Merge pull request #2434 from alixander/relative-url
d2ir: allow root URL paths
This commit is contained in:
commit
4a73ca9473
5 changed files with 169 additions and 3 deletions
|
|
@ -28,6 +28,8 @@
|
||||||
|
|
||||||
- d2cli:
|
- d2cli:
|
||||||
- Support `validate` command. [#2415](https://github.com/terrastruct/d2/pull/2415)
|
- Support `validate` command. [#2415](https://github.com/terrastruct/d2/pull/2415)
|
||||||
|
- d2compiler:
|
||||||
|
- `link`s can be set to root path, e.g. `/xyz`. [#2357](https://github.com/terrastruct/d2/issues/2357)
|
||||||
|
|
||||||
#### Bugfixes ⛑️
|
#### Bugfixes ⛑️
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1265,7 +1265,7 @@ func (c *compiler) validateBoardLinks(g *d2graph.Graph) {
|
||||||
}
|
}
|
||||||
|
|
||||||
u, err := url.Parse(html.UnescapeString(obj.Link.Value))
|
u, err := url.Parse(html.UnescapeString(obj.Link.Value))
|
||||||
isRemote := err == nil && u.Scheme != ""
|
isRemote := err == nil && (u.Scheme != "" || strings.HasPrefix(u.Path, "/"))
|
||||||
if isRemote {
|
if isRemote {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1658,6 +1658,22 @@ x -> y: {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "url_relative_link",
|
||||||
|
|
||||||
|
text: `x: {
|
||||||
|
link: /google
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
assertions: func(t *testing.T, g *d2graph.Graph) {
|
||||||
|
if len(g.Objects) != 1 {
|
||||||
|
t.Fatal(g.Objects)
|
||||||
|
}
|
||||||
|
if g.Objects[0].Link.Value != "/google" {
|
||||||
|
t.Fatal(g.Objects[0].Link.Value)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "non_url_link",
|
name: "non_url_link",
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1146,7 +1146,7 @@ func (c *compiler) extendLinks(m *Map, importF *Field, importDir string) {
|
||||||
val := f.Primary().Value.ScalarString()
|
val := f.Primary().Value.ScalarString()
|
||||||
|
|
||||||
u, err := url.Parse(html.UnescapeString(val))
|
u, err := url.Parse(html.UnescapeString(val))
|
||||||
isRemote := err == nil && u.Scheme != ""
|
isRemote := err == nil && (u.Scheme != "" || strings.HasPrefix(u.Path, "/"))
|
||||||
if isRemote {
|
if isRemote {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -1184,7 +1184,7 @@ func (c *compiler) extendLinks(m *Map, importF *Field, importDir string) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
u, err := url.Parse(html.UnescapeString(val))
|
u, err := url.Parse(html.UnescapeString(val))
|
||||||
isRemoteImg := err == nil && u.Scheme != ""
|
isRemoteImg := err == nil && (u.Scheme != "" || strings.HasPrefix(u.Path, "/"))
|
||||||
if isRemoteImg {
|
if isRemoteImg {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
148
testdata/d2compiler/TestCompile/url_relative_link.exp.json
generated
vendored
Normal file
148
testdata/d2compiler/TestCompile/url_relative_link.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,148 @@
|
||||||
|
{
|
||||||
|
"graph": {
|
||||||
|
"name": "",
|
||||||
|
"isFolderOnly": false,
|
||||||
|
"ast": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/url_relative_link.d2,0:0:0-3:0:23",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"map_key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/url_relative_link.d2,0:0:0-2:1:22",
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/url_relative_link.d2,0:0:0-0:1:1",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/url_relative_link.d2,0:0:0-0:1:1",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "x",
|
||||||
|
"raw_string": "x"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"primary": {},
|
||||||
|
"value": {
|
||||||
|
"map": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/url_relative_link.d2,0:3:3-2:1:22",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"map_key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/url_relative_link.d2,1:2:7-1:15:20",
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/url_relative_link.d2,1:2:7-1:6:11",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/url_relative_link.d2,1:2:7-1:6:11",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "link",
|
||||||
|
"raw_string": "link"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"primary": {},
|
||||||
|
"value": {
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/url_relative_link.d2,1:8:13-1:15:20",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "/google",
|
||||||
|
"raw_string": "/google"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"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": "x",
|
||||||
|
"id_val": "x",
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/url_relative_link.d2,0:0:0-0:1:1",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/url_relative_link.d2,0:0:0-0:1:1",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "x",
|
||||||
|
"raw_string": "x"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"key_path_index": 0,
|
||||||
|
"map_key_edge_index": -1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"attributes": {
|
||||||
|
"label": {
|
||||||
|
"value": "x"
|
||||||
|
},
|
||||||
|
"labelDimensions": {
|
||||||
|
"width": 0,
|
||||||
|
"height": 0
|
||||||
|
},
|
||||||
|
"style": {},
|
||||||
|
"link": {
|
||||||
|
"value": "/google"
|
||||||
|
},
|
||||||
|
"near_key": null,
|
||||||
|
"shape": {
|
||||||
|
"value": "rectangle"
|
||||||
|
},
|
||||||
|
"direction": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"constraint": null
|
||||||
|
},
|
||||||
|
"zIndex": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"err": null
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue