### Glamour v1 Example Source: https://github.com/charmbracelet/glamour/blob/main/UPGRADE_GUIDE_V2.md This is a complete example demonstrating Glamour v1 usage with auto style detection and TrueColor profile. ```go package main import ( "fmt" "github.com/charmbracelet/glamour" "github.com/muesli/termenv" ) func main() { md := `# Hello World This is **Glamour v1**! ` r, _ := glamour.NewTermRenderer( glamour.WithAutoStyle(), glamour.WithColorProfile(termenv.TrueColor), glamour.WithWordWrap(80), ) out, _ := r.Render(md) fmt.Print(out) } ``` -------------------------------- ### Link Markdown Example Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Example of a Markdown link. ```markdown This is a [link](https://charm.sh). ``` -------------------------------- ### Image Markdown Example Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Example of an image in Markdown. ```markdown ![Image](https://charm.sh/logo.png). ``` -------------------------------- ### Update Glamour v2 Dependencies Source: https://github.com/charmbracelet/glamour/blob/main/UPGRADE_GUIDE_V2.md Use `go get` to update Glamour to v2. If color downsampling is needed, also update Lip Gloss to v2. ```bash go get charm.land/glamour/v2@latest ``` ```bash go get charm.land/lipgloss/v2@latest ``` -------------------------------- ### Task List Markdown Example Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Example of a task list with finished and outstanding items in Markdown. ```markdown - [x] Finished Task - [ ] Outstanding Task ``` -------------------------------- ### Haskell Hello World Example Source: https://github.com/charmbracelet/glamour/blob/main/examples/artichokes/artichokes.md This Haskell code defines a function to greet a name and a main function to print greetings for 'artichoke' and 'alcachofa'. Requires GHC to compile. ```haskell module Main where import Data.List (intercalate) hello :: String -> String hello s = "Hello, " <> s <> "." main :: IO () main = putStrLn $ intercalate "\n" $ hello <$> [ "artichoke", "alcachofa" ] ``` -------------------------------- ### Markdown Table Example Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Example of a Markdown table structure. ```markdown | Label | Value | | ------ | ----- | | First | foo | | Second | bar | ``` -------------------------------- ### Ordered List Markdown Example Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Example of an ordered list in Markdown. ```markdown 1. First Item 2. Second Item ``` -------------------------------- ### Markdown List Example Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Example of a nested Markdown list structure. ```markdown - First Item - Nested List Item - Second Item ``` -------------------------------- ### Emphasized Text Markdown Example Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Example of emphasized text in Markdown. ```markdown This text is *emphasized*. ``` -------------------------------- ### Quoted Code Block Example Source: https://github.com/charmbracelet/glamour/blob/main/testdata/issues/79.md This is an example of a code block within a blockquote. It is not executable code but demonstrates formatting. ```text quoted code block ``` -------------------------------- ### Basic Markdown Rendering with Glamour Source: https://github.com/charmbracelet/glamour/blob/main/README.md Renders a given Markdown string to the terminal using a default 'dark' style. Ensure the 'charm.land/glamour/v2' package is imported. ```go 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.Print(out) ``` -------------------------------- ### Generate JSON Theme Files Source: https://github.com/charmbracelet/glamour/blob/main/CONTRIBUTING.md After implementing new styles in Go, run go generate to create the corresponding JSON files. ```bash go generate ./... ``` -------------------------------- ### Render Markdown with Glamour v2 Source: https://github.com/charmbracelet/glamour/blob/main/UPGRADE_GUIDE_V2.md Use `glamour.NewTermRenderer` to create a renderer with custom styles and word wrap. Ensure you use `lipgloss.Print` for correct color output. ```go package main import ( "fmt" "charm.land/glamour/v2" "charm.land/lipgloss/v2" ) func main() { md := `# Hello World This is **Glamour v2**! ` r, _ := glamour.NewTermRenderer( glamour.WithStylePath("dark"), // or omit for default glamour.WithWordWrap(80), ) out, _ := r.Render(md) lipgloss.Print(out) // Handles color downsampling } ``` -------------------------------- ### Handle Color Downsampling Explicitly with Lip Gloss Source: https://github.com/charmbracelet/glamour/blob/main/UPGRADE_GUIDE_V2.md The `WithColorProfile()` option is removed. Use Lip Gloss for color adaptation. Glamour now produces pure output, and Lip Gloss handles terminal-specific color downsampling. ```diff -import "github.com/muesli/termenv" - -r, _ := glamour.NewTermRenderer( - glamour.WithColorProfile(termenv.TrueColor), -) -out, _ := r.Render(markdown) -fmt.Print(out) +import "charm.land/lipgloss/v2" + r, _ := glamour.NewTermRenderer( + glamour.WithWordWrap(80), +) out, _ := r.Render(markdown) // Lip Gloss handles color downsampling based on terminal capabilities lipgloss.Print(out) ``` ```go r, _ := glamour.NewTermRenderer(glamour.WithWordWrap(80)) out, _ := r.Render(markdown) fmt.Print(out) // Direct output, no downsampling ``` -------------------------------- ### Use lipgloss.Print for Color Output Source: https://github.com/charmbracelet/glamour/blob/main/UPGRADE_GUIDE_V2.md When rendering markdown with Glamour, use `lipgloss.Print()` instead of `fmt.Print()` to ensure colors are displayed correctly. ```go out, _ := r.Render(markdown) lipgloss.Print(out) // Not fmt.Print(out) ``` -------------------------------- ### Document Style Configuration Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Configure the overall document style, including indentation and background color. Use block_prefix and block_suffix for content surrounding the entire document. ```json "document": { "indent": 2, "background_color": "234", "block_prefix": "\n", "block_suffix": "\n" } ``` -------------------------------- ### Update Go Module for Glamour v2 Source: https://github.com/charmbracelet/glamour/blob/main/UPGRADE_GUIDE_V2.md When migrating to Glamour v2, update your `go.mod` file to include the new package path. ```bash go get charm.land/glamour/v2 ``` -------------------------------- ### Render Markdown to Dark Theme Source: https://github.com/charmbracelet/glamour/blob/main/testdata/TestWithChromaFormatter.md Use the `glamour.Render` function to convert a Markdown string to HTML with a specified theme. Ensure the `fmt` package is imported for printing the output. ```go import "github.com/charmbracelet/glamour" in := `# Hello World This is a simple example of Markdown rendering with Glamour! Check out the [other examples](https://github.com/charmbracelet/glamour/tree/master/examples) too. Bye! ` out, err := glamour.Render(in, "dark") fmt.Print(out) ``` -------------------------------- ### Update Import Paths for Glamour v2 Source: https://github.com/charmbracelet/glamour/blob/main/UPGRADE_GUIDE_V2.md All import paths must be updated to use the new `charm.land` module path with `/v2`. ```diff -import "github.com/charmbracelet/glamour" -import "github.com/charmbracelet/glamour/ansi" -import "github.com/charmbracelet/glamour/styles" +import "charm.land/glamour/v2" +import "charm.land/glamour/v2/ansi" +import "charm.land/glamour/v2/styles" ``` -------------------------------- ### Custom Markdown Renderer with Word Wrap Source: https://github.com/charmbracelet/glamour/blob/main/README.md Creates a custom Markdown renderer with a specified word wrap width. The default width is 80 characters. ```go 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.Print(out) ``` -------------------------------- ### Verify Custom Writers with `Close()` Method Source: https://github.com/charmbracelet/glamour/blob/main/UPGRADE_GUIDE_V2.md Custom margin or padding writers using `ansi.MarginWriter` must now call `.Close()`. New `IndentWriter` and `PaddingWriter` types are available. ```go import "charm.land/glamour/v2/ansi" mw := ansi.NewMarginWriter(ctx, w, style) defer mw.Close() // Important: always close writers now // Write your content io.WriteString(mw, content) ``` -------------------------------- ### Color Downsampling with Lip Gloss Source: https://github.com/charmbracelet/glamour/blob/main/README.md Renders Markdown and then uses Lip Gloss to downsample colors based on terminal capabilities. This is necessary because Glamour itself does not perform color downsampling by default. ```go 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.Print(out) ``` -------------------------------- ### Paragraph Style Configuration Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Style paragraphs with margin, color, and background color. These settings affect the spacing and appearance of individual paragraphs. ```json "paragraph": { "margin": 4, "color": "15", "background_color": "235" } ``` -------------------------------- ### Code Block Style Configuration Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Style code blocks with a specific color and syntax highlighting theme. The 'theme' attribute uses Chroma themes for highlighting. ```json "code_block": { "color": "200", "theme": "solarized-dark" } ``` -------------------------------- ### Table Style Configuration Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Configure table margins using JSON. This style applies to the table element. ```json { "table": { "margin": 4 } } ``` -------------------------------- ### Style Strong Text in Markdown Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Use the 'strong' style to make text bold. This corresponds to Markdown's **strong** syntax. ```markdown This text is **strong**. ``` ```json "strong": { "bold": true } ``` -------------------------------- ### Task Element Style Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Define prefixes for ticked and unticked task items. This allows customization of task status indicators. ```json { "task": { "ticked": "✓ ", "unticked": "✗ " } } ``` -------------------------------- ### List Style Configuration Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Configure the appearance of lists, including their color and background. The level_indent attribute controls indentation for nested lists. ```json "list": { "color": "15", "background_color": "52", "level_indent": 4 } ``` -------------------------------- ### Heading Style Configuration Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Define styles for headings, including default color and background. Specific heading levels (h1-h6) can override these with their own prefixes, suffixes, margins, and bold attributes. ```markdown # h1 ## h2 ### h3 ``` ```json "heading": { "color": "15", "background_color": "57" }, "h1": { "prefix": "=> ", "suffix": " <=", "margin": 2, "bold": true, "background_color": "69" }, "h2": { "prefix": "## ", "margin": 4 }, "h3": { "prefix": "### ", "margin": 6 } ``` -------------------------------- ### Image Element Style Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Configure the display of images, including color and surrounding text. This affects how image markdown is rendered. ```json { "image": { "color": "123", "block_prefix": "[Image: ", "block_suffix": "]" } } ``` -------------------------------- ### Remove Auto Style Detection in Glamour v2 Source: https://github.com/charmbracelet/glamour/blob/main/UPGRADE_GUIDE_V2.md The `WithAutoStyle()` option has been removed. The default style is now `"dark"`. Specify the style explicitly using `WithStylePath()`. ```diff -r, _ := glamour.NewTermRenderer( - glamour.WithAutoStyle(), -) +r, _ := glamour.NewTermRenderer( + // "dark" is the default, or specify explicitly + glamour.WithStylePath("dark"), +) ``` ```go // For light backgrounds r, _ := glamour.NewTermRenderer(glamour.WithStylePath("light")) // For dark backgrounds (default) r, _ := glamour.NewTermRenderer(glamour.WithStylePath("dark")) // Other built-in styles: "pink", "dracula", "tokyo-night", "ascii" r, _ := glamour.NewTermRenderer(glamour.WithStylePath("dracula")) ``` ```go import "charm.land/lipgloss/v2" // Detect if we're on a dark background isDark := lipgloss.HasDarkBackground() style := "dark" if !isDark { style = "light" } r, _ := glamour.NewTermRenderer(glamour.WithStylePath(style)) ``` -------------------------------- ### Update Golden Files in Tests Source: https://github.com/charmbracelet/glamour/blob/main/CONTRIBUTING.md Use the -update flag with the go test command to update golden files when providing new features or bug fixes. ```bash go test ./pkg/... -update ``` -------------------------------- ### Item Element Style Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Set a block prefix for list items. This is used for bulleted lists. ```json { "item": { "block_prefix": "• " } } ``` -------------------------------- ### Enumeration Element Style Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Configure the block prefix for ordered list items. This is used for numbered lists. ```json { "enumeration": { "block_prefix": ". " } } ``` -------------------------------- ### Update Custom Style Definition Import Paths Source: https://github.com/charmbracelet/glamour/blob/main/UPGRADE_GUIDE_V2.md When defining custom `StyleConfig`, update the import path for `ansi` to `charm.land/glamour/v2/ansi`. ```diff -import "github.com/charmbracelet/glamour/ansi" +import "charm.land/glamour/v2/ansi" var myStyle = &ansi.StyleConfig{ // Your custom style definition Document: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Color: stringPtr("#E6DB74"), }, }, } ``` -------------------------------- ### Remove Overline Styles in Custom Configurations Source: https://github.com/charmbracelet/glamour/blob/main/UPGRADE_GUIDE_V2.md The `Overlined` field has been removed from style configurations. Consider using underline, bold, inverse, or background colors as alternatives. ```diff StylePrimitive: ansi.StylePrimitive{ Bold: &trueBool, Underline: &trueBool, - Overlined: &trueBool, } ``` -------------------------------- ### Block Quote Style Configuration Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Style block quotes with a specific color and indentation. The indent_token is used to prefix each line of the quote. ```json "block_quote": { "color": "200", "indent": 1, "indent_token": "=> " } ``` -------------------------------- ### Link Text Style Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Style the text part of a link with color and bold formatting. This targets the visible text of the URL. ```json { "link_text": { "color": "123", "bold": true } } ``` -------------------------------- ### Style Strikethrough Text in Markdown Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Use the 'strikethrough' style to apply a line through text. This corresponds to Markdown's ~~strikethrough~~ syntax. ```markdown ~~Scratch this~~. ``` ```json "strikethrough": { "crossed_out": true } ``` -------------------------------- ### Image Text Style Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Style the text associated with an image, typically its alt text. This affects the color of the image's descriptive text. ```json { "image_text": { "color": "8" } } ``` -------------------------------- ### Text Element Style Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Style the text element with bold formatting and specific colors. This applies to general text blocks. ```json { "text": { "bold": true, "color": "15", "background_color": "57" } } ``` -------------------------------- ### Link Element Style Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Style links with a specific color, underline, and surrounding characters. This affects how URLs are displayed. ```json { "link": { "color": "123", "underline": true, "block_prefix": "(", "block_suffix": ")" } } ``` -------------------------------- ### Code Element Style Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Set the color for inline code segments. This applies to code snippets within regular text. ```json { "code": { "color": "200" } } ``` -------------------------------- ### Emphasized Text Style Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Apply italic formatting to emphasized text. This is used for text marked with asterisks or underscores. ```json { "emph": { "italic": true } } ``` -------------------------------- ### Evaluate Java Expression Source: https://github.com/charmbracelet/glamour/blob/main/testdata/issues/315.md Evaluates a boolean expression in Java. This snippet demonstrates a logical OR operation between two comparison expressions. ```java (1 >= 26) || (12 >= 6) ``` -------------------------------- ### Emoji in Text Source: https://github.com/charmbracelet/glamour/blob/main/testdata/issues/48.md Emojis are rendered directly in plain text. This is useful for adding visual flair to general content. ```text :octopus: :zap: :cat: = :heart: ``` -------------------------------- ### Style Horizontal Rule in Markdown Source: https://github.com/charmbracelet/glamour/blob/main/styles/README.md Use the 'hr' style to define the appearance of horizontal rules. This corresponds to Markdown's --- syntax. ```markdown --- ``` ```json "hr": { "block_prefix": "---" } ``` -------------------------------- ### Emoji in Header Source: https://github.com/charmbracelet/glamour/blob/main/testdata/issues/48.md Emojis can be included in markdown headers to enhance their visual appeal. Ensure the markdown parser supports emoji rendering. ```markdown ## :octopus: :zap: :cat: = :heart: ``` -------------------------------- ### Emoji in Code Block Source: https://github.com/charmbracelet/glamour/blob/main/testdata/issues/48.md Emojis are not processed within fenced code blocks and are displayed as literal characters. This is standard behavior for code rendering. ```text ``` :octopus: :zap: :cat: = :heart: ``` ``` -------------------------------- ### Emoji in Inline Code Source: https://github.com/charmbracelet/glamour/blob/main/testdata/issues/48.md Emojis are treated as literal characters within inline code spans. This prevents unintended rendering in code contexts. ```text `:octopus: :zap: :cat: = :heart:` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.