Repository navigation
Add accessible themes - #182
Conversation
4ed71e2 to
9ccc524
Compare
9ccc524 to
ac8e455
Compare
andyfeller
left a comment
There was a problem hiding this comment.
@jtmcg : Really like what I'm seeing especially the tests! Nothing majorly blocking, some curious questions for your thoughts on various topics.
| func accessibleDarkStyleConfig() ansi.StyleConfig { | ||
| cfg := glamour.DarkStyleConfig | ||
|
|
||
| // Text color | ||
| cfg.Document.StylePrimitive.Color = White.ValuePtr() | ||
|
|
||
| // Link colors | ||
| cfg.Link.Color = Black.ValuePtr() | ||
| cfg.LinkText.Color = BrightCyan.ValuePtr() | ||
|
|
||
| // Heading colors | ||
| cfg.Heading.StylePrimitive.Color = BrightMagenta.ValuePtr() | ||
| cfg.H1.StylePrimitive.Color = BrightWhite.ValuePtr() | ||
| cfg.H1.StylePrimitive.BackgroundColor = BrightBlue.ValuePtr() | ||
|
|
||
| // Code colors | ||
| cfg.Code.BackgroundColor = BrightWhite.ValuePtr() | ||
| cfg.Code.Color = Red.ValuePtr() | ||
|
|
||
| // Image colors | ||
| cfg.Image.Color = BrightMagenta.ValuePtr() | ||
|
|
||
| // Horizontal rule colors | ||
| cfg.HorizontalRule.Color = White.ValuePtr() | ||
|
|
||
| return cfg | ||
| } |
There was a problem hiding this comment.
No right or wrong answer, but I take it you think we should selectively override the colors versus duplicating the whole style and maintaining it separately?
There was a problem hiding this comment.
The side-effects of overwriting the glamour styles were giving me pause... Mostly, I think this makes following the logic of what's happening for the accessibility experience easier to follow. After we chatted the other day about "how will we know if we're light or dark?" and the answer being "let glamour decide" I thought it more helpful to put the accessible things where that decision happens and be explicit about how its happening.
Compare my approach:
go-gh/pkg/markdown/markdown.go
Lines 35 to 50 in ac8e455
To yours
go-gh/pkg/markdown/markdown.go
Lines 54 to 68 in 0c30d0f
I find the logic of "this is how we are choosing to use the accessible light/dark theme" much easier to understand in the former vs the latter.
What are your thoughts?
There was a problem hiding this comment.
The side-effects of overwriting the glamour styles were giving me pause... Mostly, I think this makes following the logic of what's happening for the accessibility experience easier to follow.
Sorry, let me clarify.
I understand why these changes only override the styles if WithTheme() is called as someone using markdown.Render() without providing the TermRenderer will not get any color.
My question was primarily focused on what value we'd get by statically duplicating DarkStyleConfig and LightStyleConfig variables in cli/go-gh over run-time copying and overriding specific fields.
Not something that needs to be done; just curious for your thoughts. I can imagine this might make sense in the future as we increase the scope of customizing the styles including code block rendering, modifiers, and/or changing the resulting format of certain elements.
There was a problem hiding this comment.
Oh, I understand, like why not "copy/paste" the darkStyleConfig from glamour into go-gh, rename for accessibility, and use that instead of creating this at run-time?
There's two benefits to this, I think:
- This makes it really clear how we're deviating from Glamour's styles for accessibility
- Given we are talking about contributing back to Glamour for this, the less we have to maintain here the better.
cc13bb1 to
7f030f6
Compare
7f030f6 to
b76f1c0
Compare
andyfeller
left a comment
There was a problem hiding this comment.
Only 1 minor change to fix and let's ship it!
I'm leaving comments regarding a few errant thoughts on other aspects but nothing that's blocking for now. I look forward to seeing how our testing around style customization evolves.
| func Test_accessibleDarkStyleConfig(t *testing.T) { | ||
| cfg := accessibleDarkStyleConfig() | ||
| assert.Equal(t, White.StrPtr(), cfg.Document.StylePrimitive.Color) | ||
| assert.Equal(t, BrightCyan.StrPtr(), cfg.Link.Color) | ||
| assert.Equal(t, BrightMagenta.StrPtr(), cfg.Heading.StylePrimitive.Color) | ||
| assert.Equal(t, BrightWhite.StrPtr(), cfg.H1.StylePrimitive.Color) | ||
| assert.Equal(t, BrightBlue.StrPtr(), cfg.H1.StylePrimitive.BackgroundColor) | ||
| assert.Equal(t, BrightWhite.StrPtr(), cfg.Code.BackgroundColor) | ||
| assert.Equal(t, Red.StrPtr(), cfg.Code.Color) | ||
| assert.Equal(t, BrightMagenta.StrPtr(), cfg.Image.Color) | ||
| assert.Equal(t, White.StrPtr(), cfg.HorizontalRule.Color) | ||
|
|
||
| // Test that we haven't changed the original style | ||
| assert.Equal(t, styles.LightStyleConfig.H2, cfg.H2) | ||
| } |
There was a problem hiding this comment.
What are your thoughts if we are capable of building a more comprehensive test that can traverse ansi.StyleConfig type for any colors we did not override to ensure they are customizable?
I realize that will be significant enough work to be a separate issue and PR, but want to gather your thoughts while we're here.
There was a problem hiding this comment.
While it would be an interesting engineering problem, I don't think its one we should solve until we have a reason to, i.e. we screw something up and this suggestion would keep us from doing it again.
Changes
WithThemeNotes
The link colors weren't rendering correctly with the provided markdown colors. In particular, it seemed that the link color was overriding the link text color. As such, I've changed the link stylings so that the text renders in either the bright blue or bright cyan.
Testing
cli/clirepo, add areplacedirective pointing at your local version ofgo-gh:go mod edit -replace=github.com/cli/go-gh/v2={YOUR_LOCAL_PATH}/go-ghACCESSIBLE=true ./bin/gh repo viewScreenshots
Dark Theme
<= current | accessible =>

Light Theme
<= current | accessible =>
