From 5493558e58d1aff25b0988bbb22f53b7f1dc9a7a Mon Sep 17 00:00:00 2001 From: Johannes Kaufmann Date: Wed, 25 Dec 2024 11:12:50 +0100 Subject: [PATCH 1/6] add new testcases for
inside blockquote --- .../testdata/GoldenFiles/blockquote.in.html | 7 +++++++ .../commonmark/testdata/GoldenFiles/blockquote.out.md | 7 +++++++ plugin/commonmark/testdata/GoldenFiles/list.in.html | 11 +++++++++++ plugin/commonmark/testdata/GoldenFiles/list.out.md | 8 ++++++++ 4 files changed, 33 insertions(+) diff --git a/plugin/commonmark/testdata/GoldenFiles/blockquote.in.html b/plugin/commonmark/testdata/GoldenFiles/blockquote.in.html index 81d6ac2..592a464 100644 --- a/plugin/commonmark/testdata/GoldenFiles/blockquote.in.html +++ b/plugin/commonmark/testdata/GoldenFiles/blockquote.in.html @@ -12,6 +12,13 @@
+ + + +
Line A
Line B
+ + +

Start Line




diff --git a/plugin/commonmark/testdata/GoldenFiles/blockquote.out.md b/plugin/commonmark/testdata/GoldenFiles/blockquote.out.md index bffdddc..c4b4bdd 100644 --- a/plugin/commonmark/testdata/GoldenFiles/blockquote.out.md +++ b/plugin/commonmark/testdata/GoldenFiles/blockquote.out.md @@ -4,6 +4,13 @@ + + +> Line A +Line B + + + > Start Line > > End Line diff --git a/plugin/commonmark/testdata/GoldenFiles/list.in.html b/plugin/commonmark/testdata/GoldenFiles/list.in.html index c65903e..f422973 100644 --- a/plugin/commonmark/testdata/GoldenFiles/list.in.html +++ b/plugin/commonmark/testdata/GoldenFiles/list.in.html @@ -85,6 +85,17 @@
+ +
    +
  1. +
    Line A
    Line B
    +
  2. +
