Mercurial > repos > public > wdown
changeset 7:a5aa39557726
Add parsing of YAML frontmatter
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 17 Jun 2020 12:23:56 +0200 |
parents | a5f397e25cb7 |
children | 4a25b534c81c 0a3841171c8f |
files | go.mod go.sum test.md test.tmpl wdown.go |
diffstat | 5 files changed, 24 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/go.mod Tue Jun 16 22:10:31 2020 +0200 +++ b/go.mod Wed Jun 17 12:23:56 2020 +0200 @@ -6,4 +6,5 @@ github.com/cbroglie/mustache v1.1.0 github.com/yuin/goldmark v1.1.32 github.com/yuin/goldmark-highlighting v0.0.0-20200307114337-60d527fdb691 + github.com/yuin/goldmark-meta v0.0.0-20191126180153-f0638e958b60 )
--- a/go.sum Tue Jun 16 22:10:31 2020 +0200 +++ b/go.sum Wed Jun 17 12:23:56 2020 +0200 @@ -58,11 +58,14 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +github.com/yuin/goldmark v1.1.7/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.22/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32 h1:5tjfNdR2ki3yYQ842+eX2sQHeiwpKJ0RnHO4IYOc4V8= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark-highlighting v0.0.0-20200307114337-60d527fdb691 h1:VWSxtAiQNh3zgHJpdpkpVYjTPqRE3P6UZCOPa1nRDio= github.com/yuin/goldmark-highlighting v0.0.0-20200307114337-60d527fdb691/go.mod h1:YLF3kDffRfUH/bTxOxHhV6lxwIB3Vfj91rEwNMS9MXo= +github.com/yuin/goldmark-meta v0.0.0-20191126180153-f0638e958b60 h1:gZucqLjL1eDzVWrXj4uiWeMbAopJlBR2mKQAsTGdPwo= +github.com/yuin/goldmark-meta v0.0.0-20191126180153-f0638e958b60/go.mod h1:i9VhcIHN2PxXMbQrKqXNueok6QNONoPjNMoj9MygVL0= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= @@ -76,4 +79,5 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
--- a/test.md Tue Jun 16 22:10:31 2020 +0200 +++ b/test.md Wed Jun 17 12:23:56 2020 +0200 @@ -1,3 +1,10 @@ +--- +title: En liten testsida +tags: + - markdown + - goldmark +--- + # Rubrik Lite text måste man ha. Och kanske en lista @@ -29,7 +36,7 @@ - [x] Add command-line argument parsing - [x] Allow template file as an input - [ ] Refactor main() to be readable - - [ ] Add possibility to have YAML metadata + - [x] Add possibility to have YAML metadata ### Code highlighting - [ ] Check of other highlighters use the same kind of coloring idea
--- a/test.tmpl Tue Jun 16 22:10:31 2020 +0200 +++ b/test.tmpl Wed Jun 17 12:23:56 2020 +0200 @@ -1,4 +1,7 @@ <html> +<head> + <title>{{title}}</title> +</head> <body> {{{content}}} </body>
--- a/wdown.go Tue Jun 16 22:10:31 2020 +0200 +++ b/wdown.go Wed Jun 17 12:23:56 2020 +0200 @@ -11,6 +11,7 @@ "github.com/cbroglie/mustache" "github.com/yuin/goldmark" highlighting "github.com/yuin/goldmark-highlighting" + meta "github.com/yuin/goldmark-meta" "github.com/yuin/goldmark/extension" "github.com/yuin/goldmark/parser" ) @@ -47,6 +48,7 @@ goldmark.WithExtensions( extension.GFM, highlighting.Highlighting, + meta.Meta, ), goldmark.WithParserOptions( parser.WithAutoHeadingID(), @@ -54,16 +56,17 @@ ) var htmlContent bytes.Buffer - err = md.Convert(source, &htmlContent) + parserContext := parser.NewContext() + err = md.Convert(source, &htmlContent, parser.WithContext(parserContext)) if err != nil { log.Fatal(err) } if useTemplate { - context := map[string]string{ - "content": htmlContent.String(), - } - err := tmpl.FRender(os.Stdout, context) + templateVars := meta.Get(parserContext) + templateVars["content"] = htmlContent.String() + + err := tmpl.FRender(os.Stdout, templateVars) if err != nil { log.Fatal(err) }