1package styles
2
3import (
4 "github.com/charmbracelet/glamour/ansi"
5 "github.com/charmbracelet/lipgloss"
6)
7
8const defaultMargin = 1
9
10// Helper functions for style pointers
11func boolPtr(b bool) *bool { return &b }
12func stringPtr(s string) *string { return &s }
13func uintPtr(u uint) *uint { return &u }
14
15// CatppuccinMarkdownStyle is the Catppuccin Mocha style for Glamour markdown rendering.
16func CatppuccinMarkdownStyle() ansi.StyleConfig {
17 isDark := lipgloss.HasDarkBackground()
18 if isDark {
19 return catppuccinDark
20 }
21 return catppuccinLight
22}
23
24var catppuccinDark = ansi.StyleConfig{
25 Document: ansi.StyleBlock{
26 StylePrimitive: ansi.StylePrimitive{
27 BlockPrefix: "\n",
28 BlockSuffix: "",
29 Color: stringPtr(dark.Text().Hex),
30 },
31 Margin: uintPtr(defaultMargin),
32 },
33 BlockQuote: ansi.StyleBlock{
34 StylePrimitive: ansi.StylePrimitive{
35 Color: stringPtr(dark.Yellow().Hex),
36 Italic: boolPtr(true),
37 Prefix: "ā ",
38 },
39 Indent: uintPtr(1),
40 Margin: uintPtr(defaultMargin),
41 },
42 List: ansi.StyleList{
43 LevelIndent: defaultMargin,
44 StyleBlock: ansi.StyleBlock{
45 StylePrimitive: ansi.StylePrimitive{
46 Color: stringPtr(dark.Text().Hex),
47 },
48 },
49 },
50 Heading: ansi.StyleBlock{
51 StylePrimitive: ansi.StylePrimitive{
52 BlockSuffix: "\n",
53 Color: stringPtr(dark.Mauve().Hex),
54 Bold: boolPtr(true),
55 },
56 },
57 H1: ansi.StyleBlock{
58 StylePrimitive: ansi.StylePrimitive{
59 Prefix: "# ",
60 Color: stringPtr(dark.Lavender().Hex),
61 Bold: boolPtr(true),
62 BlockPrefix: "\n",
63 },
64 },
65 H2: ansi.StyleBlock{
66 StylePrimitive: ansi.StylePrimitive{
67 Prefix: "## ",
68 Color: stringPtr(dark.Mauve().Hex),
69 Bold: boolPtr(true),
70 },
71 },
72 H3: ansi.StyleBlock{
73 StylePrimitive: ansi.StylePrimitive{
74 Prefix: "### ",
75 Color: stringPtr(dark.Pink().Hex),
76 Bold: boolPtr(true),
77 },
78 },
79 H4: ansi.StyleBlock{
80 StylePrimitive: ansi.StylePrimitive{
81 Prefix: "#### ",
82 Color: stringPtr(dark.Flamingo().Hex),
83 Bold: boolPtr(true),
84 },
85 },
86 H5: ansi.StyleBlock{
87 StylePrimitive: ansi.StylePrimitive{
88 Prefix: "##### ",
89 Color: stringPtr(dark.Rosewater().Hex),
90 Bold: boolPtr(true),
91 },
92 },
93 H6: ansi.StyleBlock{
94 StylePrimitive: ansi.StylePrimitive{
95 Prefix: "###### ",
96 Color: stringPtr(dark.Rosewater().Hex),
97 Bold: boolPtr(true),
98 },
99 },
100 Strikethrough: ansi.StylePrimitive{
101 CrossedOut: boolPtr(true),
102 Color: stringPtr(dark.Overlay1().Hex),
103 },
104 Emph: ansi.StylePrimitive{
105 Color: stringPtr(dark.Yellow().Hex),
106 Italic: boolPtr(true),
107 },
108 Strong: ansi.StylePrimitive{
109 Bold: boolPtr(true),
110 Color: stringPtr(dark.Peach().Hex),
111 },
112 HorizontalRule: ansi.StylePrimitive{
113 Color: stringPtr(dark.Overlay0().Hex),
114 Format: "\nāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n",
115 },
116 Item: ansi.StylePrimitive{
117 BlockPrefix: "⢠",
118 Color: stringPtr(dark.Blue().Hex),
119 },
120 Enumeration: ansi.StylePrimitive{
121 BlockPrefix: ". ",
122 Color: stringPtr(dark.Sky().Hex),
123 },
124 Task: ansi.StyleTask{
125 StylePrimitive: ansi.StylePrimitive{},
126 Ticked: "[ā] ",
127 Unticked: "[ ] ",
128 },
129 Link: ansi.StylePrimitive{
130 Color: stringPtr(dark.Sky().Hex),
131 Underline: boolPtr(true),
132 },
133 LinkText: ansi.StylePrimitive{
134 Color: stringPtr(dark.Pink().Hex),
135 Bold: boolPtr(true),
136 },
137 Image: ansi.StylePrimitive{
138 Color: stringPtr(dark.Sapphire().Hex),
139 Underline: boolPtr(true),
140 Format: "š¼ {{.text}}",
141 },
142 ImageText: ansi.StylePrimitive{
143 Color: stringPtr(dark.Pink().Hex),
144 Format: "{{.text}}",
145 },
146 Code: ansi.StyleBlock{
147 StylePrimitive: ansi.StylePrimitive{
148 Color: stringPtr(dark.Green().Hex),
149 Prefix: "",
150 Suffix: "",
151 },
152 },
153 CodeBlock: ansi.StyleCodeBlock{
154 StyleBlock: ansi.StyleBlock{
155 StylePrimitive: ansi.StylePrimitive{
156 Prefix: " ",
157 Color: stringPtr(dark.Text().Hex),
158 },
159
160 Margin: uintPtr(defaultMargin),
161 },
162 Chroma: &ansi.Chroma{
163 Text: ansi.StylePrimitive{
164 Color: stringPtr(dark.Text().Hex),
165 },
166 Error: ansi.StylePrimitive{
167 Color: stringPtr(dark.Text().Hex),
168 },
169 Comment: ansi.StylePrimitive{
170 Color: stringPtr(dark.Overlay1().Hex),
171 },
172 CommentPreproc: ansi.StylePrimitive{
173 Color: stringPtr(dark.Pink().Hex),
174 },
175 Keyword: ansi.StylePrimitive{
176 Color: stringPtr(dark.Pink().Hex),
177 },
178 KeywordReserved: ansi.StylePrimitive{
179 Color: stringPtr(dark.Pink().Hex),
180 },
181 KeywordNamespace: ansi.StylePrimitive{
182 Color: stringPtr(dark.Pink().Hex),
183 },
184 KeywordType: ansi.StylePrimitive{
185 Color: stringPtr(dark.Sky().Hex),
186 },
187 Operator: ansi.StylePrimitive{
188 Color: stringPtr(dark.Pink().Hex),
189 },
190 Punctuation: ansi.StylePrimitive{
191 Color: stringPtr(dark.Text().Hex),
192 },
193 Name: ansi.StylePrimitive{
194 Color: stringPtr(dark.Sky().Hex),
195 },
196 NameBuiltin: ansi.StylePrimitive{
197 Color: stringPtr(dark.Sky().Hex),
198 },
199 NameTag: ansi.StylePrimitive{
200 Color: stringPtr(dark.Pink().Hex),
201 },
202 NameAttribute: ansi.StylePrimitive{
203 Color: stringPtr(dark.Green().Hex),
204 },
205 NameClass: ansi.StylePrimitive{
206 Color: stringPtr(dark.Sky().Hex),
207 },
208 NameConstant: ansi.StylePrimitive{
209 Color: stringPtr(dark.Mauve().Hex),
210 },
211 NameDecorator: ansi.StylePrimitive{
212 Color: stringPtr(dark.Green().Hex),
213 },
214 NameFunction: ansi.StylePrimitive{
215 Color: stringPtr(dark.Green().Hex),
216 },
217 LiteralNumber: ansi.StylePrimitive{
218 Color: stringPtr(dark.Teal().Hex),
219 },
220 LiteralString: ansi.StylePrimitive{
221 Color: stringPtr(dark.Yellow().Hex),
222 },
223 LiteralStringEscape: ansi.StylePrimitive{
224 Color: stringPtr(dark.Pink().Hex),
225 },
226 GenericDeleted: ansi.StylePrimitive{
227 Color: stringPtr(dark.Red().Hex),
228 },
229 GenericEmph: ansi.StylePrimitive{
230 Color: stringPtr(dark.Yellow().Hex),
231 Italic: boolPtr(true),
232 },
233 GenericInserted: ansi.StylePrimitive{
234 Color: stringPtr(dark.Green().Hex),
235 },
236 GenericStrong: ansi.StylePrimitive{
237 Color: stringPtr(dark.Peach().Hex),
238 Bold: boolPtr(true),
239 },
240 GenericSubheading: ansi.StylePrimitive{
241 Color: stringPtr(dark.Mauve().Hex),
242 },
243 },
244 },
245 Table: ansi.StyleTable{
246 StyleBlock: ansi.StyleBlock{
247 StylePrimitive: ansi.StylePrimitive{
248 BlockPrefix: "\n",
249 BlockSuffix: "\n",
250 },
251 },
252 CenterSeparator: stringPtr("ā¼"),
253 ColumnSeparator: stringPtr("ā"),
254 RowSeparator: stringPtr("ā"),
255 },
256 DefinitionDescription: ansi.StylePrimitive{
257 BlockPrefix: "\n ⯠",
258 Color: stringPtr(dark.Sapphire().Hex),
259 },
260}
261
262var catppuccinLight = ansi.StyleConfig{
263 Document: ansi.StyleBlock{
264 StylePrimitive: ansi.StylePrimitive{
265 BlockPrefix: "\n",
266 BlockSuffix: "\n",
267 Color: stringPtr(light.Text().Hex),
268 },
269 Margin: uintPtr(defaultMargin),
270 },
271 BlockQuote: ansi.StyleBlock{
272 StylePrimitive: ansi.StylePrimitive{
273 Color: stringPtr(light.Yellow().Hex),
274 Italic: boolPtr(true),
275 Prefix: "ā ",
276 },
277 Indent: uintPtr(1),
278 Margin: uintPtr(defaultMargin),
279 },
280 List: ansi.StyleList{
281 LevelIndent: defaultMargin,
282 StyleBlock: ansi.StyleBlock{
283 StylePrimitive: ansi.StylePrimitive{
284 Color: stringPtr(light.Text().Hex),
285 },
286 },
287 },
288 Heading: ansi.StyleBlock{
289 StylePrimitive: ansi.StylePrimitive{
290 BlockSuffix: "\n",
291 Color: stringPtr(light.Mauve().Hex),
292 Bold: boolPtr(true),
293 },
294 },
295 H1: ansi.StyleBlock{
296 StylePrimitive: ansi.StylePrimitive{
297 Prefix: "# ",
298 Color: stringPtr(light.Lavender().Hex),
299 Bold: boolPtr(true),
300 BlockPrefix: "\n",
301 },
302 },
303 H2: ansi.StyleBlock{
304 StylePrimitive: ansi.StylePrimitive{
305 Prefix: "## ",
306 Color: stringPtr(light.Mauve().Hex),
307 Bold: boolPtr(true),
308 },
309 },
310 H3: ansi.StyleBlock{
311 StylePrimitive: ansi.StylePrimitive{
312 Prefix: "### ",
313 Color: stringPtr(light.Pink().Hex),
314 Bold: boolPtr(true),
315 },
316 },
317 H4: ansi.StyleBlock{
318 StylePrimitive: ansi.StylePrimitive{
319 Prefix: "#### ",
320 Color: stringPtr(light.Flamingo().Hex),
321 Bold: boolPtr(true),
322 },
323 },
324 H5: ansi.StyleBlock{
325 StylePrimitive: ansi.StylePrimitive{
326 Prefix: "##### ",
327 Color: stringPtr(light.Rosewater().Hex),
328 Bold: boolPtr(true),
329 },
330 },
331 H6: ansi.StyleBlock{
332 StylePrimitive: ansi.StylePrimitive{
333 Prefix: "###### ",
334 Color: stringPtr(light.Rosewater().Hex),
335 Bold: boolPtr(true),
336 },
337 },
338 Strikethrough: ansi.StylePrimitive{
339 CrossedOut: boolPtr(true),
340 Color: stringPtr(light.Overlay1().Hex),
341 },
342 Emph: ansi.StylePrimitive{
343 Color: stringPtr(light.Yellow().Hex),
344 Italic: boolPtr(true),
345 },
346 Strong: ansi.StylePrimitive{
347 Bold: boolPtr(true),
348 Color: stringPtr(light.Peach().Hex),
349 },
350 HorizontalRule: ansi.StylePrimitive{
351 Color: stringPtr(light.Overlay0().Hex),
352 Format: "\nāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n",
353 },
354 Item: ansi.StylePrimitive{
355 BlockPrefix: "⢠",
356 Color: stringPtr(light.Blue().Hex),
357 },
358 Enumeration: ansi.StylePrimitive{
359 BlockPrefix: ". ",
360 Color: stringPtr(light.Sky().Hex),
361 },
362 Task: ansi.StyleTask{
363 StylePrimitive: ansi.StylePrimitive{},
364 Ticked: "[ā] ",
365 Unticked: "[ ] ",
366 },
367 Link: ansi.StylePrimitive{
368 Color: stringPtr(light.Sky().Hex),
369 Underline: boolPtr(true),
370 },
371 LinkText: ansi.StylePrimitive{
372 Color: stringPtr(light.Pink().Hex),
373 Bold: boolPtr(true),
374 },
375 Image: ansi.StylePrimitive{
376 Color: stringPtr(light.Sapphire().Hex),
377 Underline: boolPtr(true),
378 Format: "š¼ {{.text}}",
379 },
380 ImageText: ansi.StylePrimitive{
381 Color: stringPtr(light.Pink().Hex),
382 Format: "{{.text}}",
383 },
384 Code: ansi.StyleBlock{
385 StylePrimitive: ansi.StylePrimitive{
386 Color: stringPtr(light.Green().Hex),
387 Prefix: " ",
388 Suffix: " ",
389 },
390 },
391 CodeBlock: ansi.StyleCodeBlock{
392 StyleBlock: ansi.StyleBlock{
393 StylePrimitive: ansi.StylePrimitive{
394 Prefix: " ",
395 Color: stringPtr(light.Text().Hex),
396 },
397
398 Margin: uintPtr(defaultMargin),
399 },
400 Chroma: &ansi.Chroma{
401 Text: ansi.StylePrimitive{
402 Color: stringPtr(light.Text().Hex),
403 },
404 Error: ansi.StylePrimitive{
405 Color: stringPtr(light.Text().Hex),
406 },
407 Comment: ansi.StylePrimitive{
408 Color: stringPtr(light.Overlay1().Hex),
409 },
410 CommentPreproc: ansi.StylePrimitive{
411 Color: stringPtr(light.Pink().Hex),
412 },
413 Keyword: ansi.StylePrimitive{
414 Color: stringPtr(light.Pink().Hex),
415 },
416 KeywordReserved: ansi.StylePrimitive{
417 Color: stringPtr(light.Pink().Hex),
418 },
419 KeywordNamespace: ansi.StylePrimitive{
420 Color: stringPtr(light.Pink().Hex),
421 },
422 KeywordType: ansi.StylePrimitive{
423 Color: stringPtr(light.Sky().Hex),
424 },
425 Operator: ansi.StylePrimitive{
426 Color: stringPtr(light.Pink().Hex),
427 },
428 Punctuation: ansi.StylePrimitive{
429 Color: stringPtr(light.Text().Hex),
430 },
431 Name: ansi.StylePrimitive{
432 Color: stringPtr(light.Sky().Hex),
433 },
434 NameBuiltin: ansi.StylePrimitive{
435 Color: stringPtr(light.Sky().Hex),
436 },
437 NameTag: ansi.StylePrimitive{
438 Color: stringPtr(light.Pink().Hex),
439 },
440 NameAttribute: ansi.StylePrimitive{
441 Color: stringPtr(light.Green().Hex),
442 },
443 NameClass: ansi.StylePrimitive{
444 Color: stringPtr(light.Sky().Hex),
445 },
446 NameConstant: ansi.StylePrimitive{
447 Color: stringPtr(light.Mauve().Hex),
448 },
449 NameDecorator: ansi.StylePrimitive{
450 Color: stringPtr(light.Green().Hex),
451 },
452 NameFunction: ansi.StylePrimitive{
453 Color: stringPtr(light.Green().Hex),
454 },
455 LiteralNumber: ansi.StylePrimitive{
456 Color: stringPtr(light.Teal().Hex),
457 },
458 LiteralString: ansi.StylePrimitive{
459 Color: stringPtr(light.Yellow().Hex),
460 },
461 LiteralStringEscape: ansi.StylePrimitive{
462 Color: stringPtr(light.Pink().Hex),
463 },
464 GenericDeleted: ansi.StylePrimitive{
465 Color: stringPtr(light.Red().Hex),
466 },
467 GenericEmph: ansi.StylePrimitive{
468 Color: stringPtr(light.Yellow().Hex),
469 Italic: boolPtr(true),
470 },
471 GenericInserted: ansi.StylePrimitive{
472 Color: stringPtr(light.Green().Hex),
473 },
474 GenericStrong: ansi.StylePrimitive{
475 Color: stringPtr(light.Peach().Hex),
476 Bold: boolPtr(true),
477 },
478 GenericSubheading: ansi.StylePrimitive{
479 Color: stringPtr(light.Mauve().Hex),
480 },
481 },
482 },
483 Table: ansi.StyleTable{
484 StyleBlock: ansi.StyleBlock{
485 StylePrimitive: ansi.StylePrimitive{
486 BlockPrefix: "\n",
487 BlockSuffix: "\n",
488 },
489 },
490 CenterSeparator: stringPtr("ā¼"),
491 ColumnSeparator: stringPtr("ā"),
492 RowSeparator: stringPtr("ā"),
493 },
494 DefinitionDescription: ansi.StylePrimitive{
495 BlockPrefix: "\n ⯠",
496 Color: stringPtr(light.Sapphire().Hex),
497 },
498}