diff --git a/parser/atx_heading.go b/parser/atx_heading.go index dee28af..a20b4e1 100644 --- a/parser/atx_heading.go +++ b/parser/atx_heading.go @@ -223,7 +223,7 @@ func parseLastLineAttributes(node ast.Node, reader text.Reader, pc Context) { } lr.Advance(1) } - if ok && util.IsBlank(line[end.Stop:]) { + if ok && util.IsBlank(lr.Source()[end.Stop:]) { for _, attr := range attrs { node.SetAttribute(attr.Name, attr.Value) } diff --git a/text/reader.go b/text/reader.go index 0e2c3f0..7eebf52 100644 --- a/text/reader.go +++ b/text/reader.go @@ -1,10 +1,11 @@ package text import ( - "github.com/yuin/goldmark/util" "io" "regexp" "unicode/utf8" + + "github.com/yuin/goldmark/util" ) const invalidValue = -1 @@ -83,9 +84,17 @@ type reader struct { // NewReader return a new Reader that can read UTF-8 bytes . func NewReader(source []byte) Reader { + sourceLength := len(source) + if sourceLength > 0 { + if !util.IsSpace(source[sourceLength-1]) { + source = append(source, ' ') + sourceLength++ + } + } + r := &reader{ source: source, - sourceLength: len(source), + sourceLength: sourceLength, } r.ResetPosition() return r