README.md
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="http://goreportcard.com/report/charmbracelet/glamour"><img src="http://goreportcard.com/badge/charmbracelet/glamour" alt="Go ReportCard"></a>
10</p>
11
12Write handsome command-line tools with *Glamour*.
13
14![Glamour dark style example](https://stuff.charm.sh/glamour/glamour-example.png)
15
16`glamour` lets you render [markdown](https://en.wikipedia.org/wiki/Markdown)
17documents & templates on [ANSI](https://en.wikipedia.org/wiki/ANSI_escape_code)
18compatible terminals. You can create your own stylesheet or simply use one of
19the stylish defaults.
20
21
22## Usage
23
24```go
25import "github.com/charmbracelet/glamour"
26
27in := `# Hello World
28
29This is a simple example of Markdown rendering with Glamour!
30Check out the [other examples](https://github.com/charmbracelet/glamour/tree/master/examples) too.
31
32Bye!
33`
34
35out, err := glamour.Render(in, "dark")
36fmt.Print(out)
37```
38
39<img src="https://github.com/charmbracelet/glamour/raw/master/examples/helloworld/helloworld.png" width="600" alt="Hello World example">
40
41### Custom Renderer
42
43```go
44import "github.com/charmbracelet/glamour"
45
46r, _ := glamour.NewTermRenderer(
47 // detect background color and pick either the default dark or light theme
48 glamour.WithAutoStyle(),
49 // wrap output at specific width
50 glamour.WithWordWrap(40),
51)
52
53out, err := r.Render(in)
54fmt.Print(out)
55```
56
57
58## Styles
59
60You can find all available default styles in our [gallery](https://github.com/charmbracelet/glamour/tree/master/styles/gallery).
61Want to create your own style? [Learn how!](https://github.com/charmbracelet/glamour/tree/master/styles)
62
63There are a few options for using a custom style:
641. Call `glamour.Render(inputText, "desiredStyle")`
651. Set the `GLAMOUR_STYLE` environment variable to your desired default style or a file location for a style and call `glamour.RenderWithEnvironmentConfig(inputText)`
661. Set the `GLAMOUR_STYLE` environment variable and pass `glamour.WithEnvironmentConfig()` to your custom renderer
67
68
69## Glamourous Projects
70
71Check out these projects, which use `glamour`:
72- [Glow](https://github.com/charmbracelet/glow), a markdown renderer for
73the command-line.
74- [GitHub CLI](https://github.com/cli/cli), GitHub’s official command line tool.
75- [GLab](https://github.com/profclems/glab), An open source GitLab command line tool.
76
77## License
78
79[MIT](https://github.com/charmbracelet/glamour/raw/master/LICENSE)
80
81
82***
83
84Part of [Charm](https://charm.sh).
85
86<a href="https://charm.sh/"><img alt="The Charm logo" src="https://stuff.charm.sh/charm-badge-unrounded.jpg" width="400"></a>
87
88Charm热爱开源 • Charm loves open source
89
90