fix a parsing issue with input that ends with non-whitespace characters

This commit is contained in:
Daniel Kang 2019-11-14 11:29:46 -08:00
parent ea8789f650
commit f6a84f0487
2 changed files with 12 additions and 3 deletions

View file

@ -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)
}

View file

@ -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