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