diff --git a/extra_test.go b/extra_test.go index 23d3506..a9040e8 100644 --- a/extra_test.go +++ b/extra_test.go @@ -1,17 +1,34 @@ package goldmark_test import ( + "bytes" "testing" . "github.com/yuin/goldmark" - "github.com/yuin/goldmark/testutil" "github.com/yuin/goldmark/renderer/html" + "github.com/yuin/goldmark/testutil" ) -func TestDefinitionList(t *testing.T) { +func TestExtras(t *testing.T) { markdown := New(WithRendererOptions( html.WithXHTML(), html.WithUnsafe(), )) testutil.DoTestCaseFile(markdown, "_test/extra.txt", t) } + +func TestEndsWithNonSpaceCharacters(t *testing.T) { + markdown := New(WithRendererOptions( + html.WithXHTML(), + html.WithUnsafe(), + )) + source := []byte("```\na\n```") + var b bytes.Buffer + err := markdown.Convert(source, &b) + if err != nil { + t.Error(err.Error()) + } + if b.String() != "
a\n
\n" { + t.Errorf("%s \n---------\n %s", source, b.String()) + } +} diff --git a/parser/fcode_block.go b/parser/fcode_block.go index bda00ea..7216335 100644 --- a/parser/fcode_block.go +++ b/parser/fcode_block.go @@ -78,7 +78,11 @@ func (b *fencedCodeBlockParser) Continue(node ast.Node, reader text.Reader, pc C } length := i - pos if length >= fdata.length && util.IsBlank(line[i:]) { - reader.Advance(segment.Stop - segment.Start - 1 - segment.Padding) + newline := 1 + if line[len(line)-1] != '\n' { + newline = 0 + } + reader.Advance(segment.Stop - segment.Start - newline - segment.Padding) return Close } }