1# Glamour
2
3<p>
4 <img src="https://github.com/user-attachments/assets/23aabf2a-8bd8-4e7b-bb50-993bce32541d" width="300" 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
12Stylesheet-based markdown rendering for your CLI apps.
13
14<img width="845" src="https://github.com/user-attachments/assets/ec2ead40-c467-48cc-b6a8-f0f13709eeab" alt="Glamour example">
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## Usage
22
23```go
24import "github.com/charmbracelet/glamour"
25
26in := `# Hello World
27
28This is a simple example of Markdown rendering with Glamour!
29Check out the [other examples](https://github.com/charmbracelet/glamour/tree/master/examples) too.
30
31Bye!
32`
33
34out, err := glamour.Render(in, "dark")
35fmt.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
43import "github.com/charmbracelet/glamour"
44
45r, _ := 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
52out, err := r.Render(in)
53fmt.Print(out)
54```
55
56## Styles
57
58You can find all available default styles in our [gallery](https://github.com/charmbracelet/glamour/tree/master/styles/gallery).
59Want to create your own style? [Learn how!](https://github.com/charmbracelet/glamour/tree/master/styles)
60
61There are a few options for using a custom style:
62
631. Call `glamour.Render(inputText, "desiredStyle")`
641. Set the `GLAMOUR_STYLE` environment variable to your desired default style or a file location for a style and call `glamour.RenderWithEnvironmentConfig(inputText)`
651. Set the `GLAMOUR_STYLE` environment variable and pass `glamour.WithEnvironmentConfig()` to your custom renderer
66
67## Glamourous Projects
68
69Check out these projects, which use `glamour`:
70
71- [Glow](https://github.com/charmbracelet/glow), a markdown renderer for
72 the command-line.
73- [GitHub CLI](https://github.com/cli/cli), GitHub’s official command line tool.
74- [GitLab CLI](https://gitlab.com/gitlab-org/cli), GitLab's official command line tool.
75- [Gitea CLI](https://gitea.com/gitea/tea), Gitea's official command line tool.
76- [Meteor](https://github.com/odpf/meteor), an easy-to-use, plugin-driven metadata collection framework.
77
78## Feedback
79
80We’d love to hear your thoughts on this project. Feel free to drop us a note!
81
82- [Twitter](https://twitter.com/charmcli)
83- [The Fediverse](https://mastodon.social/@charmcli)
84- [Discord](https://charm.sh/chat)
85
86## License
87
88[MIT](https://github.com/charmbracelet/glamour/raw/master/LICENSE)
89
90---
91
92Part of [Charm](https://charm.sh).
93
94<a href="https://charm.sh/"><img alt="The Charm logo" src="https://stuff.charm.sh/charm-badge.jpg" width="400"></a>
95
96Charm热爱开源 • Charm loves open source