handle empty markdown for pre-measured

This commit is contained in:
Alexander Wang 2023-03-09 16:55:34 -08:00
parent 6670e1967c
commit adbf9f775b
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
4 changed files with 865 additions and 0 deletions

View file

@ -1164,6 +1164,10 @@ func getMarkdownDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler, t
return d2target.NewTextDimensions(width, height), nil
}
if strings.TrimSpace(t.Text) == "" {
return d2target.NewTextDimensions(1, 1), nil
}
return nil, fmt.Errorf("text not pre-measured and no ruler provided")
}

View file

@ -26,6 +26,14 @@ func testMeasured(t *testing.T) {
name: "empty-sql_table",
mtexts: []*d2target.MText{},
script: `a: "" { shape: sql_table }
`,
},
{
name: "empty-markdown",
mtexts: []*d2target.MText{},
script: `a: |md
` + " " + `
|
`,
},
}

View file

@ -0,0 +1,88 @@
{
"name": "",
"isFolderOnly": false,
"fontFamily": "SourceSansPro",
"shapes": [
{
"id": "a",
"type": "text",
"pos": {
"x": 0,
"y": 0
},
"width": 1,
"height": 1,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "transparent",
"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": " ",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "markdown",
"color": "N1",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 1,
"labelHeight": 1,
"zIndex": 0,
"level": 1
}
],
"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: 339 KiB