github.com/charmbracelet/glamour@v0.7.0/README.md (about) 1 # Glamour 2 3 <p> 4 <img src="https://stuff.charm.sh/glamour/glamour-github-header.png" width="245" alt="Glamour Title Treatment"><br> 5 <a href="https://github.com/charmbracelet/glamour/releases"><img src="https://img.shields.io/github/release/charmbracelet/glamour.svg" alt="Latest Release"></a> 6 <a href="https://pkg.go.dev/github.com/charmbracelet/glamour?tab=doc"><img src="https://godoc.org/github.com/golang/gddo?status.svg" alt="GoDoc"></a> 7 <a href="https://github.com/charmbracelet/glamour/actions"><img src="https://github.com/charmbracelet/glamour/workflows/build/badge.svg" alt="Build Status"></a> 8 <a href="https://coveralls.io/github/charmbracelet/glamour?branch=master"><img src="https://coveralls.io/repos/github/charmbracelet/glamour/badge.svg?branch=master" alt="Coverage Status"></a> 9 <a href="https://goreportcard.com/report/charmbracelet/glamour"><img src="https://goreportcard.com/badge/charmbracelet/glamour" alt="Go ReportCard"></a> 10 </p> 11 12 Stylesheet-based markdown rendering for your CLI apps. 13 14  15 16 `glamour` lets you render [markdown](https://en.wikipedia.org/wiki/Markdown) 17 documents & templates on [ANSI](https://en.wikipedia.org/wiki/ANSI_escape_code) 18 compatible terminals. You can create your own stylesheet or simply use one of 19 the stylish defaults. 20 21 ## Usage 22 23 ```go 24 import "github.com/charmbracelet/glamour" 25 26 in := `# Hello World 27 28 This is a simple example of Markdown rendering with Glamour! 29 Check out the [other examples](https://github.com/charmbracelet/glamour/tree/master/examples) too. 30 31 Bye! 32 ` 33 34 out, err := glamour.Render(in, "dark") 35 fmt.Print(out) 36 ``` 37 38 <img src="https://github.com/charmbracelet/glamour/raw/master/examples/helloworld/helloworld.png" width="600" alt="Hello World example"> 39 40 ### Custom Renderer 41 42 ```go 43 import "github.com/charmbracelet/glamour" 44 45 r, _ := glamour.NewTermRenderer( 46 // detect background color and pick either the default dark or light theme 47 glamour.WithAutoStyle(), 48 // wrap output at specific width (default is 80) 49 glamour.WithWordWrap(40), 50 ) 51 52 out, err := r.Render(in) 53 fmt.Print(out) 54 ``` 55 56 ## Styles 57 58 You can find all available default styles in our [gallery](https://github.com/charmbracelet/glamour/tree/master/styles/gallery). 59 Want to create your own style? [Learn how!](https://github.com/charmbracelet/glamour/tree/master/styles) 60 61 There are a few options for using a custom style: 62 1. Call `glamour.Render(inputText, "desiredStyle")` 63 1. Set the `GLAMOUR_STYLE` environment variable to your desired default style or a file location for a style and call `glamour.RenderWithEnvironmentConfig(inputText)` 64 1. Set the `GLAMOUR_STYLE` environment variable and pass `glamour.WithEnvironmentConfig()` to your custom renderer 65 66 ## Glamourous Projects 67 68 Check out these projects, which use `glamour`: 69 - [Glow](https://github.com/charmbracelet/glow), a markdown renderer for 70 the command-line. 71 - [GitHub CLI](https://github.com/cli/cli), GitHub’s official command line tool. 72 - [GitLab CLI](https://gitlab.com/gitlab-org/cli), GitLab's official command line tool. 73 - [Gitea CLI](https://gitea.com/gitea/tea), Gitea's official command line tool. 74 - [Meteor](https://github.com/odpf/meteor), an easy-to-use, plugin-driven metadata collection framework. 75 76 ## Feedback 77 78 We’d love to hear your thoughts on this project. Feel free to drop us a note! 79 80 * [Twitter](https://twitter.com/charmcli) 81 * [The Fediverse](https://mastodon.social/@charmcli) 82 * [Discord](https://charm.sh/chat) 83 84 ## License 85 86 [MIT](https://github.com/charmbracelet/glamour/raw/master/LICENSE) 87 88 *** 89 90 Part of [Charm](https://charm.sh). 91 92 <a href="https://charm.sh/"><img alt="The Charm logo" src="https://stuff.charm.sh/charm-badge.jpg" width="400"></a> 93 94 Charm热爱开源 • Charm loves open source