diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 0f1acdec8..aabaaf7b8 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -13,3 +13,4 @@ - Code blocks are not affected by uppercasing from special themes like Terminal. [#1053](https://github.com/terrastruct/d2/pull/1053) - Fixes fill-pattern replacement in the API. [#1051](https://github.com/terrastruct/d2/pull/1051) +- Fixes multiple `
` elements in a row being mismeasured in Markdown blocks. [#1060](https://github.com/terrastruct/d2/pull/1060) diff --git a/e2etests-cli/testdata/TestCLI_E2E/internal_linked_pdf.exp.pdf b/e2etests-cli/testdata/TestCLI_E2E/internal_linked_pdf.exp.pdf index 57cc95f9c..37767f237 100644 Binary files a/e2etests-cli/testdata/TestCLI_E2E/internal_linked_pdf.exp.pdf and b/e2etests-cli/testdata/TestCLI_E2E/internal_linked_pdf.exp.pdf differ diff --git a/e2etests/stable_test.go b/e2etests/stable_test.go index 30cdb8455..38641da9f 100644 --- a/e2etests/stable_test.go +++ b/e2etests/stable_test.go @@ -965,6 +965,23 @@ Here is an example of AppleScript: A code block continues until it reaches a line that is not indented (or the end of the article). `), + }, + { + name: "br", + script: `copy: |md + # Headline 1 + ## Headline 2 + Lorem ipsum dolor +
+ ## Headline 3 + Lorem ipsum dolor +
+
+ ## Headline 3 + This just disappears +
+| +`, }, { name: "giant_markdown_test", diff --git a/e2etests/testdata/stable/br/dagre/board.exp.json b/e2etests/testdata/stable/br/dagre/board.exp.json new file mode 100644 index 000000000..de21a0a3f --- /dev/null +++ b/e2etests/testdata/stable/br/dagre/board.exp.json @@ -0,0 +1,88 @@ +{ + "name": "", + "isFolderOnly": false, + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "copy", + "type": "text", + "pos": { + "x": 0, + "y": 0 + }, + "width": 150, + "height": 383, + "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": "# Headline 1\n## Headline 2\nLorem ipsum dolor\n
\n## Headline 3\nLorem ipsum dolor\n
\n
\n## Headline 3\nThis just disappears\n
", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 150, + "labelHeight": 383, + "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/stable/br/dagre/sketch.exp.svg b/e2etests/testdata/stable/br/dagre/sketch.exp.svg new file mode 100644 index 000000000..8c4635075 --- /dev/null +++ b/e2etests/testdata/stable/br/dagre/sketch.exp.svg @@ -0,0 +1,848 @@ +

Headline 1

+

Headline 2

+

Lorem ipsum dolor +

+

Headline 3

+

Lorem ipsum dolor +
+

+

Headline 3

+

This just disappears +

+
+ + +
\ No newline at end of file diff --git a/e2etests/testdata/stable/br/elk/board.exp.json b/e2etests/testdata/stable/br/elk/board.exp.json new file mode 100644 index 000000000..d23571151 --- /dev/null +++ b/e2etests/testdata/stable/br/elk/board.exp.json @@ -0,0 +1,88 @@ +{ + "name": "", + "isFolderOnly": false, + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "copy", + "type": "text", + "pos": { + "x": 12, + "y": 12 + }, + "width": 150, + "height": 383, + "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": "# Headline 1\n## Headline 2\nLorem ipsum dolor\n
\n## Headline 3\nLorem ipsum dolor\n
\n
\n## Headline 3\nThis just disappears\n
", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 150, + "labelHeight": 383, + "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/stable/br/elk/sketch.exp.svg b/e2etests/testdata/stable/br/elk/sketch.exp.svg new file mode 100644 index 000000000..e2363f8cb --- /dev/null +++ b/e2etests/testdata/stable/br/elk/sketch.exp.svg @@ -0,0 +1,848 @@ +

Headline 1

+

Headline 2

+

Lorem ipsum dolor +

+

Headline 3

+

Lorem ipsum dolor +
+

+

Headline 3

+

This just disappears +

+
+ + +
\ No newline at end of file diff --git a/lib/textmeasure/markdown.go b/lib/textmeasure/markdown.go index 52501a7ac..02a06b78a 100644 --- a/lib/textmeasure/markdown.go +++ b/lib/textmeasure/markdown.go @@ -331,6 +331,8 @@ func (ruler *Ruler) measureNode(depth int, n *html.Node, fontFamily *d2fonts.Fon } else if child.Type == html.ElementNode && child.Data == "br" { if inlineBlock != nil { endInlineBlock() + } else { + block.height += MarkdownLineHeightPx } } else if childBlock.isNotEmpty() { if inlineBlock == nil {