From ed2efda29a0f15d5de91c615c8d522fd95804a9d Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Fri, 17 Mar 2023 20:20:30 -0700 Subject: [PATCH] don't uppercase code blocks --- d2graph/d2graph.go | 4 +- .../themes/terminal/dagre/board.exp.json | 268 ++++++++++++------ .../themes/terminal/dagre/sketch.exp.svg | 247 +++++++++------- .../themes/terminal/elk/board.exp.json | 139 +++++++-- .../themes/terminal/elk/sketch.exp.svg | 249 +++++++++------- e2etests/themes_test.go | 28 ++ 6 files changed, 624 insertions(+), 311 deletions(-) diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index ac75889f2..3b921e5d0 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -1300,7 +1300,7 @@ func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler continue } - if g.Theme != nil && g.Theme.SpecialRules.CapsLock { + if g.Theme != nil && g.Theme.SpecialRules.CapsLock && !strings.EqualFold(obj.Attributes.Shape.Value, d2target.ShapeCode) { obj.Attributes.Label.Value = strings.ToUpper(obj.Attributes.Label.Value) } @@ -1450,7 +1450,7 @@ func (g *Graph) Texts() []*d2target.MText { for _, obj := range g.Objects { if obj.Attributes.Label.Value != "" { text := obj.Text() - if capsLock { + if capsLock && !strings.EqualFold(obj.Attributes.Shape.Value, d2target.ShapeCode) { text.Text = strings.ToUpper(text.Text) } texts = appendTextDedup(texts, text) diff --git a/e2etests/testdata/themes/terminal/dagre/board.exp.json b/e2etests/testdata/themes/terminal/dagre/board.exp.json index c252796b7..f6c0822e4 100644 --- a/e2etests/testdata/themes/terminal/dagre/board.exp.json +++ b/e2etests/testdata/themes/terminal/dagre/board.exp.json @@ -11,7 +11,7 @@ "y": 438 }, "width": 480, - "height": 1225, + "height": 1565, "opacity": 1, "strokeDash": 0, "strokeWidth": 2, @@ -53,7 +53,7 @@ "y": 503 }, "width": 364, - "height": 317, + "height": 657, "opacity": 1, "strokeDash": 0, "strokeWidth": 2, @@ -92,7 +92,7 @@ "type": "stored_data", "pos": { "x": 136, - "y": 535 + "y": 705 }, "width": 161, "height": 66, @@ -133,7 +133,7 @@ "type": "rectangle", "pos": { "x": 238, - "y": 722 + "y": 1062 }, "width": 151, "height": 66, @@ -174,7 +174,7 @@ "type": "rectangle", "pos": { "x": 20, - "y": 1482 + "y": 1822 }, "width": 157, "height": 151, @@ -216,7 +216,7 @@ "type": "hexagon", "pos": { "x": 71, - "y": 1523 + "y": 1863 }, "width": 65, "height": 69, @@ -257,7 +257,7 @@ "type": "rectangle", "pos": { "x": 218, - "y": 977 + "y": 1317 }, "width": 192, "height": 182, @@ -299,7 +299,7 @@ "type": "cylinder", "pos": { "x": 258, - "y": 1009 + "y": 1349 }, "width": 112, "height": 118, @@ -381,7 +381,7 @@ "type": "rectangle", "pos": { "x": 521, - "y": 1239 + "y": 1579 }, "width": 142, "height": 66, @@ -422,7 +422,7 @@ "type": "page", "pos": { "x": 551, - "y": 1476 + "y": 1816 }, "width": 82, "height": 87, @@ -745,6 +745,46 @@ "labelHeight": 119, "zIndex": 0, "level": 1 + }, + { + "id": "code", + "type": "code", + "pos": { + "x": 526, + "y": 497 + }, + "width": 868, + "height": 406, + "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": "package main\n\nimport (\n\t\"fmt\"\n)\n\ntype City struct {\n\tName string\n\tPopulation int\n}\n\nfunc tellTale(city1, city2 City) {\n\tfmt.Printf(\"There were two cities, %s and %s.\\n\", city1.Name, city2.Name)\n\tfmt.Printf(\"%s had a population of %d.\\n\", city1.Name, city1.Population)\n\tfmt.Printf(\"%s had a population of %d.\\n\", city2.Name, city2.Population)\n\tfmt.Println(\"Their tales were intertwined, and their people shared many adventures.\")\n}\n\nfunc main() {\n\tcity1 := City{Name: \"CityA\", Population: 1000000}\n\tcity2 := City{Name: \"CityB\", Population: 1200000}\n\n\ttellTale(city1, city2)\n}", + "fontSize": 16, + "fontFamily": "mono", + "language": "golang", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 863, + "labelHeight": 401, + "zIndex": 0, + "level": 1 } ], "connections": [ @@ -774,20 +814,20 @@ "labelPercentage": 0, "route": [ { - "x": 201, - "y": 602 + "x": 211, + "y": 772 }, { - "x": 179, - "y": 650 + "x": 181, + "y": 956 }, { "x": 191.7, - "y": 674.2 + "y": 1014.2 }, { "x": 264.5, - "y": 723 + "y": 1063 } ], "isCurve": true, @@ -822,20 +862,20 @@ "labelPercentage": 0, "route": [ { - "x": 226, - "y": 602 + "x": 220, + "y": 772 }, { - "x": 239.8, - "y": 650 + "x": 238.6, + "y": 956 }, { "x": 252.25, - "y": 674.2 + "y": 1014.2 }, { "x": 288.25, - "y": 723 + "y": 1063 } ], "isCurve": true, @@ -870,20 +910,20 @@ "labelPercentage": 0, "route": [ { - "x": 290, - "y": 602 + "x": 238, + "y": 772 }, { - "x": 395.2, - "y": 650 + "x": 356.2, + "y": 956 }, { - "x": 407.5, - "y": 674.2 + "x": 376.35, + "y": 1014.2 }, { - "x": 351.5, - "y": 723 + "x": 338.75, + "y": 1063 } ], "isCurve": true, @@ -919,31 +959,31 @@ "route": [ { "x": 313.5, - "y": 788.5 + "y": 1128.5 }, { "x": 313.5, - "y": 814.1 + "y": 1154.1 }, { "x": 313.5, - "y": 832.6 + "y": 1172.6 }, { "x": 313.5, - "y": 850.75 + "y": 1190.75 }, { "x": 313.5, - "y": 868.9 + "y": 1208.9 }, { "x": 313.6, - "y": 955.2 + "y": 1295.2 }, { "x": 314, - "y": 1010 + "y": 1350 } ], "isCurve": true, @@ -1059,143 +1099,143 @@ }, { "x": 76.25, - "y": 463.6 + "y": 497.6 }, { "x": 76.25, - "y": 488.5 + "y": 573.5 }, { "x": 76.25, - "y": 513.4 + "y": 649.4 }, { "x": 76.25, - "y": 548.7 + "y": 752.7 }, { "x": 76.25, - "y": 576.75 + "y": 831.75 }, { "x": 76.25, - "y": 604.8 + "y": 910.8 }, { "x": 76.25, - "y": 642.2 + "y": 982.2 }, { "x": 76.25, - "y": 670.25 + "y": 1010.25 }, { "x": 76.25, - "y": 698.3 + "y": 1038.3 }, { "x": 76.25, - "y": 733.6 + "y": 1073.6 }, { "x": 76.25, - "y": 758.5 + "y": 1098.5 }, { "x": 76.25, - "y": 783.4 + "y": 1123.4 }, { "x": 76.25, - "y": 812.1 + "y": 1152.1 }, { "x": 76.25, - "y": 830.25 + "y": 1170.25 }, { "x": 76.25, - "y": 848.4 + "y": 1188.4 }, { "x": 76.25, - "y": 872.6 + "y": 1212.6 }, { "x": 76.25, - "y": 890.75 + "y": 1230.75 }, { "x": 76.25, - "y": 908.9 + "y": 1248.9 }, { "x": 76.25, - "y": 942.8 + "y": 1282.8 }, { "x": 76.25, - "y": 975.5 + "y": 1315.5 }, { "x": 76.25, - "y": 1008.2 + "y": 1348.2 }, { "x": 76.25, - "y": 1051.8 + "y": 1391.8 }, { "x": 76.25, - "y": 1084.5 + "y": 1424.5 }, { "x": 76.25, - "y": 1117.2 + "y": 1457.2 }, { "x": 76.25, - "y": 1149 + "y": 1489 }, { "x": 76.25, - "y": 1164 + "y": 1504 }, { "x": 76.25, - "y": 1179 + "y": 1519 }, { "x": 76.25, - "y": 1205.6 + "y": 1545.6 }, { "x": 76.25, - "y": 1230.5 + "y": 1570.5 }, { "x": 76.25, - "y": 1255.4 + "y": 1595.4 }, { "x": 76.25, - "y": 1290.7 + "y": 1630.7 }, { "x": 76.25, - "y": 1318.75 + "y": 1658.75 }, { "x": 76.25, - "y": 1346.8 + "y": 1686.8 }, { "x": 79.6, - "y": 1445.6 + "y": 1785.6 }, { "x": 93, - "y": 1524 + "y": 1864 } ], "isCurve": true, @@ -1231,19 +1271,19 @@ "route": [ { "x": 520.5, - "y": 1286.4080303852415 + "y": 1626.4080303852415 }, { "x": 208.7, - "y": 1349.6816060770484 + "y": 1689.6816060770484 }, { "x": 127.4, - "y": 1445.6 + "y": 1785.6 }, { "x": 114, - "y": 1524 + "y": 1864 } ], "isCurve": true, @@ -1279,19 +1319,19 @@ "route": [ { "x": 591.5, - "y": 1305 + "y": 1645 }, { "x": 591.5, - "y": 1353.4 + "y": 1693.4 }, { "x": 591.6, - "y": 1436 + "y": 1776 }, { "x": 592, - "y": 1476 + "y": 1816 } ], "isCurve": true, @@ -1327,19 +1367,79 @@ "route": [ { "x": 313.5, - "y": 1159.5 + "y": 1499.5 }, { "x": 313.5, - "y": 1183.1 + "y": 1523.1 }, { "x": 354.9, - "y": 1201.3604316546762 + "y": 1541.3604316546762 }, { "x": 520.5, - "y": 1250.8021582733813 + "y": 1590.8021582733813 + } + ], + "isCurve": true, + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "(markdown -> code)[0]", + "src": "markdown", + "srcArrow": "none", + "srcLabel": "", + "dst": "code", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "B1", + "label": "", + "fontSize": 16, + "fontFamily": "mono", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 959.5, + "y": 198.5 + }, + { + "x": 959.5, + "y": 308.9 + }, + { + "x": 959.5, + "y": 348.6 + }, + { + "x": 959.5, + "y": 366.75 + }, + { + "x": 959.5, + "y": 384.9 + }, + { + "x": 959.5, + "y": 457 + }, + { + "x": 959.5, + "y": 497 } ], "isCurve": true, diff --git a/e2etests/testdata/themes/terminal/dagre/sketch.exp.svg b/e2etests/testdata/themes/terminal/dagre/sketch.exp.svg index 241601ee4..868d2949a 100644 --- a/e2etests/testdata/themes/terminal/dagre/sketch.exp.svg +++ b/e2etests/testdata/themes/terminal/dagre/sketch.exp.svg @@ -1,23 +1,30 @@ - \ No newline at end of file diff --git a/e2etests/testdata/themes/terminal/elk/board.exp.json b/e2etests/testdata/themes/terminal/elk/board.exp.json index f91bc7198..2f2cac771 100644 --- a/e2etests/testdata/themes/terminal/elk/board.exp.json +++ b/e2etests/testdata/themes/terminal/elk/board.exp.json @@ -8,7 +8,7 @@ "type": "rectangle", "pos": { "x": 12, - "y": 524 + "y": 909 }, "width": 611, "height": 902, @@ -50,7 +50,7 @@ "type": "rectangle", "pos": { "x": 62, - "y": 574 + "y": 959 }, "width": 261, "height": 413, @@ -92,7 +92,7 @@ "type": "stored_data", "pos": { "x": 112, - "y": 624 + "y": 1009 }, "width": 161, "height": 66, @@ -133,7 +133,7 @@ "type": "rectangle", "pos": { "x": 117, - "y": 871 + "y": 1256 }, "width": 151, "height": 66, @@ -174,7 +174,7 @@ "type": "rectangle", "pos": { "x": 343, - "y": 579 + "y": 964 }, "width": 230, "height": 169, @@ -216,7 +216,7 @@ "type": "hexagon", "pos": { "x": 418, - "y": 629 + "y": 1014 }, "width": 80, "height": 69, @@ -257,7 +257,7 @@ "type": "rectangle", "pos": { "x": 70, - "y": 1158 + "y": 1543 }, "width": 245, "height": 218, @@ -299,7 +299,7 @@ "type": "cylinder", "pos": { "x": 136, - "y": 1208 + "y": 1593 }, "width": 112, "height": 118, @@ -422,7 +422,7 @@ "type": "page", "pos": { "x": 703, - "y": 524 + "y": 909 }, "width": 82, "height": 87, @@ -711,7 +711,7 @@ "type": "text", "pos": { "x": 1243, - "y": 90 + "y": 169 }, "width": 128, "height": 119, @@ -745,6 +745,46 @@ "labelHeight": 119, "zIndex": 0, "level": 1 + }, + { + "id": "code", + "type": "code", + "pos": { + "x": 873, + "y": 418 + }, + "width": 868, + "height": 406, + "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": "package main\n\nimport (\n\t\"fmt\"\n)\n\ntype City struct {\n\tName string\n\tPopulation int\n}\n\nfunc tellTale(city1, city2 City) {\n\tfmt.Printf(\"There were two cities, %s and %s.\\n\", city1.Name, city2.Name)\n\tfmt.Printf(\"%s had a population of %d.\\n\", city1.Name, city1.Population)\n\tfmt.Printf(\"%s had a population of %d.\\n\", city2.Name, city2.Population)\n\tfmt.Println(\"Their tales were intertwined, and their people shared many adventures.\")\n}\n\nfunc main() {\n\tcity1 := City{Name: \"CityA\", Population: 1000000}\n\tcity2 := City{Name: \"CityB\", Population: 1200000}\n\n\ttellTale(city1, city2)\n}", + "fontSize": 16, + "fontFamily": "mono", + "language": "golang", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 863, + "labelHeight": 401, + "zIndex": 0, + "level": 1 } ], "connections": [ @@ -775,11 +815,11 @@ "route": [ { "x": 143, - "y": 690 + "y": 1075 }, { "x": 143.5, - "y": 871 + "y": 1256 } ], "animated": false, @@ -814,11 +854,11 @@ "route": [ { "x": 192, - "y": 690 + "y": 1075 }, { "x": 192.5, - "y": 871 + "y": 1256 } ], "animated": false, @@ -853,11 +893,11 @@ "route": [ { "x": 241, - "y": 690 + "y": 1075 }, { "x": 241.5, - "y": 871 + "y": 1256 } ], "animated": false, @@ -892,11 +932,11 @@ "route": [ { "x": 192.5, - "y": 937 + "y": 1322 }, { "x": 193, - "y": 1208 + "y": 1593 } ], "animated": false, @@ -943,7 +983,7 @@ }, { "x": 214.08333333333337, - "y": 574 + "y": 959 } ], "animated": false, @@ -981,16 +1021,16 @@ "y": 262 }, { - "x": 343.8333333333333, - "y": 479 + "x": 343.83333333333337, + "y": 864 }, { "x": 444.6666666666667, - "y": 479 + "y": 864 }, { "x": 445, - "y": 629 + "y": 1014 } ], "animated": false, @@ -1029,15 +1069,15 @@ }, { "x": 573.3333333333334, - "y": 479 + "y": 864 }, { "x": 471.33333333333337, - "y": 479 + "y": 864 }, { "x": 471, - "y": 629 + "y": 1014 } ], "animated": false, @@ -1084,7 +1124,7 @@ }, { "x": 744, - "y": 524 + "y": 909 } ], "animated": false, @@ -1119,15 +1159,15 @@ "route": [ { "x": 136.5, - "y": 1376 + "y": 1761 }, { "x": 136.5, - "y": 1471 + "y": 1856 }, { "x": 663, - "y": 1471 + "y": 1856 }, { "x": 663, @@ -1146,6 +1186,45 @@ "tooltip": "", "icon": null, "zIndex": 0 + }, + { + "id": "(markdown -> code)[0]", + "src": "markdown", + "srcArrow": "none", + "srcLabel": "", + "dst": "code", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "B1", + "label": "", + "fontSize": 16, + "fontFamily": "mono", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 1307.8333333333333, + "y": 288 + }, + { + "x": 1307.8333333333333, + "y": 418 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 } ], "root": { diff --git a/e2etests/testdata/themes/terminal/elk/sketch.exp.svg b/e2etests/testdata/themes/terminal/elk/sketch.exp.svg index db42a341e..ba67e8cc5 100644 --- a/e2etests/testdata/themes/terminal/elk/sketch.exp.svg +++ b/e2etests/testdata/themes/terminal/elk/sketch.exp.svg @@ -1,23 +1,30 @@ - \ No newline at end of file diff --git a/e2etests/themes_test.go b/e2etests/themes_test.go index 8eea208fc..d44bcf760 100644 --- a/e2etests/themes_test.go +++ b/e2etests/themes_test.go @@ -77,6 +77,34 @@ markdown: |md - of - two cities | +code: |go +package main + +import ( + "fmt" +) + +type City struct { + Name string + Population int +} + +func tellTale(city1, city2 City) { + fmt.Printf("There were two cities, %s and %s.\n", city1.Name, city2.Name) + fmt.Printf("%s had a population of %d.\n", city1.Name, city1.Population) + fmt.Printf("%s had a population of %d.\n", city2.Name, city2.Population) + fmt.Println("Their tales were intertwined, and their people shared many adventures.") +} + +func main() { + city1 := City{Name: "CityA", Population: 1000000} + city2 := City{Name: "CityB", Population: 1200000} + + tellTale(city1, city2) +} +| + +markdown -> code `, }, {