Merge pull request #2031 from alixander/fix-shebang

render: fix invalid svg from code block edge case
This commit is contained in:
Alexander Wang 2024-07-31 11:06:15 -06:00 committed by GitHub
commit f3ee9fa43c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 524 additions and 2 deletions

View file

@ -20,3 +20,4 @@
- Fix importing a file with underscores in links [#1999](https://github.com/terrastruct/d2/pull/1999) - Fix importing a file with underscores in links [#1999](https://github.com/terrastruct/d2/pull/1999)
- Replace a panic with an error message resulting from invalid `link` usage [#2011](https://github.com/terrastruct/d2/pull/2011) - Replace a panic with an error message resulting from invalid `link` usage [#2011](https://github.com/terrastruct/d2/pull/2011)
- Fix globs not applying to scenarios on keys that were applied in earlier scenarios [#2021](https://github.com/terrastruct/d2/pull/2021) - Fix globs not applying to scenarios on keys that were applied in earlier scenarios [#2021](https://github.com/terrastruct/d2/pull/2021)
- Fix edge case of invalid SVG from code blocks [#2031](https://github.com/terrastruct/d2/pull/2031)

View file

@ -49,8 +49,23 @@ func styleAttr(styles map[chroma.TokenType]string, tt chroma.TokenType) string {
} }
} }
// Custom code // Custom code
out := strings.Replace(styles[tt], `font-weight="bold"`, `class="text-mono-bold"`, -1) out := styles[tt]
return strings.Replace(out, `font-style="italic"`, `class="text-mono-italic"`, -1) classes := []string{}
if strings.Contains(out, `font-weight="bold"`) {
out = strings.Replace(out, `font-weight="bold"`, ``, 1)
classes = append(classes, "text-mono-bold")
}
if strings.Contains(out, `font-style="italic"`) {
out = strings.Replace(out, `font-style="italic"`, ``, 1)
classes = append(classes, "text-mono-italic")
}
if len(classes) > 0 {
out += `class="` + strings.Join(classes, " ") + `"`
}
return strings.TrimSpace(out)
} }
// <<< END // <<< END

View file

@ -2834,6 +2834,16 @@ y: profits {
icon.near: outside-bottom-center icon.near: outside-bottom-center
} }
`, `,
},
{
name: "shebang-codeblock",
script: `
"test.sh": {
someid: |sh
#!/usr/bin/env bash
echo testing
|
}`,
}, },
loadFromFile(t, "arrowhead_scaling"), loadFromFile(t, "arrowhead_scaling"),
loadFromFile(t, "teleport_grid"), loadFromFile(t, "teleport_grid"),

View file

@ -0,0 +1,129 @@
{
"name": "",
"isFolderOnly": false,
"fontFamily": "SourceSansPro",
"shapes": [
{
"id": "\"test.sh\"",
"type": "rectangle",
"pos": {
"x": 10,
"y": 20
},
"width": 259,
"height": 117,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "B4",
"stroke": "B1",
"shadow": false,
"3d": false,
"multiple": false,
"double-border": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "test.sh",
"fontSize": 28,
"fontFamily": "DEFAULT",
"language": "",
"color": "N1",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 78,
"labelHeight": 36,
"labelPosition": "OUTSIDE_TOP_CENTER",
"zIndex": 0,
"level": 1
},
{
"id": "\"test.sh\".someid",
"type": "code",
"pos": {
"x": 40,
"y": 50
},
"width": 199,
"height": 57,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "N7",
"stroke": "N1",
"shadow": false,
"3d": false,
"multiple": false,
"double-border": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "#!/usr/bin/env bash\necho testing",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "sh",
"color": "N1",
"italic": false,
"bold": true,
"underline": false,
"labelWidth": 183,
"labelHeight": 41,
"zIndex": 0,
"level": 2
}
],
"connections": [],
"root": {
"id": "",
"type": "",
"pos": {
"x": 0,
"y": 0
},
"width": 0,
"height": 0,
"opacity": 0,
"strokeDash": 0,
"strokeWidth": 0,
"borderRadius": 0,
"fill": "N7",
"stroke": "",
"shadow": false,
"3d": false,
"multiple": false,
"double-border": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 0,
"labelHeight": 0,
"zIndex": 0,
"level": 0
}
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 26 KiB

View file

@ -0,0 +1,129 @@
{
"name": "",
"isFolderOnly": false,
"fontFamily": "SourceSansPro",
"shapes": [
{
"id": "\"test.sh\"",
"type": "rectangle",
"pos": {
"x": 12,
"y": 12
},
"width": 299,
"height": 157,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "B4",
"stroke": "B1",
"shadow": false,
"3d": false,
"multiple": false,
"double-border": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "test.sh",
"fontSize": 28,
"fontFamily": "DEFAULT",
"language": "",
"color": "N1",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 78,
"labelHeight": 36,
"labelPosition": "INSIDE_TOP_CENTER",
"zIndex": 0,
"level": 1
},
{
"id": "\"test.sh\".someid",
"type": "code",
"pos": {
"x": 62,
"y": 62
},
"width": 199,
"height": 57,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "N7",
"stroke": "N1",
"shadow": false,
"3d": false,
"multiple": false,
"double-border": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "#!/usr/bin/env bash\necho testing",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "sh",
"color": "N1",
"italic": false,
"bold": true,
"underline": false,
"labelWidth": 183,
"labelHeight": 41,
"zIndex": 0,
"level": 2
}
],
"connections": [],
"root": {
"id": "",
"type": "",
"pos": {
"x": 0,
"y": 0
},
"width": 0,
"height": 0,
"opacity": 0,
"strokeDash": 0,
"strokeWidth": 0,
"borderRadius": 0,
"fill": "N7",
"stroke": "",
"shadow": false,
"3d": false,
"multiple": false,
"double-border": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 0,
"labelHeight": 0,
"zIndex": 0,
"level": 0
}
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 26 KiB