Ruby bindings for charmbracelet/glamour.
Render markdown documents & templates on ANSI compatible terminals.
Add to your Gemfile:
gem "glamour"Or install directly:
gem install glamourRender markdown with auto-detected style:
require "glamour"
puts Glamour.render("# Hello World")Render with a specific style:
puts Glamour.render("# Hello", style: "dark")
puts Glamour.render("# Hello", style: "light")
puts Glamour.render("# Hello", style: "dracula")
puts Glamour.render("# Hello", style: "notty")Render with word wrap:
puts Glamour.render(long_markdown, width: 80)| Option | Description |
|---|---|
style |
"auto", "dark", "light", "notty", "dracula" |
width |
Word wrap width |
emoji |
Enable emoji rendering (:wave: → 👋) |
preserve_newlines |
Preserve newlines in output |
base_url |
Base URL for relative links |
color_profile |
:auto, :true_color, :ansi256, :ansi, :ascii |
Example with all options:
Glamour.render(markdown,
style: "dark",
width: 80,
emoji: true,
preserve_newlines: true,
base_url: "https://example.com",
color_profile: :true_color
)Define a custom style:
custom_style = {
heading: { bold: true, color: "212" },
strong: { bold: true, color: "196" },
emph: { italic: true, color: "226" },
code: { color: "203", background_color: "236" }
}Render with the custom style:
Glamour.render_with_style("# Hello **World**", custom_style)With width option:
Glamour.render_with_style("# Hello", custom_style, width: 60)Define reusable styles using a Ruby DSL:
class MyStyle < Glamour::Style
style :heading do
bold true
color "212"
end
style :h1 do
prefix "# "
color "99"
bold true
end
style :strong do
bold true
color "196"
end
style :emph do
italic true
color "226"
end
style :code do
color "203"
background_color "236"
end
style :document do
margin 2
end
endUse the style class directly:
MyStyle.render("# Hello **World**")
MyStyle.render("# Hello", width: 80)Or pass to Glamour.render:
Glamour.render("# Hello", style: MyStyle)Create a renderer with preset options:
renderer = Glamour::Renderer.new(
style: "dark",
width: 80,
emoji: true
)Render multiple documents:
puts renderer.render("# Hello :wave:")
puts renderer.render("# Another document")With a Style class:
renderer = Glamour::Renderer.new(style: MyStyle, width: 60)
puts renderer.render("# Styled output")| Element | Description |
|---|---|
document |
Root document wrapper |
paragraph |
Text paragraphs |
heading |
Base heading style (h1-h6 inherit from this) |
h1 - h6 |
Individual heading levels |
block_quote |
Block quotations |
code_block |
Fenced code blocks |
list |
List containers |
item |
List items (bullets) |
enumeration |
Numbered list items |
table |
Markdown tables |
hr |
Horizontal rules |
| Element | Description |
|---|---|
text |
Base text styling |
strong |
Bold text (**bold**) |
emph |
Italic text (*italic*) |
strikethrough |
Strikethrough text |
code |
Inline code (`code`) |
link |
Link elements |
link_text |
Link text display |
image |
Image references |
Text decoration:
bold true
italic true
underline true
crossed_out true
faint true
inverse true
overlined trueColors (ANSI 256 color codes):
color "212"
background_color "236"Spacing:
margin 2
indent 1
indent_token " "
level_indent 2Prefix/suffix:
prefix "# "
suffix ""
block_prefix ""
block_suffix "\n""auto"- Auto-detect dark/light terminal"dark"- Dark terminal theme"light"- Light terminal theme"notty"- No colors (for non-TTY output)"dracula"- Dracula color scheme
puts Glamour.versionRequirements:
- Go 1.23+
- Ruby 3.2+
Install dependencies:
bundle installBuild the Go library and compile the extension:
bundle exec rake compileRun tests:
bundle exec rake testRun demos:
./demo/basic
./demo/styles
./demo/style_dslBug reports and pull requests are welcome on GitHub at https://github.com/marcoroth/glamour-ruby.
The gem is available as open source under the terms of the MIT License.
This gem wraps charmbracelet/glamour, part of the excellent Charm ecosystem. Charm Ruby is not affiliated with or endorsed by Charmbracelet, Inc.
Part of Charm Ruby.
Lipgloss • Bubble Tea • Bubbles • Glamour • Huh? • Harmonica • Bubblezone • Gum • ntcharts
The terminal doesn't have to be boring.
