Remove blackfriday requirement from clients

This commit is contained in:
Toby Padilla 2019-11-12 16:36:51 -05:00
commit 218aff99ae
2 changed files with 13 additions and 3 deletions

View file

@ -7,7 +7,6 @@ import (
"os"
"github.com/magicnumbers/gold"
bf "gopkg.in/russross/blackfriday.v2"
)
func main() {
@ -25,11 +24,10 @@ func main() {
}
defer f.Close()
b, _ := ioutil.ReadAll(f)
r, err := gold.NewTermRenderer(*s)
out, err := gold.RenderBytes(b, *s)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
out := bf.Run(b, bf.WithRenderer(r))
fmt.Printf("%s", string(out))
}

12
gold.go
View file

@ -209,6 +209,18 @@ func NewElement(node *bf.Node) Element {
}
func Render(in string, stylePath string) ([]byte, error) {
return RenderBytes([]byte(in), stylePath)
}
func RenderBytes(in []byte, stylePath string) ([]byte, error) {
r, err := NewTermRenderer(stylePath)
if err != nil {
return nil, err
}
return bf.Run(in, bf.WithRenderer(r)), nil
}
func NewTermRenderer(stylePath string) (*TermRenderer, error) {
if stylePath == "" {
return NewTermRendererFromBytes([]byte("{}"))