Skip to content

Commit 68a08b0

Browse files
committed
docs: how to support dynamic theme switching
1 parent 6fb9d92 commit 68a08b0

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

formatters/html/html.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,12 @@ func (f *Formatter) writeCSSRule(w io.Writer, comment string, selector string, s
461461
//
462462
// Rules are scoped by the style's mode (eg. ".chroma.dark") so that CSS
463463
// generated from a light and dark style can be combined without conflict.
464+
// To support dynamic theme switching, call WriteCSS with both styles,
465+
// concatenate the output, and toggle the wrapper's mode class (added
466+
// automatically by Format) at runtime. Tokens that one theme leaves
467+
// unstyled fall back to that theme's ".chroma.<mode>" text/background
468+
// via the CSS cascade; pass WithAllClasses(true) if you need every
469+
// token's rule materialised explicitly for both themes.
464470
func (f *Formatter) WriteCSS(w io.Writer, style *chroma.Style) error {
465471
css := f.styleCache.get(style, false)
466472
modeCls := f.modeClass(style)

0 commit comments

Comments
 (0)