goldmark-mmd

A different way of handling Markdown Metadata
git clone git://src.gearsix.net/goldmark-mmd
Log | Files | Refs | Atom | README | LICENSE

commit e40269f191075cd0f6020f30366602c0ee8f5759
parent 91ef461d76584b602ff9e6e8ae2abb434072f3e0
Author: gearsix <gearsix@tuta.io>
Date:   Tue, 21 Feb 2023 12:28:33 +0000

fixed issue with parsing metadata

The issue was to do with returning the correct node value and advancing
the reader the correct amount (I think there was a 1-byte offset issue).

Diffstat:
Mmeta.go | 13++++++-------
Mmeta_test.go | 2+-
2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/meta.go b/meta.go @@ -118,8 +118,7 @@ func (b *metaParser) Trigger() []byte { } func (b *metaParser) Open(parent gast.Node, reader text.Reader, pc parser.Context) (gast.Node, parser.State) { - linenum, _ := reader.Position() - if linenum != 0 { + if linenum, _ := reader.Position(); linenum != 0 { return nil, parser.NoChildren } line, _ := reader.PeekLine() @@ -133,11 +132,11 @@ func (b *metaParser) Open(parent gast.Node, reader text.Reader, pc parser.Contex } node := gast.NewTextBlock() - if state := b.Continue(node, reader, pc); state == parser.Close { - parent.AppendChild(parent, node) - b.Close(node, reader, pc) + if b.Continue(node, reader, pc) != parser.Close { + return node, parser.NoChildren } - return node, parser.NoChildren + parent.AppendChild(parent, node) + b.Close(node, reader, pc) } return nil, parser.NoChildren } @@ -147,7 +146,7 @@ func (b *metaParser) Continue(node gast.Node, reader text.Reader, pc parser.Cont if n := isClose(line, b.format); n != -1 && !util.IsBlank(line) { segment.Stop -= len(line[n:]) node.Lines().Append(segment) - reader.Advance((n + 1) + len(closeToken)) + reader.Advance(n + len(closeToken) + 1) return parser.Close } node.Lines().Append(segment) diff --git a/meta_test.go b/meta_test.go @@ -56,10 +56,10 @@ func TestMeta(t *testing.T) { ), ) - var buf bytes.Buffer context := parser.NewContext() for _, format := range testMetaFormats { + var buf bytes.Buffer if err := markdown.Convert([]byte(validSource[format]), &buf, parser.WithContext(context)); err != nil { t.Fatal(err) }