glow/main.go

36 lines
623 B
Go
Raw Normal View History

2019-11-04 23:17:36 +00:00
package main
import (
2019-11-09 20:07:01 +00:00
"flag"
2019-11-04 23:17:36 +00:00
"fmt"
2019-11-09 22:12:54 +00:00
"io/ioutil"
2019-11-09 20:07:01 +00:00
"os"
2019-11-04 23:17:36 +00:00
"github.com/magicnumbers/gold"
bf "gopkg.in/russross/blackfriday.v2"
)
func main() {
2019-11-09 20:07:01 +00:00
s := flag.String("s", "", "style json path")
flag.Parse()
2019-11-09 22:12:54 +00:00
args := flag.Args()
if len(args) != 1 {
fmt.Println("Missing Markdown file. Usage: ./gold -s STYLE.json FILE.md")
os.Exit(1)
}
f, err := os.Open(args[0])
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer f.Close()
b, _ := ioutil.ReadAll(f)
2019-11-09 20:07:01 +00:00
r, err := gold.NewTermRenderer(*s)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
2019-11-09 22:12:54 +00:00
out := bf.Run(b, bf.WithRenderer(r))
fmt.Printf("%s", string(out))
2019-11-04 23:17:36 +00:00
}