glow/main.go

51 lines
772 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"
"io"
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
2019-11-15 18:35:04 +00:00
"github.com/charmbracelet/gold"
2019-11-04 23:17:36 +00:00
)
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)
}
var in io.Reader
if isGitHubURL(args[0]) {
resp, err := findGitHubREADME(args[0])
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer resp.Body.Close()
in = resp.Body
} else {
f, err := os.Open(args[0])
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer f.Close()
in = f
2019-11-09 22:12:54 +00:00
}
b, _ := ioutil.ReadAll(in)
out, err := gold.RenderBytes(b, *s)
2019-11-09 20:07:01 +00:00
if err != nil {
fmt.Println(err)
os.Exit(1)
}
2019-11-09 22:12:54 +00:00
fmt.Printf("%s", string(out))
2019-11-04 23:17:36 +00:00
}