From fe9a5e13eee3882a65bec0bf76b2708bd78b886e Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Fri, 2 Aug 2024 08:01:26 -0600 Subject: [PATCH 1/3] language works for sequence diagram notes --- d2exporter/export.go | 6 +- d2graph/d2graph.go | 3 +- d2renderers/d2svg/d2svg.go | 88 +- .../dagre/board.exp.json | 368 ++++++++ .../dagre/sketch.exp.svg | 866 ++++++++++++++++++ .../elk/board.exp.json | 368 ++++++++ .../elk/sketch.exp.svg | 866 ++++++++++++++++++ e2etests/txtar.txt | 22 + 8 files changed, 2540 insertions(+), 47 deletions(-) create mode 100644 e2etests/testdata/txtar/sequence-diagram-note-md/dagre/board.exp.json create mode 100644 e2etests/testdata/txtar/sequence-diagram-note-md/dagre/sketch.exp.svg create mode 100644 e2etests/testdata/txtar/sequence-diagram-note-md/elk/board.exp.json create mode 100644 e2etests/testdata/txtar/sequence-diagram-note-md/elk/sketch.exp.svg diff --git a/d2exporter/export.go b/d2exporter/export.go index d01147af92..4cbd6ae601 100644 --- a/d2exporter/export.go +++ b/d2exporter/export.go @@ -164,7 +164,7 @@ func toShape(obj *d2graph.Object, g *d2graph.Graph) d2target.Shape { shape.Color = text.GetColor(shape.Italic) applyStyles(shape, obj) - switch obj.Shape.Value { + switch strings.ToLower(obj.Shape.Value) { case d2target.ShapeCode, d2target.ShapeText: shape.Language = obj.Language shape.Label = obj.Label.Value @@ -179,6 +179,10 @@ func toShape(obj *d2graph.Object, g *d2graph.Graph) d2target.Shape { if obj.ContentAspectRatio != nil { shape.ContentAspectRatio = go2.Pointer(*obj.ContentAspectRatio) } + case d2target.ShapePage: + if obj.IsSequenceDiagramNote() { + shape.Language = obj.Language + } } shape.Label = text.Text shape.LabelWidth = text.Dimensions.Width diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index 40c37e55e8..6a141b0027 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -582,8 +582,7 @@ func (obj *Object) GetFill() string { func (obj *Object) GetStroke(dashGapSize interface{}) string { shape := obj.Shape.Value - if strings.EqualFold(shape, d2target.ShapeCode) || - strings.EqualFold(shape, d2target.ShapeText) { + if obj.Language != "" { return color.N1 } if strings.EqualFold(shape, d2target.ShapeClass) || diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go index a0e2c14ad1..49d191f1a3 100644 --- a/d2renderers/d2svg/d2svg.go +++ b/d2renderers/d2svg/d2svg.go @@ -1313,7 +1313,49 @@ func drawShape(writer, appendixWriter io.Writer, diagramHash string, targetShape fontClass += " text-underline" } - if targetShape.Type == d2target.ShapeCode { + if targetShape.Language == "latex" { + render, err := d2latex.Render(targetShape.Label) + if err != nil { + return labelMask, err + } + gEl := d2themes.NewThemableElement("g", inlineTheme) + gEl.SetTranslate(float64(box.TopLeft.X), float64(box.TopLeft.Y)) + gEl.Color = targetShape.Stroke + gEl.Content = render + fmt.Fprint(writer, gEl.Render()) + } else if targetShape.Language == "markdown" { + render, err := textmeasure.RenderMarkdown(targetShape.Label) + if err != nil { + return labelMask, err + } + fmt.Fprintf(writer, ``, + box.TopLeft.X, box.TopLeft.Y, targetShape.Width, targetShape.Height, + ) + // we need the self closing form in this svg/xhtml context + render = strings.ReplaceAll(render, "
", "
") + + mdEl := d2themes.NewThemableElement("div") + mdEl.ClassName = "md" + mdEl.Content = render + + // We have to set with styles since within foreignObject, we're in html + // land and not SVG attributes + var styles []string + if targetShape.FontSize != textmeasure.MarkdownFontSize { + styles = append(styles, fmt.Sprintf("font-size:%vpx", targetShape.FontSize)) + } + if targetShape.Fill != "" && targetShape.Fill != "transparent" { + styles = append(styles, fmt.Sprintf(`background-color:%s`, targetShape.Fill)) + } + if !color.IsThemeColor(targetShape.Color) { + styles = append(styles, fmt.Sprintf(`color:%s`, targetShape.Color)) + } + + mdEl.Style = strings.Join(styles, ";") + + fmt.Fprint(writer, mdEl.Render()) + fmt.Fprint(writer, `
`) + } else if targetShape.Language != "" { lexer := lexers.Get(targetShape.Language) if lexer == nil { lexer = lexers.Fallback @@ -1377,48 +1419,6 @@ func drawShape(writer, appendixWriter io.Writer, diagramHash string, targetShape } fmt.Fprint(writer, "") } - } else if targetShape.Type == d2target.ShapeText && targetShape.Language == "latex" { - render, err := d2latex.Render(targetShape.Label) - if err != nil { - return labelMask, err - } - gEl := d2themes.NewThemableElement("g", inlineTheme) - gEl.SetTranslate(float64(box.TopLeft.X), float64(box.TopLeft.Y)) - gEl.Color = targetShape.Stroke - gEl.Content = render - fmt.Fprint(writer, gEl.Render()) - } else if targetShape.Type == d2target.ShapeText && targetShape.Language != "" { - render, err := textmeasure.RenderMarkdown(targetShape.Label) - if err != nil { - return labelMask, err - } - fmt.Fprintf(writer, ``, - box.TopLeft.X, box.TopLeft.Y, targetShape.Width, targetShape.Height, - ) - // we need the self closing form in this svg/xhtml context - render = strings.ReplaceAll(render, "
", "
") - - mdEl := d2themes.NewThemableElement("div", inlineTheme) - mdEl.ClassName = "md" - mdEl.Content = render - - // We have to set with styles since within foreignObject, we're in html - // land and not SVG attributes - var styles []string - if targetShape.FontSize != textmeasure.MarkdownFontSize { - styles = append(styles, fmt.Sprintf("font-size:%vpx", targetShape.FontSize)) - } - if targetShape.Fill != "" && targetShape.Fill != "transparent" { - styles = append(styles, fmt.Sprintf(`background-color:%s`, targetShape.Fill)) - } - if !color.IsThemeColor(targetShape.Color) { - styles = append(styles, fmt.Sprintf(`color:%s`, targetShape.Color)) - } - - mdEl.Style = strings.Join(styles, ";") - - fmt.Fprint(writer, mdEl.Render()) - fmt.Fprint(writer, `
`) } else { if targetShape.LabelFill != "" { rectEl := d2themes.NewThemableElement("rect", inlineTheme) @@ -1936,7 +1936,7 @@ func Render(diagram *d2target.Diagram, opts *RenderOpts) ([]byte, error) { hasMarkdown := false for _, s := range diagram.Shapes { - if s.Label != "" && s.Type == d2target.ShapeText { + if s.Language == "markdown" { hasMarkdown = true break } diff --git a/e2etests/testdata/txtar/sequence-diagram-note-md/dagre/board.exp.json b/e2etests/testdata/txtar/sequence-diagram-note-md/dagre/board.exp.json new file mode 100644 index 0000000000..1587ed8360 --- /dev/null +++ b/e2etests/testdata/txtar/sequence-diagram-note-md/dagre/board.exp.json @@ -0,0 +1,368 @@ +{ + "name": "", + "isFolderOnly": false, + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "x", + "type": "rectangle", + "pos": { + "x": 12, + "y": 52 + }, + "width": 100, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B5", + "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": "x", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 7, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "y", + "type": "rectangle", + "pos": { + "x": 242, + "y": 52 + }, + "width": 100, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B5", + "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": "y", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "x.x", + "type": "page", + "pos": { + "x": -128, + "y": 258 + }, + "width": 380, + "height": 119, + "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": "## A man who fishes for marlin in ponds\n\n- ...dramatic pause\n\nwill put his money in Etruscan bonds.", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 380, + "labelHeight": 119, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 5, + "level": 2 + }, + { + "id": "y.z", + "type": "page", + "pos": { + "x": 211, + "y": 447 + }, + "width": 162, + "height": 41, + "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": "\\\\lim_{h \\\\rightarrow 0 } \\\\frac{f(x+h)-f(x)}{h}", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "latex", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 162, + "labelHeight": 41, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 5, + "level": 2 + }, + { + "id": "x.z", + "type": "page", + "pos": { + "x": 10, + "y": 558 + }, + "width": 103, + "height": 37, + "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": "1 + 1 = 2", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "python", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 87, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 5, + "level": 2 + } + ], + "connections": [ + { + "id": "(x -> y)[0]", + "src": "x", + "srcArrow": "none", + "dst": "y", + "dstArrow": "triangle", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "B1", + "borderRadius": 10, + "label": "hello", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 33, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "labelPercentage": 0, + "route": [ + { + "x": 62, + "y": 188 + }, + { + "x": 292, + "y": 188 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 4 + }, + { + "id": "(x -- )[0]", + "src": "x", + "srcArrow": "none", + "dst": "x-lifeline-end-1678191278", + "dstArrow": "none", + "opacity": 1, + "strokeDash": 6, + "strokeWidth": 2, + "stroke": "B2", + "borderRadius": 10, + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 62, + "y": 118 + }, + { + "x": 62, + "y": 665 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 1 + }, + { + "id": "(y -- )[0]", + "src": "y", + "srcArrow": "none", + "dst": "y-lifeline-end-35261543", + "dstArrow": "none", + "opacity": 1, + "strokeDash": 6, + "strokeWidth": 2, + "stroke": "B2", + "borderRadius": 10, + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 292, + "y": 118 + }, + { + "x": 292, + "y": 665 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 1 + } + ], + "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 + } +} diff --git a/e2etests/testdata/txtar/sequence-diagram-note-md/dagre/sketch.exp.svg b/e2etests/testdata/txtar/sequence-diagram-note-md/dagre/sketch.exp.svg new file mode 100644 index 0000000000..d878978424 --- /dev/null +++ b/e2etests/testdata/txtar/sequence-diagram-note-md/dagre/sketch.exp.svg @@ -0,0 +1,866 @@ +xy hello

A man who fishes for marlin in ponds

+
    +
  • ...dramatic pause
  • +
+

will put his money in Etruscan bonds.

+
1 + 1 = 21 + 1 = 2 + + + + + + + +
\ No newline at end of file diff --git a/e2etests/testdata/txtar/sequence-diagram-note-md/elk/board.exp.json b/e2etests/testdata/txtar/sequence-diagram-note-md/elk/board.exp.json new file mode 100644 index 0000000000..1587ed8360 --- /dev/null +++ b/e2etests/testdata/txtar/sequence-diagram-note-md/elk/board.exp.json @@ -0,0 +1,368 @@ +{ + "name": "", + "isFolderOnly": false, + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "x", + "type": "rectangle", + "pos": { + "x": 12, + "y": 52 + }, + "width": 100, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B5", + "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": "x", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 7, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "y", + "type": "rectangle", + "pos": { + "x": 242, + "y": 52 + }, + "width": 100, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B5", + "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": "y", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "x.x", + "type": "page", + "pos": { + "x": -128, + "y": 258 + }, + "width": 380, + "height": 119, + "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": "## A man who fishes for marlin in ponds\n\n- ...dramatic pause\n\nwill put his money in Etruscan bonds.", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 380, + "labelHeight": 119, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 5, + "level": 2 + }, + { + "id": "y.z", + "type": "page", + "pos": { + "x": 211, + "y": 447 + }, + "width": 162, + "height": 41, + "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": "\\\\lim_{h \\\\rightarrow 0 } \\\\frac{f(x+h)-f(x)}{h}", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "latex", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 162, + "labelHeight": 41, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 5, + "level": 2 + }, + { + "id": "x.z", + "type": "page", + "pos": { + "x": 10, + "y": 558 + }, + "width": 103, + "height": 37, + "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": "1 + 1 = 2", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "python", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 87, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 5, + "level": 2 + } + ], + "connections": [ + { + "id": "(x -> y)[0]", + "src": "x", + "srcArrow": "none", + "dst": "y", + "dstArrow": "triangle", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "B1", + "borderRadius": 10, + "label": "hello", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 33, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "labelPercentage": 0, + "route": [ + { + "x": 62, + "y": 188 + }, + { + "x": 292, + "y": 188 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 4 + }, + { + "id": "(x -- )[0]", + "src": "x", + "srcArrow": "none", + "dst": "x-lifeline-end-1678191278", + "dstArrow": "none", + "opacity": 1, + "strokeDash": 6, + "strokeWidth": 2, + "stroke": "B2", + "borderRadius": 10, + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 62, + "y": 118 + }, + { + "x": 62, + "y": 665 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 1 + }, + { + "id": "(y -- )[0]", + "src": "y", + "srcArrow": "none", + "dst": "y-lifeline-end-35261543", + "dstArrow": "none", + "opacity": 1, + "strokeDash": 6, + "strokeWidth": 2, + "stroke": "B2", + "borderRadius": 10, + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 292, + "y": 118 + }, + { + "x": 292, + "y": 665 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 1 + } + ], + "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 + } +} diff --git a/e2etests/testdata/txtar/sequence-diagram-note-md/elk/sketch.exp.svg b/e2etests/testdata/txtar/sequence-diagram-note-md/elk/sketch.exp.svg new file mode 100644 index 0000000000..d878978424 --- /dev/null +++ b/e2etests/testdata/txtar/sequence-diagram-note-md/elk/sketch.exp.svg @@ -0,0 +1,866 @@ +xy hello

A man who fishes for marlin in ponds

+
    +
  • ...dramatic pause
  • +
+

will put his money in Etruscan bonds.

+
1 + 1 = 21 + 1 = 2 + + + + + + + +
\ No newline at end of file diff --git a/e2etests/txtar.txt b/e2etests/txtar.txt index d669dcc18a..c02d25bdc6 100644 --- a/e2etests/txtar.txt +++ b/e2etests/txtar.txt @@ -279,6 +279,7 @@ a <-> c: {style.animated: true} a <-> d: {style.animated: true} a <-> e f <-> g: {style.animated: true} +<<<<<<< HEAD:e2etests/txtar.txt x -- x: {style.animated: true} -- sequence-edge-group-tall-edge-label -- @@ -469,3 +470,24 @@ colors: { style.font-color: "linear-gradient(to bottom right, red 0%, yellow 25%, green 50%, cyan 75%, blue 100%)" } gradient -> colors +x -- x: {style.animated: true} + +-- sequence-diagram-note-md -- +shape: sequence_diagram +x -> y: hello +x.x: |md + ## A man who fishes for marlin in ponds + + - ...dramatic pause + + will put his money in Etruscan bonds. +| + +y.z: |latex + \\lim_{h \\rightarrow 0 } \\frac{f(x+h)-f(x)}{h} +| + +x.z: |python + 1 + 1 = 2 +| + From a8bf4383c28dd3a43a46edb42f914ad5710448cf Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Fri, 2 Aug 2024 15:13:29 -0600 Subject: [PATCH 2/3] save --- d2exporter/export.go | 8 +- d2graph/d2graph.go | 13 +- .../txtar/md-label/dagre/board.exp.json | 746 ++++++++++++++ .../txtar/md-label/dagre/sketch.exp.svg | 936 ++++++++++++++++++ .../txtar/md-label/elk/board.exp.json | 746 ++++++++++++++ .../txtar/md-label/elk/sketch.exp.svg | 936 ++++++++++++++++++ .../dagre/board.exp.json | 20 +- .../dagre/sketch.exp.svg | 580 +++++------ .../elk/board.exp.json | 20 +- .../elk/sketch.exp.svg | 580 +++++------ e2etests/txtar.txt | 153 +++ 11 files changed, 4123 insertions(+), 615 deletions(-) create mode 100644 e2etests/testdata/txtar/md-label/dagre/board.exp.json create mode 100644 e2etests/testdata/txtar/md-label/dagre/sketch.exp.svg create mode 100644 e2etests/testdata/txtar/md-label/elk/board.exp.json create mode 100644 e2etests/testdata/txtar/md-label/elk/sketch.exp.svg diff --git a/d2exporter/export.go b/d2exporter/export.go index 4cbd6ae601..42b20a5c69 100644 --- a/d2exporter/export.go +++ b/d2exporter/export.go @@ -144,6 +144,7 @@ func toShape(obj *d2graph.Object, g *d2graph.Graph) d2target.Shape { shape.Pos = d2target.NewPoint(int(obj.TopLeft.X), int(obj.TopLeft.Y)) shape.Width = int(obj.Width) shape.Height = int(obj.Height) + shape.Language = obj.Language text := obj.Text() shape.Bold = text.IsBold @@ -165,9 +166,6 @@ func toShape(obj *d2graph.Object, g *d2graph.Graph) d2target.Shape { applyStyles(shape, obj) switch strings.ToLower(obj.Shape.Value) { - case d2target.ShapeCode, d2target.ShapeText: - shape.Language = obj.Language - shape.Label = obj.Label.Value case d2target.ShapeClass: shape.Class = *obj.Class // The label is the header for classes and tables, which is set in client to be 4 px larger than the object's set font size @@ -179,10 +177,6 @@ func toShape(obj *d2graph.Object, g *d2graph.Graph) d2target.Shape { if obj.ContentAspectRatio != nil { shape.ContentAspectRatio = go2.Pointer(*obj.ContentAspectRatio) } - case d2target.ShapePage: - if obj.IsSequenceDiagramNote() { - shape.Language = obj.Language - } } shape.Label = text.Text shape.LabelWidth = text.Dimensions.Width diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index 6a141b0027..b4a9f594a3 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -582,7 +582,8 @@ func (obj *Object) GetFill() string { func (obj *Object) GetStroke(dashGapSize interface{}) string { shape := obj.Shape.Value - if obj.Language != "" { + if strings.EqualFold(shape, d2target.ShapeCode) || + strings.EqualFold(shape, d2target.ShapeText) { return color.N1 } if strings.EqualFold(shape, d2target.ShapeClass) || @@ -936,7 +937,9 @@ func (obj *Object) GetLabelSize(mtexts []*d2target.MText, ruler *textmeasure.Rul var dims *d2target.TextDimensions switch shapeType { - case d2target.ShapeText: + case d2target.ShapeClass: + dims = GetTextDimensions(mtexts, ruler, obj.Text(), go2.Pointer(d2fonts.SourceCodePro)) + default: if obj.Language == "latex" { width, height, err := d2latex.Measure(obj.Text().Text) if err != nil { @@ -952,12 +955,6 @@ func (obj *Object) GetLabelSize(mtexts []*d2target.MText, ruler *textmeasure.Rul } else { dims = GetTextDimensions(mtexts, ruler, obj.Text(), fontFamily) } - - case d2target.ShapeClass: - dims = GetTextDimensions(mtexts, ruler, obj.Text(), go2.Pointer(d2fonts.SourceCodePro)) - - default: - dims = GetTextDimensions(mtexts, ruler, obj.Text(), fontFamily) } if shapeType == d2target.ShapeSQLTable && obj.Label.Value == "" { diff --git a/e2etests/testdata/txtar/md-label/dagre/board.exp.json b/e2etests/testdata/txtar/md-label/dagre/board.exp.json new file mode 100644 index 0000000000..ca5395c76b --- /dev/null +++ b/e2etests/testdata/txtar/md-label/dagre/board.exp.json @@ -0,0 +1,746 @@ +{ + "name": "", + "isFolderOnly": false, + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "rectangle", + "type": "rectangle", + "pos": { + "x": 0, + "y": 68 + }, + "width": 116, + "height": 176, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B6", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "square", + "type": "rectangle", + "pos": { + "x": 176, + "y": 68 + }, + "width": 176, + "height": 176, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B6", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "page", + "type": "page", + "pos": { + "x": 412, + "y": 58 + }, + "width": 116, + "height": 197, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "AB4", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "parallelogram", + "type": "parallelogram", + "pos": { + "x": 588, + "y": 68 + }, + "width": 168, + "height": 176, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "N5", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "document", + "type": "document", + "pos": { + "x": 816, + "y": 44 + }, + "width": 116, + "height": 224, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "AB4", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "cylinder", + "type": "cylinder", + "pos": { + "x": 992, + "y": 42 + }, + "width": 116, + "height": 228, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "AA4", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "queue", + "type": "queue", + "pos": { + "x": 1168, + "y": 68 + }, + "width": 168, + "height": 176, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "N5", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "package", + "type": "package", + "pos": { + "x": 1396, + "y": 51 + }, + "width": 116, + "height": 210, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "AA4", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "step", + "type": "step", + "pos": { + "x": 1572, + "y": 51 + }, + "width": 156, + "height": 211, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "AB4", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "callout", + "type": "callout", + "pos": { + "x": 1788, + "y": 56 + }, + "width": 116, + "height": 201, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "N7", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "stored_data", + "type": "stored_data", + "pos": { + "x": 1964, + "y": 68 + }, + "width": 136, + "height": 176, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "AA4", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "person", + "type": "person", + "pos": { + "x": 2160, + "y": 68 + }, + "width": 117, + "height": 176, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B3", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "OUTSIDE_BOTTOM_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "diamond", + "type": "diamond", + "pos": { + "x": 2337, + "y": 0 + }, + "width": 172, + "height": 312, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "N4", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "oval", + "type": "oval", + "pos": { + "x": 2569, + "y": 35 + }, + "width": 136, + "height": 242, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B6", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "circle", + "type": "oval", + "pos": { + "x": 2765, + "y": 40 + }, + "width": 233, + "height": 233, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B6", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "hexagon", + "type": "hexagon", + "pos": { + "x": 3058, + "y": 39 + }, + "width": 144, + "height": 234, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "N5", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "cloud", + "type": "cloud", + "pos": { + "x": 3262, + "y": 61 + }, + "width": 212, + "height": 191, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "N7", + "stroke": "B1", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "contentAspectRatio": 0.3741391678622669, + "label": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "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 + } +} diff --git a/e2etests/testdata/txtar/md-label/dagre/sketch.exp.svg b/e2etests/testdata/txtar/md-label/dagre/sketch.exp.svg new file mode 100644 index 0000000000..53ab94c0a2 --- /dev/null +++ b/e2etests/testdata/txtar/md-label/dagre/sketch.exp.svg @@ -0,0 +1,936 @@ +

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+
+ + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/e2etests/testdata/txtar/md-label/elk/board.exp.json b/e2etests/testdata/txtar/md-label/elk/board.exp.json new file mode 100644 index 0000000000..79cc92a575 --- /dev/null +++ b/e2etests/testdata/txtar/md-label/elk/board.exp.json @@ -0,0 +1,746 @@ +{ + "name": "", + "isFolderOnly": false, + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "rectangle", + "type": "rectangle", + "pos": { + "x": 12, + "y": 80 + }, + "width": 116, + "height": 176, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B6", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "square", + "type": "rectangle", + "pos": { + "x": 148, + "y": 80 + }, + "width": 176, + "height": 176, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B6", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "page", + "type": "page", + "pos": { + "x": 344, + "y": 69 + }, + "width": 116, + "height": 197, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "AB4", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "parallelogram", + "type": "parallelogram", + "pos": { + "x": 480, + "y": 80 + }, + "width": 168, + "height": 176, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "N5", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "document", + "type": "document", + "pos": { + "x": 668, + "y": 56 + }, + "width": 116, + "height": 224, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "AB4", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "cylinder", + "type": "cylinder", + "pos": { + "x": 804, + "y": 54 + }, + "width": 116, + "height": 228, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "AA4", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "queue", + "type": "queue", + "pos": { + "x": 940, + "y": 80 + }, + "width": 168, + "height": 176, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "N5", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "package", + "type": "package", + "pos": { + "x": 1128, + "y": 63 + }, + "width": 116, + "height": 210, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "AA4", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "step", + "type": "step", + "pos": { + "x": 1264, + "y": 62 + }, + "width": 156, + "height": 211, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "AB4", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "callout", + "type": "callout", + "pos": { + "x": 1440, + "y": 67 + }, + "width": 116, + "height": 201, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "N7", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "stored_data", + "type": "stored_data", + "pos": { + "x": 1576, + "y": 80 + }, + "width": 136, + "height": 176, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "AA4", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "person", + "type": "person", + "pos": { + "x": 1732, + "y": 12 + }, + "width": 117, + "height": 176, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B3", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "OUTSIDE_BOTTOM_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "diamond", + "type": "diamond", + "pos": { + "x": 1869, + "y": 12 + }, + "width": 172, + "height": 312, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "N4", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "oval", + "type": "oval", + "pos": { + "x": 2061, + "y": 47 + }, + "width": 136, + "height": 242, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B6", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "circle", + "type": "oval", + "pos": { + "x": 2217, + "y": 51 + }, + "width": 233, + "height": 233, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B6", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "hexagon", + "type": "hexagon", + "pos": { + "x": 2470, + "y": 51 + }, + "width": 144, + "height": 234, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "N5", + "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": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "cloud", + "type": "cloud", + "pos": { + "x": 2634, + "y": 72 + }, + "width": 212, + "height": 191, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "N7", + "stroke": "B1", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "contentAspectRatio": 0.3741391678622669, + "label": "# hello\n\n- world\n\nblah blah", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 71, + "labelHeight": 131, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "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 + } +} diff --git a/e2etests/testdata/txtar/md-label/elk/sketch.exp.svg b/e2etests/testdata/txtar/md-label/elk/sketch.exp.svg new file mode 100644 index 0000000000..0e7aef9977 --- /dev/null +++ b/e2etests/testdata/txtar/md-label/elk/sketch.exp.svg @@ -0,0 +1,936 @@ +

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+

hello

+
    +
  • world
  • +
+

blah blah

+
+ + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/e2etests/testdata/txtar/sequence-diagram-note-md/dagre/board.exp.json b/e2etests/testdata/txtar/sequence-diagram-note-md/dagre/board.exp.json index 1587ed8360..4ed4a2f6e6 100644 --- a/e2etests/testdata/txtar/sequence-diagram-note-md/dagre/board.exp.json +++ b/e2etests/testdata/txtar/sequence-diagram-note-md/dagre/board.exp.json @@ -99,7 +99,7 @@ "strokeWidth": 2, "borderRadius": 0, "fill": "N7", - "stroke": "N1", + "stroke": "B1", "shadow": false, "3d": false, "multiple": false, @@ -140,7 +140,7 @@ "strokeWidth": 2, "borderRadius": 0, "fill": "N7", - "stroke": "N1", + "stroke": "B1", "shadow": false, "3d": false, "multiple": false, @@ -171,17 +171,17 @@ "id": "x.z", "type": "page", "pos": { - "x": 10, + "x": 27, "y": 558 }, - "width": 103, - "height": 37, + "width": 69, + "height": 40, "opacity": 1, "strokeDash": 0, "strokeWidth": 2, "borderRadius": 0, "fill": "N7", - "stroke": "N1", + "stroke": "B1", "shadow": false, "3d": false, "multiple": false, @@ -202,8 +202,8 @@ "italic": false, "bold": false, "underline": false, - "labelWidth": 87, - "labelHeight": 21, + "labelWidth": 53, + "labelHeight": 24, "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 5, "level": 2 @@ -278,7 +278,7 @@ }, { "x": 62, - "y": 665 + "y": 668 } ], "animated": false, @@ -316,7 +316,7 @@ }, { "x": 292, - "y": 665 + "y": 668 } ], "animated": false, diff --git a/e2etests/testdata/txtar/sequence-diagram-note-md/dagre/sketch.exp.svg b/e2etests/testdata/txtar/sequence-diagram-note-md/dagre/sketch.exp.svg index d878978424..dfd8ff0d80 100644 --- a/e2etests/testdata/txtar/sequence-diagram-note-md/dagre/sketch.exp.svg +++ b/e2etests/testdata/txtar/sequence-diagram-note-md/dagre/sketch.exp.svg @@ -1,34 +1,34 @@ -xy hello

A man who fishes for marlin in ponds

+xy hello

A man who fishes for marlin in ponds

  • ...dramatic pause

will put his money in Etruscan bonds.

-
1 + 1 = 21 + 1 = 2 - +
1 + 1 = 21 + 1 = 2 + - +
\ No newline at end of file diff --git a/e2etests/testdata/txtar/sequence-diagram-note-md/elk/board.exp.json b/e2etests/testdata/txtar/sequence-diagram-note-md/elk/board.exp.json index 1587ed8360..4ed4a2f6e6 100644 --- a/e2etests/testdata/txtar/sequence-diagram-note-md/elk/board.exp.json +++ b/e2etests/testdata/txtar/sequence-diagram-note-md/elk/board.exp.json @@ -99,7 +99,7 @@ "strokeWidth": 2, "borderRadius": 0, "fill": "N7", - "stroke": "N1", + "stroke": "B1", "shadow": false, "3d": false, "multiple": false, @@ -140,7 +140,7 @@ "strokeWidth": 2, "borderRadius": 0, "fill": "N7", - "stroke": "N1", + "stroke": "B1", "shadow": false, "3d": false, "multiple": false, @@ -171,17 +171,17 @@ "id": "x.z", "type": "page", "pos": { - "x": 10, + "x": 27, "y": 558 }, - "width": 103, - "height": 37, + "width": 69, + "height": 40, "opacity": 1, "strokeDash": 0, "strokeWidth": 2, "borderRadius": 0, "fill": "N7", - "stroke": "N1", + "stroke": "B1", "shadow": false, "3d": false, "multiple": false, @@ -202,8 +202,8 @@ "italic": false, "bold": false, "underline": false, - "labelWidth": 87, - "labelHeight": 21, + "labelWidth": 53, + "labelHeight": 24, "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 5, "level": 2 @@ -278,7 +278,7 @@ }, { "x": 62, - "y": 665 + "y": 668 } ], "animated": false, @@ -316,7 +316,7 @@ }, { "x": 292, - "y": 665 + "y": 668 } ], "animated": false, diff --git a/e2etests/testdata/txtar/sequence-diagram-note-md/elk/sketch.exp.svg b/e2etests/testdata/txtar/sequence-diagram-note-md/elk/sketch.exp.svg index d878978424..dfd8ff0d80 100644 --- a/e2etests/testdata/txtar/sequence-diagram-note-md/elk/sketch.exp.svg +++ b/e2etests/testdata/txtar/sequence-diagram-note-md/elk/sketch.exp.svg @@ -1,34 +1,34 @@ -xy hello

A man who fishes for marlin in ponds

+xy hello

A man who fishes for marlin in ponds

  • ...dramatic pause

will put his money in Etruscan bonds.

-
1 + 1 = 21 + 1 = 2 - +
1 + 1 = 21 + 1 = 2 + - +
\ No newline at end of file diff --git a/e2etests/txtar.txt b/e2etests/txtar.txt index c02d25bdc6..761d02d40b 100644 --- a/e2etests/txtar.txt +++ b/e2etests/txtar.txt @@ -491,3 +491,156 @@ x.z: |python 1 + 1 = 2 | +-- md-label -- +rectangle.shape: rectangle +rectangle: |md + # hello + + - world + + blah blah +| + +square.shape: square +square: |md + # hello + + - world + + blah blah +| + +page.shape: page +page: |md + # hello + + - world + + blah blah +| + +parallelogram.shape: parallelogram +parallelogram: |md + # hello + + - world + + blah blah +| + +document.shape: document +document: |md + # hello + + - world + + blah blah +| + +cylinder.shape: cylinder +cylinder: |md + # hello + + - world + + blah blah +| + +queue.shape: queue +queue: |md + # hello + + - world + + blah blah +| + +package.shape: package +package: |md + # hello + + - world + + blah blah +| + +step.shape: step +step: |md + # hello + + - world + + blah blah +| + +callout.shape: callout +callout: |md + # hello + + - world + + blah blah +| + +stored_data.shape: stored_data +stored_data: |md + # hello + + - world + + blah blah +| + +person.shape: person +person: |md + # hello + + - world + + blah blah +| + +diamond.shape: diamond +diamond: |md + # hello + + - world + + blah blah +| + +oval.shape: oval +oval: |md + # hello + + - world + + blah blah +| + +circle.shape: circle +circle: |md + # hello + + - world + + blah blah +| + +hexagon.shape: hexagon +hexagon: |md + # hello + + - world + + blah blah +| + +cloud.shape: cloud +cloud: |md + # hello + + - world + + blah blah +| From e9986e22106d38b79c461ab6439ee6dbc7df3525 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Fri, 8 Nov 2024 14:58:03 -0700 Subject: [PATCH 3/3] fix rebase --- d2renderers/d2svg/d2svg.go | 2 +- e2etests/txtar.txt | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go index 49d191f1a3..4c8f82fd53 100644 --- a/d2renderers/d2svg/d2svg.go +++ b/d2renderers/d2svg/d2svg.go @@ -1334,7 +1334,7 @@ func drawShape(writer, appendixWriter io.Writer, diagramHash string, targetShape // we need the self closing form in this svg/xhtml context render = strings.ReplaceAll(render, "
", "
") - mdEl := d2themes.NewThemableElement("div") + mdEl := d2themes.NewThemableElement("div", inlineTheme) mdEl.ClassName = "md" mdEl.Content = render diff --git a/e2etests/txtar.txt b/e2etests/txtar.txt index 761d02d40b..5f3dfd58f4 100644 --- a/e2etests/txtar.txt +++ b/e2etests/txtar.txt @@ -279,8 +279,6 @@ a <-> c: {style.animated: true} a <-> d: {style.animated: true} a <-> e f <-> g: {style.animated: true} -<<<<<<< HEAD:e2etests/txtar.txt -x -- x: {style.animated: true} -- sequence-edge-group-tall-edge-label -- Sequence: {