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) lr.Advance(1)
} }
if ok && util.IsBlank(line[end.Stop:]) { if ok && util.IsBlank(lr.Source()[end.Stop:]) {
for _, attr := range attrs { for _, attr := range attrs {
node.SetAttribute(attr.Name, attr.Value) node.SetAttribute(attr.Name, attr.Value)
} }

View file

@ -1,10 +1,11 @@
package text package text
import ( import (
"github.com/yuin/goldmark/util"
"io" "io"
"regexp" "regexp"
"unicode/utf8" "unicode/utf8"
"github.com/yuin/goldmark/util"
) )
const invalidValue = -1 const invalidValue = -1
@ -83,9 +84,17 @@ type reader struct {
// NewReader return a new Reader that can read UTF-8 bytes . // NewReader return a new Reader that can read UTF-8 bytes .
func NewReader(source []byte) Reader { func NewReader(source []byte) Reader {
sourceLength := len(source)
if sourceLength > 0 {
if !util.IsSpace(source[sourceLength-1]) {
source = append(source, ' ')
sourceLength++
}
}
r := &reader{ r := &reader{
source: source, source: source,
sourceLength: len(source), sourceLength: sourceLength,
} }
r.ResetPosition() r.ResetPosition()
return r return r