style.go

 1package common
 2
 3import (
 4	"github.com/charmbracelet/colorprofile"
 5	gansi "github.com/charmbracelet/glamour/v2/ansi"
 6	"github.com/charmbracelet/glamour/v2/styles"
 7)
 8
 9// DefaultColorProfile is the default color profile used by the SSH server.
10var DefaultColorProfile = colorprofile.ANSI256
11
12func strptr(s string) *string {
13	return &s
14}
15
16// StyleConfig returns the default Glamour style configuration.
17func StyleConfig() gansi.StyleConfig {
18	noColor := strptr("")
19	s := styles.DarkStyleConfig
20	s.H1.BackgroundColor = noColor
21	s.H1.Prefix = "# "
22	s.H1.Suffix = ""
23	s.H1.Color = strptr("39")
24	s.Document.StylePrimitive.Color = noColor
25	s.CodeBlock.Chroma.Text.Color = noColor
26	s.CodeBlock.Chroma.Name.Color = noColor
27	// This fixes an issue with the default style config. For example
28	// highlighting empty spaces with red in Dockerfile type.
29	s.CodeBlock.Chroma.Error.BackgroundColor = noColor
30	return s
31}
32
33// StyleRenderer returns a new Glamour renderer with the DefaultColorProfile.
34func StyleRenderer() gansi.RenderContext {
35	return StyleRendererWithStyles(StyleConfig())
36}
37
38// StyleRendererWithStyles returns a new Glamour renderer with the
39// DefaultColorProfile and styles.
40func StyleRendererWithStyles(styles gansi.StyleConfig) gansi.RenderContext {
41	return gansi.NewRenderContext(gansi.Options{
42		Styles: styles,
43	})
44}