parser: Refactor frontmatter parser and add tests

Lots of cleanups here:

- Refactor InterfaceToConfig and InterfaceToFrontMatter to use io.Writer.
- Simplify InterfaceToFrontMatter by wrapping InterfaceToConfig.
- Export FrontmatterType since we return it in DetectFrontMatter.
- Refactor removeTOMLIdentifier to avoid blindly replacing "+++".
- Update HandleJSONMetaData to return an empty map on nil input.
- Updates vendored goorgeous package and test for org-mode frontmatter.
- Add tests and godoc comments.

Coverage for parser package increased from 45.2% to 85.2%.
This commit is contained in:
Cameron Moore
2016-12-26 15:23:20 -06:00
committed by Bjørn Erik Pedersen
parent ddc8cc0082
commit f039e3be9e
9 changed files with 552 additions and 91 deletions

View File

@@ -1424,15 +1424,20 @@ func (p *Page) SetSourceMetaData(in interface{}, mark rune) (err error) {
}
}()
var by []byte
buf := bp.GetBuffer()
defer bp.PutBuffer(buf)
by, err = parser.InterfaceToFrontMatter(in, mark)
err = parser.InterfaceToFrontMatter(in, mark, buf)
if err != nil {
return
}
by = append(by, '\n')
p.Source.Frontmatter = by
_, err = buf.WriteRune('\n')
if err != nil {
return
}
p.Source.Frontmatter = buf.Bytes()
return
}