goldmark-mmd

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

commit 7d3bdde4968ab7db50b99b84890fa8a48a1fc1a5
parent f0638e958b6012128b08195f7678d379ae7fd018
Author: yuin <yuin@inforno.net>
Date:   Sat, 31 Oct 2020 15:11:55 +0900

Fixes #3

Diffstat:
Mmeta.go | 3++-
Mmeta_test.go | 53++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/meta.go b/meta.go @@ -7,6 +7,7 @@ package meta import ( "bytes" "fmt" + "github.com/yuin/goldmark" gast "github.com/yuin/goldmark/ast" east "github.com/yuin/goldmark/extension/ast" @@ -85,7 +86,7 @@ func (b *metaParser) Open(parent gast.Node, reader text.Reader, pc parser.Contex func (b *metaParser) Continue(node gast.Node, reader text.Reader, pc parser.Context) parser.State { line, segment := reader.PeekLine() - if isSeparator(line) { + if isSeparator(line) && !util.IsBlank(line) { reader.Advance(segment.Len()) return parser.Close } diff --git a/meta_test.go b/meta_test.go @@ -2,12 +2,13 @@ package meta import ( "bytes" + "testing" + "github.com/yuin/goldmark" "github.com/yuin/goldmark/extension" "github.com/yuin/goldmark/parser" "github.com/yuin/goldmark/renderer" "github.com/yuin/goldmark/util" - "testing" ) func TestMeta(t *testing.T) { @@ -143,3 +144,53 @@ Tags: t.Error("invalid error output") } } + +func TestMetaTableWithBlankline(t *testing.T) { + markdown := goldmark.New( + goldmark.WithExtensions( + New(WithTable()), + ), + goldmark.WithRendererOptions( + renderer.WithNodeRenderers( + util.Prioritized(extension.NewTableHTMLRenderer(), 500), + ), + ), + ) + source := `--- +Title: goldmark-meta +Summary: Add YAML metadata to the document + +# comments +Tags: + - markdown + - goldmark +--- + +# Hello goldmark-meta +` + + var buf bytes.Buffer + if err := markdown.Convert([]byte(source), &buf); err != nil { + panic(err) + } + if buf.String() != `<table> +<thead> +<tr> +<th>Title</th> +<th>Summary</th> +<th>Tags</th> +</tr> +</thead> +<tbody> +<tr> +<td>goldmark-meta</td> +<td>Add YAML metadata to the document</td> +<td>[markdown goldmark]</td> +</tr> +</tbody> +</table> +<h1>Hello goldmark-meta</h1> +` { + t.Error("invalid table output") + } +}