@@ -1,16 +1,30 @@
1package common
1package common
4 "charm.land/glamour/v2"
6 "charm.land/glamour/v2"
7+ "github.com/alecthomas/chroma/v2/formatters"
5 "github.com/charmbracelet/crush/internal/ui/styles"
8 "github.com/charmbracelet/crush/internal/ui/styles"
9+ "github.com/charmbracelet/crush/internal/ui/xchroma"
12+const formatterName = "crush"
15+ // NOTE: Glamour does not offer us an option to pass the formatter
16+ // implementation directly. We need to register and use by name.
18+ formatters.Register(formatterName, xchroma.Formatter(zero, nil))
8// MarkdownRenderer returns a glamour [glamour.TermRenderer] configured with
21// MarkdownRenderer returns a glamour [glamour.TermRenderer] configured with
9// the given styles and width.
22// the given styles and width.
10func MarkdownRenderer(sty *styles.Styles, width int) *glamour.TermRenderer {
23func MarkdownRenderer(sty *styles.Styles, width int) *glamour.TermRenderer {
11 r, _ := glamour.NewTermRenderer(
24 r, _ := glamour.NewTermRenderer(
12 glamour.WithStyles(sty.Markdown),
25 glamour.WithStyles(sty.Markdown),
13 glamour.WithWordWrap(width),
26 glamour.WithWordWrap(width),
27+ glamour.WithChromaFormatter(formatterName),
@@ -21,6 +35,7 @@ func PlainMarkdownRenderer(sty *styles.Styles, width int) *glamour.TermRenderer
21 r, _ := glamour.NewTermRenderer(
35 r, _ := glamour.NewTermRenderer(
22 glamour.WithStyles(sty.PlainMarkdown),
36 glamour.WithStyles(sty.PlainMarkdown),
23 glamour.WithWordWrap(width),
37 glamour.WithWordWrap(width),
38+ glamour.WithChromaFormatter(formatterName),