1package styles
 2
 3import (
 4	"github.com/alecthomas/chroma/v2"
 5	"github.com/charmbracelet/glamour/v2/ansi"
 6)
 7
 8func chromaStyle(style ansi.StylePrimitive) string {
 9	var s string
10
11	if style.Color != nil {
12		s = *style.Color
13	}
14	if style.BackgroundColor != nil {
15		if s != "" {
16			s += " "
17		}
18		s += "bg:" + *style.BackgroundColor
19	}
20	if style.Italic != nil && *style.Italic {
21		if s != "" {
22			s += " "
23		}
24		s += "italic"
25	}
26	if style.Bold != nil && *style.Bold {
27		if s != "" {
28			s += " "
29		}
30		s += "bold"
31	}
32	if style.Underline != nil && *style.Underline {
33		if s != "" {
34			s += " "
35		}
36		s += "underline"
37	}
38
39	return s
40}
41
42func GetChromaTheme() chroma.StyleEntries {
43	t := CurrentTheme()
44	rules := t.S().Markdown.CodeBlock
45
46	return chroma.StyleEntries{
47		chroma.Text:                chromaStyle(rules.Chroma.Text),
48		chroma.Error:               chromaStyle(rules.Chroma.Error),
49		chroma.Comment:             chromaStyle(rules.Chroma.Comment),
50		chroma.CommentPreproc:      chromaStyle(rules.Chroma.CommentPreproc),
51		chroma.Keyword:             chromaStyle(rules.Chroma.Keyword),
52		chroma.KeywordReserved:     chromaStyle(rules.Chroma.KeywordReserved),
53		chroma.KeywordNamespace:    chromaStyle(rules.Chroma.KeywordNamespace),
54		chroma.KeywordType:         chromaStyle(rules.Chroma.KeywordType),
55		chroma.Operator:            chromaStyle(rules.Chroma.Operator),
56		chroma.Punctuation:         chromaStyle(rules.Chroma.Punctuation),
57		chroma.Name:                chromaStyle(rules.Chroma.Name),
58		chroma.NameBuiltin:         chromaStyle(rules.Chroma.NameBuiltin),
59		chroma.NameTag:             chromaStyle(rules.Chroma.NameTag),
60		chroma.NameAttribute:       chromaStyle(rules.Chroma.NameAttribute),
61		chroma.NameClass:           chromaStyle(rules.Chroma.NameClass),
62		chroma.NameConstant:        chromaStyle(rules.Chroma.NameConstant),
63		chroma.NameDecorator:       chromaStyle(rules.Chroma.NameDecorator),
64		chroma.NameException:       chromaStyle(rules.Chroma.NameException),
65		chroma.NameFunction:        chromaStyle(rules.Chroma.NameFunction),
66		chroma.NameOther:           chromaStyle(rules.Chroma.NameOther),
67		chroma.Literal:             chromaStyle(rules.Chroma.Literal),
68		chroma.LiteralNumber:       chromaStyle(rules.Chroma.LiteralNumber),
69		chroma.LiteralDate:         chromaStyle(rules.Chroma.LiteralDate),
70		chroma.LiteralString:       chromaStyle(rules.Chroma.LiteralString),
71		chroma.LiteralStringEscape: chromaStyle(rules.Chroma.LiteralStringEscape),
72		chroma.GenericDeleted:      chromaStyle(rules.Chroma.GenericDeleted),
73		chroma.GenericEmph:         chromaStyle(rules.Chroma.GenericEmph),
74		chroma.GenericInserted:     chromaStyle(rules.Chroma.GenericInserted),
75		chroma.GenericStrong:       chromaStyle(rules.Chroma.GenericStrong),
76		chroma.GenericSubheading:   chromaStyle(rules.Chroma.GenericSubheading),
77		chroma.Background:          chromaStyle(rules.Chroma.Background),
78	}
79}