-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add term renderer option for chroma formatter #395
base: master
Are you sure you want to change the base?
Conversation
Previously, code blocks were hardcoded to render 8-bit color depth regardless of user preferences. This made it difficult to provide accessible experiences for users who depend upon native terminals' ability to change how base 16 ANSI colors are viewed. Now, with the functional options pattern, `WithChromaFormatter` term renderer allows users to choose a different chroma formatter, which allows for selection of one that downsamples colors when rendering code blocks.
One other addition in this pull request is
|
// NewTermRenderer returns a new TermRenderer the given options. | |
func NewTermRenderer(options ...TermRendererOption) (*TermRenderer, error) { | |
tr := &TermRenderer{ | |
md: goldmark.New( | |
goldmark.WithExtensions( | |
extension.GFM, | |
extension.DefinitionList, | |
), | |
goldmark.WithParserOptions( | |
parser.WithAutoHeadingID(), | |
), | |
), | |
ansiOptions: ansi.Options{ | |
WordWrap: defaultWidth, | |
ColorProfile: termenv.TrueColor, | |
}, | |
} | |
for _, o := range options { | |
if err := o(tr); err != nil { | |
return nil, err | |
} | |
} |
We thought this could benefit other glamour
users in similar situations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
This relates to #376
Previously, code blocks were hardcoded to render 8-bit color depth regardless of user preferences. This made it difficult to provide accessible experiences for users who depend upon native terminals' ability to change how base 16 ANSI colors are viewed.
Now, with the functional options pattern,
WithChromaFormatter
term renderer allows users to choose a different chroma formatter, which allows for selection of one that downsamples colors when rendering code blocks.Credit @andyfeller who actually wrote this, I'm really just the PR monkey.