compiler: allow non-http scheme url links
This commit is contained in:
parent
50d048f0a8
commit
024faad406
5 changed files with 168 additions and 3 deletions
|
|
@ -10,6 +10,7 @@
|
|||
- Latex: Backslashes in Latex blocks do not escape [#2232](https://github.com/terrastruct/d2/pull/2232)
|
||||
- This is a breaking change. Previously Latex blocks required escaping the backslash. So
|
||||
for older D2 versions, you should remove the excess backslashes.
|
||||
- Links: non-http url scheme links are supported (e.g. `x.link: vscode://file/`) [#2237](https://github.com/terrastruct/d2/issues/2237)
|
||||
|
||||
#### Bugfixes ⛑️
|
||||
|
||||
|
|
|
|||
|
|
@ -1215,7 +1215,7 @@ func (c *compiler) validateBoardLinks(g *d2graph.Graph) {
|
|||
}
|
||||
|
||||
u, err := url.Parse(html.UnescapeString(obj.Link.Value))
|
||||
isRemote := err == nil && strings.HasPrefix(u.Scheme, "http")
|
||||
isRemote := err == nil && u.Scheme != ""
|
||||
if isRemote {
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1511,6 +1511,22 @@ x -> y: {
|
|||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "non_url_link",
|
||||
|
||||
text: `x: {
|
||||
link: vscode://file//Users/pmoura/logtalk/examples/searching/hill_climbing1.lgt:35:0
|
||||
}
|
||||
`,
|
||||
assertions: func(t *testing.T, g *d2graph.Graph) {
|
||||
if len(g.Objects) != 1 {
|
||||
t.Fatal(g.Objects)
|
||||
}
|
||||
if g.Objects[0].Link.Value != "vscode://file//Users/pmoura/logtalk/examples/searching/hill_climbing1.lgt:35:0" {
|
||||
t.Fatal(g.Objects[0].Link.Value)
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "import_url_link",
|
||||
|
||||
|
|
|
|||
|
|
@ -977,7 +977,7 @@ func (c *compiler) extendLinks(m *Map, importF *Field, importDir string) {
|
|||
val := f.Primary().Value.ScalarString()
|
||||
|
||||
u, err := url.Parse(html.UnescapeString(val))
|
||||
isRemote := err == nil && strings.HasPrefix(u.Scheme, "http")
|
||||
isRemote := err == nil && u.Scheme != ""
|
||||
if isRemote {
|
||||
continue
|
||||
}
|
||||
|
|
@ -1015,7 +1015,7 @@ func (c *compiler) extendLinks(m *Map, importF *Field, importDir string) {
|
|||
continue
|
||||
}
|
||||
u, err := url.Parse(html.UnescapeString(val))
|
||||
isRemoteImg := err == nil && strings.HasPrefix(u.Scheme, "http")
|
||||
isRemoteImg := err == nil && u.Scheme != ""
|
||||
if isRemoteImg {
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
148
testdata/d2compiler/TestCompile/non_url_link.exp.json
generated
vendored
Normal file
148
testdata/d2compiler/TestCompile/non_url_link.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
{
|
||||
"graph": {
|
||||
"name": "",
|
||||
"isFolderOnly": false,
|
||||
"ast": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/non_url_link.d2,0:0:0-3:0:94",
|
||||
"nodes": [
|
||||
{
|
||||
"map_key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/non_url_link.d2,0:0:0-2:1:93",
|
||||
"key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/non_url_link.d2,0:0:0-0:1:1",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/non_url_link.d2,0:0:0-0:1:1",
|
||||
"value": [
|
||||
{
|
||||
"string": "x",
|
||||
"raw_string": "x"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {
|
||||
"map": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/non_url_link.d2,0:3:3-2:1:93",
|
||||
"nodes": [
|
||||
{
|
||||
"map_key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/non_url_link.d2,1:2:7-1:86:91",
|
||||
"key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/non_url_link.d2,1:2:7-1:6:11",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/non_url_link.d2,1:2:7-1:6:11",
|
||||
"value": [
|
||||
{
|
||||
"string": "link",
|
||||
"raw_string": "link"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/non_url_link.d2,1:8:13-1:86:91",
|
||||
"value": [
|
||||
{
|
||||
"string": "vscode://file//Users/pmoura/logtalk/examples/searching/hill_climbing1.lgt:35:0",
|
||||
"raw_string": "vscode://file//Users/pmoura/logtalk/examples/searching/hill_climbing1.lgt:35:0"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"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/non_url_link.d2,0:0:0-0:1:1",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/non_url_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": "vscode://file//Users/pmoura/logtalk/examples/searching/hill_climbing1.lgt:35:0"
|
||||
},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": "rectangle"
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": null
|
||||
},
|
||||
"zIndex": 0
|
||||
}
|
||||
]
|
||||
},
|
||||
"err": null
|
||||
}
|
||||
Loading…
Reference in a new issue