From f2603b39ef55aa0789da4d67ecc5cde4939c6b4e Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Fri, 25 Nov 2022 16:17:14 -0800 Subject: [PATCH] cleanup --- ci/release/changelogs/next.md | 3 +-- d2renderers/textmeasure/markdown.go | 9 ++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index bc726434d..00eefa603 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -12,5 +12,4 @@ - System dark mode was incorrectly applying to markdown in renders. [#159](https://github.com/terrastruct/d2/issues/159) - Fixes markdown newlines created with a trailing double space or backslash. - [#212](https://github.com/terrastruct/d2/issues/212) - [#209](https://github.com/terrastruct/d2/issues/209) + [#214](https://github.com/terrastruct/d2/pull/214) diff --git a/d2renderers/textmeasure/markdown.go b/d2renderers/textmeasure/markdown.go index 60154dbe7..056af2f77 100644 --- a/d2renderers/textmeasure/markdown.go +++ b/d2renderers/textmeasure/markdown.go @@ -201,7 +201,7 @@ func (b *blockAttrs) isNotEmpty() bool { } // measures node dimensions to match rendering with styles in github-markdown.css -func (ruler *Ruler) measureNode(depth int, n *html.Node, font d2fonts.Font) (block blockAttrs) { +func (ruler *Ruler) measureNode(depth int, n *html.Node, font d2fonts.Font) blockAttrs { var parentElementType string if n.Parent != nil && n.Parent.Type == html.ElementNode { parentElementType = n.Parent.Data @@ -210,7 +210,7 @@ func (ruler *Ruler) measureNode(depth int, n *html.Node, font d2fonts.Font) (blo switch n.Type { case html.TextNode: if strings.TrimSpace(n.Data) == "" { - return + return blockAttrs{} } spaceWidths := 0. @@ -272,6 +272,8 @@ func (ruler *Ruler) measureNode(depth int, n *html.Node, font d2fonts.Font) (blo isCode = true } + block := blockAttrs{} + if n.FirstChild != nil { first := getNext(n.FirstChild) last := getPrev(n.LastChild) @@ -398,6 +400,7 @@ func (ruler *Ruler) measureNode(depth int, n *html.Node, font d2fonts.Font) (blo if block.height > 0 && block.height < MarkdownLineHeightPx { block.height = MarkdownLineHeightPx } + return block } - return block + return blockAttrs{} }