From d89a564bb19b7d8d6c1b45e62412021c7cb59954 Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Mon, 7 Nov 2022 19:27:51 -0800 Subject: [PATCH] fix indented code block test --- d2renderers/textmeasure/markdown.go | 29 ----------------------------- e2etests/todo_test.go | 11 +++++++---- 2 files changed, 7 insertions(+), 33 deletions(-) diff --git a/d2renderers/textmeasure/markdown.go b/d2renderers/textmeasure/markdown.go index fb2145767..fbb005190 100644 --- a/d2renderers/textmeasure/markdown.go +++ b/d2renderers/textmeasure/markdown.go @@ -4,7 +4,6 @@ import ( "bytes" "math" "strings" - "unicode" "unicode/utf8" "github.com/PuerkitoBio/goquery" @@ -209,7 +208,6 @@ func (ruler *Ruler) measureNode(depth int, n *html.Node, font d2fonts.Font) (wid spaceRune, _ := utf8.DecodeRuneInString(" ") // measure will not include leading or trailing whitespace, so we have to add in the space width spaceWidth := ruler.atlases[font].glyph(spaceRune).advance - tabWidth := TAB_SIZE * spaceWidth str := n.Data @@ -234,33 +232,6 @@ func (ruler *Ruler) measureNode(depth int, n *html.Node, font d2fonts.Font) (wid spaceWidths += spaceWidth } } - } else { - isNotSpace := func(r rune) bool { - return !unicode.IsSpace(r) - } - - startIndex := strings.IndexFunc(str, isNotSpace) - endIndex := strings.LastIndexFunc(str, isNotSpace) - - if startIndex != -1 && endIndex != -1 { - for i, r := range str { - // skip over runes in middle - if i >= startIndex && i <= endIndex { - continue - } - - // measure width of leading/trailing whitespace - switch r { - case ' ': - spaceWidths += spaceWidth - case '\t': - spaceWidths += tabWidth - } - } - - str = str[startIndex : endIndex+1] - } - } if parentElementType == "pre" { diff --git a/e2etests/todo_test.go b/e2etests/todo_test.go index 61d2458e5..9ae90c4aa 100644 --- a/e2etests/todo_test.go +++ b/e2etests/todo_test.go @@ -33,10 +33,13 @@ a -> md -> b { name: "md_code_block_indented", script: `md: |md - { - indented: "block", - of: "json", - } +a line of text and an + + { + indented: "block", + of: "json", + } + | a -> md -> b `,