Merge pull request #650 from alixander/ignore-lexer-not-found
render code snippets: fallback lexer if none found
This commit is contained in:
commit
180bef5d0e
7 changed files with 205 additions and 1 deletions
|
|
@ -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 ⛑️
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -302,6 +302,13 @@ k8s -> osvc: keycloak
|
|||
k8s -> osvc: heptapod
|
||||
k8s -> osvc: harbor
|
||||
k8s -> osvc: vault
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "no-lexer",
|
||||
script: `x: |d2
|
||||
x -> y
|
||||
|
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
46
e2etests/testdata/regression/no-lexer/dagre/board.exp.json
generated
vendored
Normal file
46
e2etests/testdata/regression/no-lexer/dagre/board.exp.json
generated
vendored
Normal 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": []
|
||||
}
|
||||
52
e2etests/testdata/regression/no-lexer/dagre/sketch.exp.svg
vendored
Normal file
52
e2etests/testdata/regression/no-lexer/dagre/sketch.exp.svg
vendored
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 182 KiB |
46
e2etests/testdata/regression/no-lexer/elk/board.exp.json
generated
vendored
Normal file
46
e2etests/testdata/regression/no-lexer/elk/board.exp.json
generated
vendored
Normal 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": []
|
||||
}
|
||||
52
e2etests/testdata/regression/no-lexer/elk/sketch.exp.svg
vendored
Normal file
52
e2etests/testdata/regression/no-lexer/elk/sketch.exp.svg
vendored
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 182 KiB |
Loading…
Reference in a new issue