Much better parsing, README example

This commit is contained in:
Toby Padilla 2019-11-09 16:12:54 -06:00
parent dda88169f4
commit 09bb6b3dd1
3 changed files with 37 additions and 3 deletions

15
README.md Normal file
View file

@ -0,0 +1,15 @@
# Charm Gold
Render markdown on the CLI, with _pizzazz_!
## Usage
Supply a JSON stylesheet with the `-s` flag. Use a markdown file as the argument.
```
./gold -s dark.json README.md
```
## Colors
Currently `gold` uses the [Aurora ANSI colors](https://godoc.org/github.com/logrusorgru/aurora#Index).

View file

@ -5,6 +5,12 @@
},
"heading": {
"bold": true,
"inverse": true
"color": "3"
},
"code": {
"color": "200"
},
"code_block": {
"color": "200"
}
}

17
main.go
View file

@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"github.com/magicnumbers/gold"
@ -26,11 +27,23 @@ This is a test yo.
func main() {
s := flag.String("s", "", "style json path")
flag.Parse()
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)
r, err := gold.NewTermRenderer(*s)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
out := bf.Run([]byte(tmd), bf.WithRenderer(r))
fmt.Println(string(out))
out := bf.Run(b, bf.WithRenderer(r))
fmt.Printf("%s", string(out))
}