# charmbracelet/glamour architecture

> Architecture diagram of the GitHub repository charmbracelet/glamour, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/charmbracelet/glamour
- Repository: https://github.com/charmbracelet/glamour

## Overview

Glamour is a Go library for stylesheet-driven Markdown rendering to ANSI-compatible terminal output. Its principal workflow accepts Markdown through the public renderer API, parses it with Goldmark, maps Markdown nodes to renderable ANSI elements, and produces styled text. Distinct capabilities include syntax-highlighted code, links and table link footers, emoji, and selectable built-in or file-based styles. The graph reflects the excerpts and README; unsampled renderer internals are represented only where documented, so uncertain implementation links are omitted.

Main entry points: [`ansi/elements.go`](https://github.com/charmbracelet/glamour/blob/main/ansi/elements.go) (AST Element Mapping), [`glamour.go`](https://github.com/charmbracelet/glamour/blob/main/glamour.go) (Term Renderer), [`ansi/baseelement.go`](https://github.com/charmbracelet/glamour/blob/main/ansi/baseelement.go) (Styled Primitives), [`styles/styles.go`](https://github.com/charmbracelet/glamour/blob/main/styles/styles.go) (Built-in Styles)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Renderer API"]
  node_renderer_api["Term Renderer<br/>[glamour.go]"]
end

subgraph group_markdown["Markdown Rendering"]
  node_goldmark["Goldmark Parser"]
  node_element_map["AST Element Mapping<br/>[elements.go]"]
  node_ansi_primitives["Styled Primitives<br/>[baseelement.go]"]
  node_layout_writers["Margin Layout<br/>[margin.go]"]
end

subgraph group_styles["Style Configuration"]
  node_style_options["Style Selection<br/>[glamour.go]"]
  node_style_configs["Style Configurations<br/>[style.go]"]
  node_builtin_styles["Built-in Styles<br/>[styles.go]"]
end

subgraph group_features["Rendering Features"]
  node_code_blocks["Code Blocks<br/>[codeblock.go]"]
  node_chroma["Chroma Highlighter"]
  node_link_rendering["Hyperlinks<br/>[link.go]"]
  node_table_links["Table Link Footers<br/>[table_links.go]"]
  node_autolink["URL Shortening<br/>[autolink.go]"]
  node_emoji["Emoji Extension"]
end

node_consumer(("Go Application"))
node_terminal_output(("ANSI Output"))

node_consumer -->|"provides Markdown"| node_renderer_api
node_renderer_api -->|"parses Markdown"| node_goldmark
node_goldmark -.->|"supplies AST"| node_element_map
node_element_map -->|"maps elements"| node_ansi_primitives
node_element_map -->|"creates code blocks"| node_code_blocks
node_code_blocks -->|"highlights code"| node_chroma
node_element_map -->|"creates links"| node_link_rendering
node_element_map -->|"collects table links"| node_table_links
node_element_map -->|"shortens URLs"| node_autolink
node_table_links -->|"shortens URLs"| node_autolink
node_renderer_api -->|"enables extension"| node_emoji
node_renderer_api -->|"applies options"| node_style_options
node_style_options -->|"selects defaults"| node_builtin_styles
node_builtin_styles -->|"defines styles"| node_style_configs
node_ansi_primitives -.->|"writes styled text"| node_terminal_output
node_layout_writers -.->|"formats output"| node_terminal_output
node_renderer_api -->|"returns rendered text"| node_terminal_output

click node_renderer_api "https://github.com/charmbracelet/glamour/blob/main/glamour.go"
click node_element_map "https://github.com/charmbracelet/glamour/blob/main/ansi/elements.go"
click node_ansi_primitives "https://github.com/charmbracelet/glamour/blob/main/ansi/baseelement.go"
click node_layout_writers "https://github.com/charmbracelet/glamour/blob/main/ansi/margin.go"
click node_code_blocks "https://github.com/charmbracelet/glamour/blob/main/ansi/codeblock.go"
click node_link_rendering "https://github.com/charmbracelet/glamour/blob/main/ansi/link.go"
click node_table_links "https://github.com/charmbracelet/glamour/blob/main/ansi/table_links.go"
click node_autolink "https://github.com/charmbracelet/glamour/blob/main/internal/autolink/autolink.go"
click node_style_options "https://github.com/charmbracelet/glamour/blob/main/glamour.go"
click node_style_configs "https://github.com/charmbracelet/glamour/blob/main/ansi/style.go"
click node_builtin_styles "https://github.com/charmbracelet/glamour/blob/main/styles/styles.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_renderer_api toneBlue
class node_goldmark,node_element_map,node_ansi_primitives,node_layout_writers toneAmber
class node_style_options,node_style_configs,node_builtin_styles toneMint
class node_code_blocks,node_chroma,node_link_rendering,node_table_links,node_autolink,node_emoji toneRose
class node_consumer,node_terminal_output toneIndigo
```

## Components

### Renderer API

- [Term Renderer](https://github.com/charmbracelet/glamour/blob/main/glamour.go): `glamour.go`

### Markdown Rendering

- **Goldmark Parser**
- [AST Element Mapping](https://github.com/charmbracelet/glamour/blob/main/ansi/elements.go): `ansi/elements.go`
- [Styled Primitives](https://github.com/charmbracelet/glamour/blob/main/ansi/baseelement.go): `ansi/baseelement.go`
- [Margin Layout](https://github.com/charmbracelet/glamour/blob/main/ansi/margin.go): `ansi/margin.go`

### Style Configuration

- [Style Selection](https://github.com/charmbracelet/glamour/blob/main/glamour.go): `glamour.go`
- [Style Configurations](https://github.com/charmbracelet/glamour/blob/main/ansi/style.go): `ansi/style.go`
- [Built-in Styles](https://github.com/charmbracelet/glamour/blob/main/styles/styles.go): `styles/styles.go`

### Rendering Features

- [Code Blocks](https://github.com/charmbracelet/glamour/blob/main/ansi/codeblock.go): `ansi/codeblock.go`
- **Chroma Highlighter**
- [Hyperlinks](https://github.com/charmbracelet/glamour/blob/main/ansi/link.go): `ansi/link.go`
- [Table Link Footers](https://github.com/charmbracelet/glamour/blob/main/ansi/table_links.go): `ansi/table_links.go`
- [URL Shortening](https://github.com/charmbracelet/glamour/blob/main/internal/autolink/autolink.go): `internal/autolink/autolink.go`
- **Emoji Extension**

### Other components

- **Go Application**
- **ANSI Output**

## Connections

- Go Application → Term Renderer: provides Markdown (evidence: `README.md`)
- Term Renderer → Goldmark Parser: parses Markdown (evidence: `glamour.go`)
- Goldmark Parser → AST Element Mapping: supplies AST
- AST Element Mapping → Styled Primitives: maps elements (evidence: `ansi/elements.go`)
- AST Element Mapping → Code Blocks: creates code blocks (evidence: `ansi/elements.go`)
- Code Blocks → Chroma Highlighter: highlights code (evidence: `ansi/codeblock.go`)
- AST Element Mapping → Hyperlinks: creates links (evidence: `ansi/elements.go`)
- AST Element Mapping → Table Link Footers: collects table links (evidence: `ansi/elements.go`)
- AST Element Mapping → URL Shortening: shortens URLs (evidence: `ansi/elements.go`)
- Table Link Footers → URL Shortening: shortens URLs (evidence: `ansi/table_links.go`)
- Term Renderer → Emoji Extension: enables extension (evidence: `glamour.go`)
- Term Renderer → Style Selection: applies options (evidence: `glamour.go`)
- Style Selection → Built-in Styles: selects defaults (evidence: `glamour.go`)
- Built-in Styles → Style Configurations: defines styles (evidence: `styles/styles.go`)
- Styled Primitives → ANSI Output: writes styled text
- Margin Layout → ANSI Output: formats output
- Term Renderer → ANSI Output: returns rendered text (evidence: `README.md`)
