okami.mom/glamour
git clone https://git.nkp.pet/okami.mom/glamour
cf874d7
main
Glamour
<p> <img src="https://github.com/user-attachments/assets/23aabf2a-8bd8-4e7b-bb50-993bce32541d" width="300" alt="Glamour Title Treatment"><br> <a href="https://github.com/charmbracelet/glamour/releases"><img src="https://img.shields.io/github/release/charmbracelet/glamour.svg" alt="Latest Release"></a> <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> <a href="https://github.com/charmbracelet/glamour/actions"><img src="https://github.com/charmbracelet/glamour/workflows/build/badge.svg" alt="Build Status"></a> <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> <a href="https://goreportcard.com/report/charmbracelet/glamour"><img src="https://goreportcard.com/badge/charmbracelet/glamour" alt="Go ReportCard"></a> </p>Stylesheet-based markdown rendering for your CLI apps.
<img width="845" src="https://github.com/user-attachments/assets/ec2ead40-c467-48cc-b6a8-f0f13709eeab" alt="Glamour example">glamour lets you render markdown
documents & templates on ANSI
compatible terminals. You can create your own stylesheet or simply use one of
the stylish defaults.
Usage
<img src="https://github.com/charmbracelet/glamour/raw/master/examples/helloworld/helloworld.png" width="600" alt="Hello World example">import "charm.land/glamour/v2" in := `# Hello World This is a simple example of Markdown rendering with Glamour! Check out the [other examples](https://github.com/charmbracelet/glamour/tree/main/examples) too. Bye! ` out ,err := glamour .Render (in ,"dark" )fmt .out )
Custom Renderer
import "charm.land/glamour/v2" r ,_ := glamour .NewTermRenderer (// wrap output at specific width (default is 80) glamour .WithWordWrap (40 ), )out ,err := r .Render (in )fmt .out )
Color Downsampling
Since the renderer is designed to be "pure" and always produce the same output for the same input, it doesn't have access to the terminal's capabilities. This means that color downsampling is not performed by default. In this case, use Lip Gloss to perform downsampling before rendering:
import ("charm.land/glamour/v2" "charm.land/lipgloss/v2" )r ,_ := glamour .NewTermRenderer (// wrap output at specific width (default is 80) glamour .WithWordWrap (40 ), )out ,err := r .Render (in )if err != nil {// handle error }// downsample colors based on terminal capabilities. lipgloss .out )
Styles
You can find all available default styles in our gallery. Want to create your own style? Learn how!
There are a few options for using a custom style:
- Call
glamour.Render(inputText, "desiredStyle") - Set the
GLAMOUR_STYLEenvironment variable to your desired default style or a file location for a style and callglamour.RenderWithEnvironmentConfig(inputText) - Set the
GLAMOUR_STYLEenvironment variable and passglamour.WithEnvironmentConfig()to your custom renderer
Glamourous Projects
Check out these projects, which use glamour:
- Glow, a markdown renderer for the command-line.
- GitHub CLI, GitHub’s official command line tool.
- GitLab CLI, GitLab's official command line tool.
- Gitea CLI, Gitea's official command line tool.
- Meteor, an easy-to-use, plugin-driven metadata collection framework.
Contributing
See contributing.
Feedback
We’d love to hear your thoughts on this project. Feel free to drop us a note!
License
Part of Charm.
<a href="https://charm.sh/"><img alt="The Charm logo" src="https://stuff.charm.sh/charm-badge.jpg" width="400"></a>
Charm热爱开源 • Charm loves open source
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 "charm.land/glamour/v2" 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/main/examples) too. 30 31Bye! 32` 33 34out, err := glamour . Render ( in , "dark" ) 35fmt. ( 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 "charm.land/glamour/v2" 44 45r, _ := glamour . NewTermRenderer ( 46// wrap output at specific width (default is 80) 47glamour . WithWordWrap ( 40 ), 48) 49 50out, err := r . Render ( in ) 51fmt. ( out ) 52``` 53 54### Color Downsampling 55 56Since the renderer is designed to be "pure" and always produce the same output 57for the same input, it doesn't have access to the terminal's capabilities. This 58means that color downsampling is not performed by default. In this case, use [Lip Gloss][lipgloss] 59to perform downsampling before rendering: 60 61``` go 62import ( 63"charm.land/glamour/v2" 64"charm.land/lipgloss/v2" 65) 66 67r, _ := glamour . NewTermRenderer ( 68// wrap output at specific width (default is 80) 69glamour . WithWordWrap ( 40 ), 70) 71 72out, err := r . Render ( in ) 73if err != nil { 74// handle error 75} 76 77// downsample colors based on terminal capabilities. 78lipgloss. ( out ) 79``` 80 81[lipgloss] : https://github.com/charmbracelet/lipgloss 82 83## Styles 84 85You can find all available default styles in our [gallery](https://github.com/charmbracelet/glamour/tree/main/styles/gallery). 86Want to create your own style? [Learn how!](https://github.com/charmbracelet/glamour/tree/main/styles) 87 88There are a few options for using a custom style: 89 901. Call `glamour.Render(inputText, "desiredStyle")` 911. Set the `GLAMOUR_STYLE` environment variable to your desired default style or a file location for a style and call `glamour.RenderWithEnvironmentConfig(inputText)` 921. Set the `GLAMOUR_STYLE` environment variable and pass `glamour.WithEnvironmentConfig()` to your custom renderer 93 94## Glamourous Projects 95 96Check out these projects, which use `glamour`: 97 98- [Glow](https://github.com/charmbracelet/glow), a markdown renderer for 99the command-line. 100- [GitHub CLI](https://github.com/cli/cli), GitHub’s official command line tool. 101- [GitLab CLI](https://gitlab.com/gitlab-org/cli), GitLab's official command line tool. 102- [Gitea CLI](https://gitea.com/gitea/tea), Gitea's official command line tool. 103- [Meteor](https://github.com/odpf/meteor), an easy-to-use, plugin-driven metadata collection framework. 104 105## Contributing 106 107See [contributing][contribute]. 108 109[contribute] : https://github.com/charmbracelet/glamour/contribute 110 111## Feedback 112 113We’d love to hear your thoughts on this project. Feel free to drop us a note! 114 115- [Twitter](https://twitter.com/charmcli) 116- [The Fediverse](https://mastodon.social/@charmcli) 117- [Discord](https://charm.sh/chat) 118 119## License 120 121[MIT](https://github.com/charmbracelet/glamour/raw/master/LICENSE) 122 123--- 124 125Part of [Charm](https://charm.sh). 126 127<a href="https://charm.sh/"><img alt="The Charm logo" src="https://stuff.charm.sh/charm-badge.jpg" width="400"></a> 128 129Charm热爱开源 • Charm loves open source