mirror of
https://github.com/charmbracelet/glow.git
synced 2026-08-24 00:54:17 +02:00
Merge 5c027db556 into e5cb757278
This commit is contained in:
commit
5c132231cf
2 changed files with 37 additions and 1 deletions
|
|
@ -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
36
utils/utils_test.go
Normal 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")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue