Merge pull request #650 from alixander/ignore-lexer-not-found

render code snippets: fallback lexer if none found
This commit is contained in:
Alexander Wang 2023-01-12 00:09:13 -08:00 committed by GitHub
commit 180bef5d0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 205 additions and 1 deletions

View file

@ -3,5 +3,6 @@
#### Improvements 🧹
- ELK layouts tuned to have better defaults. [#627](https://github.com/terrastruct/d2/pull/627)
- Code snippets of unrecognized languages will render (just without syntax highlighting). [#650](https://github.com/terrastruct/d2/pull/650)
#### Bugfixes ⛑️

View file

@ -807,7 +807,7 @@ func drawShape(writer io.Writer, targetShape d2target.Shape, sketchRunner *d2ske
if targetShape.Type == d2target.ShapeCode {
lexer := lexers.Get(targetShape.Language)
if lexer == nil {
return labelMask, fmt.Errorf("code snippet lexer for %s not found", targetShape.Language)
lexer = lexers.Fallback
}
style := styles.Get("github")
if style == nil {

View file

@ -302,6 +302,13 @@ k8s -> osvc: keycloak
k8s -> osvc: heptapod
k8s -> osvc: harbor
k8s -> osvc: vault
`,
},
{
name: "no-lexer",
script: `x: |d2
x -> y
|
`,
},
}

View file

@ -0,0 +1,46 @@
{
"name": "",
"fontFamily": "SourceSansPro",
"shapes": [
{
"id": "x",
"type": "code",
"pos": {
"x": 0,
"y": 0
},
"width": 73,
"height": 38,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "#FFFFFF",
"stroke": "#0A0F25",
"shadow": false,
"3d": false,
"multiple": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "x -> y",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "d2",
"color": "#0A0F25",
"italic": false,
"bold": true,
"underline": false,
"labelWidth": 73,
"labelHeight": 38,
"zIndex": 0,
"level": 1
}
],
"connections": []
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 182 KiB

View file

@ -0,0 +1,46 @@
{
"name": "",
"fontFamily": "SourceSansPro",
"shapes": [
{
"id": "x",
"type": "code",
"pos": {
"x": 12,
"y": 12
},
"width": 73,
"height": 38,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "#FFFFFF",
"stroke": "#0A0F25",
"shadow": false,
"3d": false,
"multiple": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "x -> y",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "d2",
"color": "#0A0F25",
"italic": false,
"bold": true,
"underline": false,
"labelWidth": 73,
"labelHeight": 38,
"zIndex": 0,
"level": 1
}
],
"connections": []
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 182 KiB