Skip to content

Commit de80002

Browse files
authored
Merge pull request #641 from rumpl/feat-markdown-theme
Create our own markdown theme
2 parents 72b8eb5 + 5dda01e commit de80002

3 files changed

Lines changed: 418 additions & 47 deletions

File tree

pkg/tui/components/markdown/renderer.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,16 @@ package markdown
22

33
import (
44
"github.com/charmbracelet/glamour/v2"
5-
allstyles "github.com/charmbracelet/glamour/v2/styles"
6-
)
75

8-
func uintPtr(u uint) *uint { return &u }
6+
"github.com/docker/cagent/pkg/tui/styles"
7+
)
98

109
func NewRenderer(width int) *glamour.TermRenderer {
11-
customDarkStyle := *allstyles.DefaultStyles["dark"]
12-
13-
customDarkStyle.Document.Margin = uintPtr(0)
14-
customDarkStyle.Document.BlockPrefix = ""
15-
customDarkStyle.Document.BlockSuffix = ""
16-
17-
// The default indent token is buggy. It breaks line splitting.
18-
customDarkStyle.BlockQuote.IndentToken = nil
10+
style := styles.MarkdownStyle()
1911

2012
r, _ := glamour.NewTermRenderer(
2113
glamour.WithWordWrap(min(width, 120)),
22-
glamour.WithStyles(customDarkStyle),
14+
glamour.WithStyles(style),
2315
)
2416
return r
2517
}

pkg/tui/components/tool/syntax.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55

66
"github.com/alecthomas/chroma/v2"
77
"github.com/alecthomas/chroma/v2/lexers"
8-
chromastyles "github.com/alecthomas/chroma/v2/styles"
98
"github.com/aymanbagabas/go-udiff"
109
"github.com/charmbracelet/lipgloss/v2"
1110
"github.com/mattn/go-runewidth"
@@ -21,11 +20,7 @@ func syntaxHighlight(code, filePath string) []chromaToken {
2120
}
2221
lexer = chroma.Coalesce(lexer)
2322

24-
style := chromastyles.Get("monokai")
25-
if style == nil {
26-
style = chromastyles.Fallback
27-
}
28-
23+
style := styles.ChromaStyle()
2924
iterator, err := lexer.Tokenise(nil, code)
3025
if err != nil {
3126
return []chromaToken{{Text: code, Style: lipgloss.NewStyle()}}
@@ -57,13 +52,11 @@ func chromaToLipgloss(tokenType chroma.TokenType, style *chroma.Style) lipgloss.
5752
lipStyle := lipgloss.NewStyle()
5853

5954
if entry.Colour.IsSet() {
60-
color := entry.Colour.String()
61-
lipStyle = lipStyle.Foreground(lipgloss.Color(color))
55+
lipStyle = lipStyle.Foreground(lipgloss.Color(entry.Colour.String()))
6256
}
6357

6458
if entry.Background.IsSet() {
65-
color := entry.Background.String()
66-
lipStyle = lipStyle.Background(lipgloss.Color(color))
59+
lipStyle = lipStyle.Background(lipgloss.Color(entry.Background.String()))
6760
}
6861

6962
if entry.Bold == chroma.Yes {

0 commit comments

Comments
 (0)