From 5c027db556a5cf370d06dd06cb9d612f561b1e27 Mon Sep 17 00:00:00 2001 From: Seonghyun Hong Date: Thu, 18 Jun 2026 21:24:53 +0900 Subject: [PATCH] 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 ' 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 --- utils/utils.go | 2 +- utils/utils_test.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 utils/utils_test.go diff --git a/utils/utils.go b/utils/utils.go index 9f33a1e..205467d 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -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) } diff --git a/utils/utils_test.go b/utils/utils_test.go new file mode 100644 index 0000000..6e688f6 --- /dev/null +++ b/utils/utils_test.go @@ -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") + } +}