This commit is contained in:
SEONGHYUN HONG 2026-08-04 18:41:34 +04:00 committed by GitHub
commit 5c132231cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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")
}
}