diff --git a/README.md b/README.md index 81d75ad..a3a686e 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,32 @@ fmt.Printf(out) ![HelloWorld Example](https://github.com/charmbracelet/glamour/raw/master/examples/helloworld/helloworld.png) +### Custom Renderer + +```go +import ( + "github.com/charmbracelet/glamour" + "github.com/charmbracelet/glamour/ansi" +) + +in := `# Custom Renderer + +Word-wrapping will occur when lines exceed the limit of 40 characters. Just so +you know: Glamour's default word-wrapping limit is set to 100 characters per +line. + +Bye! +` + +r, _ := glamour.NewTermRenderer("dark", ansi.Options{ + WordWrap: int(40), +}) + +out, _ := r.Render(in) +fmt.Printf("%s", out) +} +``` + ## Glamourous Projects diff --git a/examples/custom_renderer/main.go b/examples/custom_renderer/main.go new file mode 100644 index 0000000..ccc4b66 --- /dev/null +++ b/examples/custom_renderer/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + + "github.com/charmbracelet/glamour" + "github.com/charmbracelet/glamour/ansi" +) + +func main() { + in := `# Custom Renderer + +Word-wrapping will occur when lines exceed the limit of 40 characters. Just so +you know: Glamour's default word-wrapping limit is set to 100 characters per +line. + +Bye! +` + + r, _ := glamour.NewTermRenderer("dark", ansi.Options{ + WordWrap: int(40), + }) + + out, _ := r.Render(in) + fmt.Printf("%s", out) +}