You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
840 B
Go

package main
import (
"bytes"
"flag"
// "fmt"
"io"
"log"
"os"
"github.com/yuin/goldmark"
"github.com/yuin/goldmark-meta"
// "github.com/yuin/goldmark/extension"
"github.com/yuin/goldmark/parser"
)
func LoadNote(r io.Reader) (interface{}, error) {
var buf bytes.Buffer
markdown := goldmark.New(
goldmark.WithExtensions(
meta.Meta,
),
)
context := parser.NewContext()
io.Copy(&buf, r)
if err := markdown.Convert(buf.Bytes(), &buf, parser.WithContext(context)); err != nil {
return nil, err
}
metaData := meta.Get(context)
log.Printf("%#+v\n", metaData)
return nil, nil
}
func main() {
var (
note string
)
flag.StringVar(&note, "note", "demo.md", "filename of test note")
flag.Parse()
f, err := os.Open(note)
if err != nil {
log.Fatalf("error opening markdown file: %s\n", err)
}
LoadNote(f)
}