fix: use TokyoNight config for tokyo-night code rendering

GlamourStyle's code-block branch mapped the tokyo-night style to
DraculaStyleConfig, so 'glow --style tokyo-night <codefile>' rendered code
with Dracula colors instead of Tokyo Night. glamour exports a distinct
TokyoNightStyleConfig; use it. Every other case maps to its own config.

Signed-off-by: Seonghyun Hong <s3onghyun.hong@gmail.com>
This commit is contained in:
Seonghyun Hong 2026-06-18 21:24:53 +09:00
commit 5c027db556
2 changed files with 37 additions and 1 deletions

View file

@ -101,7 +101,7 @@ func GlamourStyle(style string, isCode bool) glamour.TermRendererOption {
case styles.DraculaStyle:
styleConfig = styles.DraculaStyleConfig
case styles.TokyoNightStyle:
styleConfig = styles.DraculaStyleConfig
styleConfig = styles.TokyoNightStyleConfig
default:
return glamour.WithStylesFromJSONFile(style)
}

36
utils/utils_test.go Normal file
View file

@ -0,0 +1,36 @@
package utils
import (
"testing"
"github.com/charmbracelet/glamour"
"github.com/charmbracelet/glamour/styles"
)
// renderCode renders a fenced code block with the given style in code mode.
func renderCode(t *testing.T, style string) string {
t.Helper()
r, err := glamour.NewTermRenderer(GlamourStyle(style, true))
if err != nil {
t.Fatalf("new renderer for %q: %v", style, err)
}
out, err := r.Render("```go\nfmt.Println(\"hello\")\n```\n")
if err != nil {
t.Fatalf("render with %q: %v", style, err)
}
return out
}
// TestGlamourStyleTokyoNightCodeDistinctFromDracula guards against the
// tokyo-night code style being mapped to the dracula StyleConfig. The two
// themes use different colors, so their rendered code output must differ.
func TestGlamourStyleTokyoNightCodeDistinctFromDracula(t *testing.T) {
t.Setenv("CLICOLOR_FORCE", "1") // force ANSI color so styles are distinguishable
tokyo := renderCode(t, styles.TokyoNightStyle)
dracula := renderCode(t, styles.DraculaStyle)
if tokyo == dracula {
t.Errorf("tokyo-night code rendering is identical to dracula; GlamourStyle must use TokyoNightStyleConfig")
}
}