+ + +
+ +
  1. one
  2. diff --git a/plugin/commonmark/testdata/GoldenFiles/list.out.md b/plugin/commonmark/testdata/GoldenFiles/list.out.md index ef9d811..20fda74 100644 --- a/plugin/commonmark/testdata/GoldenFiles/list.out.md +++ b/plugin/commonmark/testdata/GoldenFiles/list.out.md @@ -54,6 +54,14 @@ List Item without Container * * * + + +1. > Line A + + Line B + +* * * + 1. one From e40d875cb4b7450341dd240177ba30b19ca54c6c Mon Sep 17 00:00:00 2001 From: Johannes Kaufmann Date: Wed, 25 Dec 2024 11:17:22 +0100 Subject: [PATCH 2/6] render
    directly as hard-line-break --- plugin/commonmark/commonmark_test.go | 2 +- plugin/commonmark/render_break.go | 8 +++--- .../testdata/GoldenFiles/blockquote.out.md | 9 ++++++- .../testdata/GoldenFiles/heading.out.md | 3 --- .../testdata/GoldenFiles/image.out.md | 2 +- .../testdata/GoldenFiles/link.out.md | 27 +++++++++++++++++-- .../testdata/GoldenFiles/list.out.md | 17 ++++++++---- .../testdata/GoldenFiles/metadata.out.md | 8 ++++-- 8 files changed, 58 insertions(+), 18 deletions(-) diff --git a/plugin/commonmark/commonmark_test.go b/plugin/commonmark/commonmark_test.go index cac0159..bff3c5c 100644 --- a/plugin/commonmark/commonmark_test.go +++ b/plugin/commonmark/commonmark_test.go @@ -152,7 +152,7 @@ func TestOptionFunc(t *testing.T) { commonmark.WithHeadingStyle("setext"), }, input: `

    important
    heading

    `, - expected: "important\n\\\nheading\n=========", + expected: "important\nheading\n=========", }, // - - - - - - - - - - Link - - - - - - - - - - // diff --git a/plugin/commonmark/render_break.go b/plugin/commonmark/render_break.go index 7cb32c1..fe18710 100644 --- a/plugin/commonmark/render_break.go +++ b/plugin/commonmark/render_break.go @@ -2,12 +2,14 @@ package commonmark import ( "github.com/JohannesKaufmann/html-to-markdown/v2/converter" - "github.com/JohannesKaufmann/html-to-markdown/v2/marker" "golang.org/x/net/html" ) func (c *commonmark) renderBreak(_ converter.Context, w converter.Writer, _ *html.Node) converter.RenderStatus { - w.Write(marker.BytesMarkerLineBreak) - w.Write(marker.BytesMarkerLineBreak) + // w.Write(marker.BytesMarkerLineBreak) + // w.Write(marker.BytesMarkerLineBreak) + // w.WriteString("\n") + + w.WriteString(" \n") return converter.RenderSuccess } diff --git a/plugin/commonmark/testdata/GoldenFiles/blockquote.out.md b/plugin/commonmark/testdata/GoldenFiles/blockquote.out.md index c4b4bdd..7803195 100644 --- a/plugin/commonmark/testdata/GoldenFiles/blockquote.out.md +++ b/plugin/commonmark/testdata/GoldenFiles/blockquote.out.md @@ -7,12 +7,19 @@ > Line A -Line B +> Line B > Start Line > +> +> +> +> +> +> +> > End Line diff --git a/plugin/commonmark/testdata/GoldenFiles/heading.out.md b/plugin/commonmark/testdata/GoldenFiles/heading.out.md index c190577..390bf46 100644 --- a/plugin/commonmark/testdata/GoldenFiles/heading.out.md +++ b/plugin/commonmark/testdata/GoldenFiles/heading.out.md @@ -105,7 +105,6 @@ not title * * * > [**Heading 2** -> \ > **Heading 5**](/page.html) * * * @@ -113,9 +112,7 @@ not title > [**Heading 2** > \ > Description Line 1 -> \ > Description Line 2 -> \ > Description Line 3 > \ > "Some quote"](/page.html) diff --git a/plugin/commonmark/testdata/GoldenFiles/image.out.md b/plugin/commonmark/testdata/GoldenFiles/image.out.md index 6a533ba..935d04a 100644 --- a/plugin/commonmark/testdata/GoldenFiles/image.out.md +++ b/plugin/commonmark/testdata/GoldenFiles/image.out.md @@ -76,7 +76,7 @@ -[![image alt text](/image.jpg "image title text")](/page.html "link title text") +[![image alt text](/image.jpg "image title text")](/page.html "link title text") diff --git a/plugin/commonmark/testdata/GoldenFiles/link.out.md b/plugin/commonmark/testdata/GoldenFiles/link.out.md index 54ace99..2df083c 100644 --- a/plugin/commonmark/testdata/GoldenFiles/link.out.md +++ b/plugin/commonmark/testdata/GoldenFiles/link.out.md @@ -143,15 +143,39 @@ before [content](/) after [Start Line \ +\ +\ +\ +\ +\ +\ +\ End Line](/) + + + + [newlines around the link content](/) + + + + - [first text + \ + \ + \ + \ + \ + \ + \ + \ + \ \ second text](/) @@ -170,8 +194,7 @@ second text](/page.html) [**Heading A** -\ -**Heading B**](/page.html) +**Heading B**](/page.html) diff --git a/plugin/commonmark/testdata/GoldenFiles/list.out.md b/plugin/commonmark/testdata/GoldenFiles/list.out.md index 20fda74..b438ed6 100644 --- a/plugin/commonmark/testdata/GoldenFiles/list.out.md +++ b/plugin/commonmark/testdata/GoldenFiles/list.out.md @@ -11,8 +11,7 @@ A paragraph - - 5.1 5 After -- 6 Before - +- 6 Before 6 also Before - 6A.1 @@ -56,9 +55,8 @@ List Item without Container -1. > Line A - - Line B +1. > Line A + > Line B * * * @@ -118,6 +116,8 @@ text between + + - List 7 * * * @@ -136,6 +136,13 @@ text between - Start Line + + + + + + + End Line -[**Heading A** +[**Heading A** **Heading B**](/page.html) From 54dfab5eb4be01472ca8379775228e62e339e22a Mon Sep 17 00:00:00 2001 From: Johannes Kaufmann Date: Wed, 25 Dec 2024 12:03:20 +0100 Subject: [PATCH 4/6] remove old logic for unused marker --- internal/textutils/surrounding_spaces.go | 6 ++---- plugin/base/base.go | 3 +-- plugin/commonmark/commonmark.go | 9 --------- plugin/commonmark/render_break.go | 5 +---- plugin/commonmark/render_heading.go | 3 +-- plugin/commonmark/render_link.go | 3 +-- plugin/commonmark/render_list.go | 5 +---- 7 files changed, 7 insertions(+), 27 deletions(-) diff --git a/internal/textutils/surrounding_spaces.go b/internal/textutils/surrounding_spaces.go index 4f73623..b9b796a 100644 --- a/internal/textutils/surrounding_spaces.go +++ b/internal/textutils/surrounding_spaces.go @@ -41,18 +41,16 @@ package textutils import ( "bytes" "unicode" - - "github.com/JohannesKaufmann/html-to-markdown/v2/marker" ) func SurroundingSpaces(content []byte) ([]byte, []byte, []byte) { rightTrimmed := bytes.TrimRightFunc(content, func(r rune) bool { - return unicode.IsSpace(r) || r == marker.MarkerLineBreak + return unicode.IsSpace(r) }) rightExtra := content[len(rightTrimmed):] trimmed := bytes.TrimLeftFunc(rightTrimmed, func(r rune) bool { - return unicode.IsSpace(r) || r == marker.MarkerLineBreak + return unicode.IsSpace(r) }) leftExtra := content[0 : len(rightTrimmed)-len(trimmed)] diff --git a/plugin/base/base.go b/plugin/base/base.go index fdd1293..172ea8c 100644 --- a/plugin/base/base.go +++ b/plugin/base/base.go @@ -10,7 +10,6 @@ import ( "github.com/JohannesKaufmann/html-to-markdown/v2/collapse" "github.com/JohannesKaufmann/html-to-markdown/v2/internal/domutils" "github.com/JohannesKaufmann/html-to-markdown/v2/internal/textutils" - "github.com/JohannesKaufmann/html-to-markdown/v2/marker" "golang.org/x/net/html" ) @@ -122,7 +121,7 @@ func (b *base) handleTextTransform(ctx converter.Context, content string) string func (b *base) postRenderTrimContent(ctx converter.Context, result []byte) []byte { // Remove whitespace from the beginning & end - result = bytes.TrimFunc(result, marker.IsSpace) + result = bytes.TrimSpace(result) // Remove too many newlines result = textutils.TrimConsecutiveNewlines(result) diff --git a/plugin/commonmark/commonmark.go b/plugin/commonmark/commonmark.go index d4b7f9b..3d7e174 100644 --- a/plugin/commonmark/commonmark.go +++ b/plugin/commonmark/commonmark.go @@ -179,7 +179,6 @@ func (cm *commonmark) Init(conv *converter.Converter) error { conv.Register.TextTransformer(cm.handleTextTransform, converter.PriorityLate) conv.Register.PostRenderer(cm.handlePostRenderCodeBlockNewline, converter.PriorityLate) - conv.Register.PostRenderer(cm.handlePostRenderLineBreak, converter.PriorityStandard+10) return nil } @@ -191,14 +190,6 @@ func (cm commonmark) handlePostRenderCodeBlockNewline(ctx converter.Context, con []byte("\n"), ) } -func (cm commonmark) handlePostRenderLineBreak(ctx converter.Context, content []byte) []byte { - return bytes.ReplaceAll( - content, - // Two line break markers should be replaced with a "hard line break". - marker.BytesTWICEMarkerLineBreak, - []byte(" \n"), - ) -} func (cm commonmark) handleTextTransform(ctx converter.Context, content string) string { diff --git a/plugin/commonmark/render_break.go b/plugin/commonmark/render_break.go index fe18710..7feff53 100644 --- a/plugin/commonmark/render_break.go +++ b/plugin/commonmark/render_break.go @@ -6,10 +6,7 @@ import ( ) func (c *commonmark) renderBreak(_ converter.Context, w converter.Writer, _ *html.Node) converter.RenderStatus { - // w.Write(marker.BytesMarkerLineBreak) - // w.Write(marker.BytesMarkerLineBreak) - // w.WriteString("\n") - + // Render a "hard line break" w.WriteString(" \n") return converter.RenderSuccess } diff --git a/plugin/commonmark/render_heading.go b/plugin/commonmark/render_heading.go index ca0c92b..f307c63 100644 --- a/plugin/commonmark/render_heading.go +++ b/plugin/commonmark/render_heading.go @@ -110,7 +110,7 @@ func (c *commonmark) renderHeading(ctx converter.Context, w converter.Writer, n ctx.RenderChildNodes(ctx, &buf, n) content := buf.Bytes() - if bytes.TrimFunc(content, marker.IsSpace) == nil { + if len(bytes.TrimSpace(content)) == 0 { return converter.RenderSuccess } @@ -126,7 +126,6 @@ func (c *commonmark) renderHeading(ctx converter.Context, w converter.Writer, n w.Write(underline) w.WriteString("\n\n") } else { - content = bytes.ReplaceAll(content, marker.BytesMarkerLineBreak, []byte(" ")) content = bytes.ReplaceAll(content, []byte("\n"), []byte(" ")) content = bytes.ReplaceAll(content, []byte("\r"), []byte(" ")) // Replace multiple spaces by one space. diff --git a/plugin/commonmark/render_link.go b/plugin/commonmark/render_link.go index a1127fd..dd29ac1 100644 --- a/plugin/commonmark/render_link.go +++ b/plugin/commonmark/render_link.go @@ -7,7 +7,6 @@ import ( "github.com/JohannesKaufmann/dom" "github.com/JohannesKaufmann/html-to-markdown/v2/converter" "github.com/JohannesKaufmann/html-to-markdown/v2/internal/textutils" - "github.com/JohannesKaufmann/html-to-markdown/v2/marker" "golang.org/x/net/html" ) @@ -72,7 +71,7 @@ func (c *commonmark) renderLink(ctx converter.Context, w converter.Writer, n *ht ctx.RenderChildNodes(ctx, &buf, n) content := buf.Bytes() - if len(bytes.TrimFunc(content, marker.IsSpace)) == 0 { + if len(bytes.TrimSpace(content)) == 0 { // Fallback to the title content = []byte(l.title) } diff --git a/plugin/commonmark/render_list.go b/plugin/commonmark/render_list.go index d737960..3a1463e 100644 --- a/plugin/commonmark/render_list.go +++ b/plugin/commonmark/render_list.go @@ -9,7 +9,6 @@ import ( "github.com/JohannesKaufmann/dom" "github.com/JohannesKaufmann/html-to-markdown/v2/converter" "github.com/JohannesKaufmann/html-to-markdown/v2/internal/textutils" - "github.com/JohannesKaufmann/html-to-markdown/v2/marker" "golang.org/x/net/html" ) @@ -43,9 +42,7 @@ func (c commonmark) getPrefixFunc(n *html.Node, sliceLength int) func(int) strin } func renderMultiLineListItem(w converter.Writer, content []byte, indentCount int) { - lines := marker.SplitFunc(content, func(r rune) bool { - return r == '\n' || r == marker.MarkerLineBreak - }) + lines := bytes.Split(content, []byte("\n")) for i := range lines { if i != 0 { From ce09b2cea083ab40977242eea61f26a238395bfd Mon Sep 17 00:00:00 2001 From: Johannes Kaufmann Date: Wed, 25 Dec 2024 19:03:14 +0100 Subject: [PATCH 5/6] new logic to remove consecutive newlines --- internal/textutils/consecutive_newlines.go | 49 ++++- .../textutils/consecutive_newlines_test.go | 190 ++++++++---------- .../testdata/GoldenFiles/blockquote.out.md | 7 - .../testdata/GoldenFiles/link.out.md | 24 --- .../testdata/GoldenFiles/list.out.md | 9 - .../testdata/GoldenFiles/metadata.out.md | 4 - 6 files changed, 126 insertions(+), 157 deletions(-) diff --git a/internal/textutils/consecutive_newlines.go b/internal/textutils/consecutive_newlines.go index e520253..78b73d4 100644 --- a/internal/textutils/consecutive_newlines.go +++ b/internal/textutils/consecutive_newlines.go @@ -2,13 +2,51 @@ package textutils import ( "unicode/utf8" - - "github.com/JohannesKaufmann/html-to-markdown/v2/marker" ) +func TrimConsecutiveNewlines(input []byte) []byte { + var result []byte + newlineCount := 0 + spaceBuffer := []byte{} + + for i := 0; i < len(input); { + r, size := utf8.DecodeRune(input[i:]) + + if r == '\n' { + newlineCount++ + if newlineCount <= 2 { + // Preserve up to 2 newlines, including preceding spaces + result = append(result, spaceBuffer...) + result = append(result, '\n') + spaceBuffer = spaceBuffer[:0] // Clear space buffer + } else { + // Skip additional newlines + spaceBuffer = spaceBuffer[:0] // Clear space buffer + } + } else if r == ' ' { + // Collect spaces into the space buffer + spaceBuffer = append(spaceBuffer, input[i:i+size]...) + } else { + // Reset newline count and append non-newline characters + newlineCount = 0 + result = append(result, spaceBuffer...) + result = append(result, input[i:i+size]...) + spaceBuffer = spaceBuffer[:0] // Clear space buffer + } + + i += size + } + + // Append any trailing spaces + result = append(result, spaceBuffer...) + + return result +} + +/* func TrimConsecutiveNewlines(source []byte) []byte { // Some performance optimizations: - // - If no replacement was done, we return the original slice and dont allocate. + // - If no replacement was done, we return the original slice and don't allocate. // - We batch appends var ret []byte @@ -22,7 +60,7 @@ func TrimConsecutiveNewlines(source []byte) []byte { r, size := utf8.DecodeRune(source[i:]) _ = size - isNewline := r == '\n' || r == marker.MarkerLineBreak + isNewline := r == '\n' // || r == marker.MarkerLineBreak if isNewline { count += 1 } @@ -82,9 +120,10 @@ func TrimConsecutiveNewlines(source []byte) []byte { } if ret == nil { - // Huray, we did not do any allocations with make() + // Hurray, we did not do any allocations with make() // and instead just return the original slice. return source } return ret } +*/ diff --git a/internal/textutils/consecutive_newlines_test.go b/internal/textutils/consecutive_newlines_test.go index dda0993..6bf4b34 100644 --- a/internal/textutils/consecutive_newlines_test.go +++ b/internal/textutils/consecutive_newlines_test.go @@ -6,107 +6,69 @@ import ( ) func TestTrimConsecutiveNewlines(t *testing.T) { - runs := []struct { - desc string - input []byte - expected []byte + tests := []struct { + name string + input string + expected string }{ - { - desc: "empty", - input: []byte(""), - expected: []byte(""), - }, - { - desc: "not needed", - input: []byte("normal text"), - expected: []byte("normal text"), - }, - { - desc: "also not needed", - input: []byte("normal\n\ntext"), - expected: []byte("normal\n\ntext"), - }, + {"empty string", "", ""}, + {"single char", "a", "a"}, + {"simple text", "hello", "hello"}, + {"normal text without newlines", "hello this is a normal text", "hello this is a normal text"}, - { - desc: "just two newlines", - input: []byte("\n\n"), - expected: []byte("\n\n"), - }, - { - desc: "just three newlines", - input: []byte("\n\n\n"), - expected: []byte("\n\n"), - }, - { - desc: "just four newlines", - input: []byte("\n\n\n\n"), - expected: []byte("\n\n"), - }, + // Single newline cases + {"single newline", "a\nb", "a\nb"}, + {"single newline with spaces", "a \nb", "a \nb"}, + {"spaces after newline", "a\n b", "a\n b"}, - { - desc: "newlines before", - input: []byte("\n\n\ntext"), - expected: []byte("\n\ntext"), - }, - { - desc: "newlines after", - input: []byte("text\n\n\n"), - expected: []byte("text\n\n"), - }, - { - desc: "newlines before and after", - input: []byte("\n\n\ntext\n\n\n"), - expected: []byte("\n\ntext\n\n"), - }, - { - desc: "newlines between", - input: []byte("before\n\n\nafter"), - expected: []byte("before\n\nafter"), - }, - { - desc: "newlines between multiple times", - input: []byte("1\n\n\n2\n\n\n3"), - expected: []byte("1\n\n2\n\n3"), - }, + // Double newline cases + {"double newline", "a\n\nb", "a\n\nb"}, + {"double newline with spaces", "a \n\nb", "a \n\nb"}, + {"spaces between newlines", "a\n \nb", "a\n \nb"}, + {"spaces after double newline", "a\n\n b", "a\n\n b"}, - { - desc: "not needed the first time", - input: []byte("abc\n\nabc\n\n\nabc"), - expected: []byte("abc\n\nabc\n\nabc"), - }, - { - desc: "not needed the second time", - input: []byte("abc\n\n\nabc\n\nabc"), - expected: []byte("abc\n\nabc\n\nabc"), - }, + // Triple+ newline cases + {"triple newline", "a\n\n\nb", "a\n\nb"}, + {"quad newline", "a\n\n\n\nb", "a\n\nb"}, + {"triple newline with spaces", "a \n\n\nb", "a \n\nb"}, - { - desc: "with special characters", - input: []byte("äöü\n\n\näöü"), - expected: []byte("äöü\n\näöü"), - }, - { - desc: "space at end", - input: []byte("a\n\n\nb "), - expected: []byte("a\n\nb "), - }, - { - desc: "one newline at end", - input: []byte("a\n\n\nb\n"), - expected: []byte("a\n\nb\n"), - }, - { - desc: "two newlines at end", - input: []byte("a\n\n\nb\n\n"), - expected: []byte("a\n\nb\n\n"), - }, + // Multiple segment cases + {"multiple segments", "a\n\nb\n\nc", "a\n\nb\n\nc"}, + {"multiple segments with spaces", "a \n\nb \n\nc", "a \n\nb \n\nc"}, + + // Spaces at end of line + {"hard-line-break followed by text", "a \nb", "a \nb"}, + {"hard-line-break followed by newline", "a \n\nb", "a \n\nb"}, + + // Edge cases + {"only newlines", "\n\n\n", "\n\n"}, + {"only spaces", " ", " "}, + + {"leading and trailing newlines", "\n\n\ntext\n\n\n", "\n\ntext\n\n"}, + {"newlines and spaces", " \n \n \n \n ", " \n \n "}, + + {"leading spaces", " a", " a"}, + {"leading newline 1", "\na", "\na"}, + {"leading newline 2", "\n\na", "\n\na"}, + {"leading newline 3", "\n\n\na", "\n\na"}, + + {"trailing spaces", "a ", "a "}, + {"trailing newline 1", "a\n", "a\n"}, + {"trailing newlines 2", "a\n\n", "a\n\n"}, + {"trailing newlines 3", "a\n\n\n", "a\n\n"}, + + // UTF-8 cases + {"german special chars", "äöü\n\n\näöü", "äöü\n\näöü"}, + {"utf8 chars", "🌟\n\n\n🌟\n\n\n🌟", "🌟\n\n🌟\n\n🌟"}, } - for _, run := range runs { - t.Run(run.desc, func(t *testing.T) { - output := TrimConsecutiveNewlines(run.input) - if !bytes.Equal(output, run.expected) { - t.Errorf("expected %q but got %q", string(run.expected), string(output)) + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := string(TrimConsecutiveNewlines([]byte(tt.input))) + if got != tt.expected { + t.Errorf("\ninput: %q\nexpected: %q\ngot: %q", + tt.input, tt.expected, got, + ) } }) } @@ -115,31 +77,43 @@ func TestTrimConsecutiveNewlines(t *testing.T) { func TestTrimConsecutiveNewlines_Allocs(t *testing.T) { const N = 1000 - avg := testing.AllocsPerRun(N, func() { - input := []byte("abc") - output := TrimConsecutiveNewlines(input) - _ = output - }) - if avg != 0 { - t.Errorf("with no newlines there should be no allocations but got %f", avg) - } + var avg float64 + /* + avg = testing.AllocsPerRun(N, func() { + input := []byte("abc") + output := TrimConsecutiveNewlines(input) + _ = output + }) + if avg != 0 { + t.Errorf("with no newlines there should be no allocations but got %f", avg) + } + + avg = testing.AllocsPerRun(N, func() { + input := []byte("abc\n\nabc") + output := TrimConsecutiveNewlines(input) + _ = output + }) + if avg != 0 { + t.Errorf("with only two newlines there should be no allocations but got %f", avg) + } + */ avg = testing.AllocsPerRun(N, func() { - input := []byte("abc\n\nabc") + input := []byte("abc\n\n\nabc") output := TrimConsecutiveNewlines(input) _ = output }) - if avg != 0 { - t.Errorf("with only two newlines there should be no allocations but got %f", avg) + if avg != 1 { + t.Errorf("with three newlines there should be 1 allocation but got %f", avg) } avg = testing.AllocsPerRun(N, func() { - input := []byte("abc\n\n\nabc") + input := []byte("abc\n\n\n\n\n\nabc\n\n\n\n\n\nabc\n\n\n\n\n\nabc\n\n\n\n\n\nabc\n\n\n\n\n\nabc") output := TrimConsecutiveNewlines(input) _ = output }) - if avg != 1 { - t.Errorf("with trhee newlines there should be 1 allocation but got %f", avg) + if avg != 3 { + t.Errorf("with many newlines there should be 3 allocation but got %f", avg) } } diff --git a/plugin/commonmark/testdata/GoldenFiles/blockquote.out.md b/plugin/commonmark/testdata/GoldenFiles/blockquote.out.md index 7803195..e9f42a9 100644 --- a/plugin/commonmark/testdata/GoldenFiles/blockquote.out.md +++ b/plugin/commonmark/testdata/GoldenFiles/blockquote.out.md @@ -13,13 +13,6 @@ > Start Line > -> -> -> -> -> -> -> > End Line diff --git a/plugin/commonmark/testdata/GoldenFiles/link.out.md b/plugin/commonmark/testdata/GoldenFiles/link.out.md index e941657..23dfc27 100644 --- a/plugin/commonmark/testdata/GoldenFiles/link.out.md +++ b/plugin/commonmark/testdata/GoldenFiles/link.out.md @@ -143,39 +143,15 @@ before [content](/) after [Start Line \ -\ -\ -\ -\ -\ -\ -\ End Line](/) - - - - [newlines around the link content](/) - - - - - [first text - \ - \ - \ - \ - \ - \ - \ - \ - \ \ second text](/) diff --git a/plugin/commonmark/testdata/GoldenFiles/list.out.md b/plugin/commonmark/testdata/GoldenFiles/list.out.md index b438ed6..5e1f558 100644 --- a/plugin/commonmark/testdata/GoldenFiles/list.out.md +++ b/plugin/commonmark/testdata/GoldenFiles/list.out.md @@ -116,8 +116,6 @@ text between - - - List 7 * * * @@ -136,13 +134,6 @@ text between - Start Line - - - - - - - End Line