mirror of
https://github.com/alecthomas/chroma.git
synced 2025-03-19 21:10:15 +02:00
Ensure class names from default set exist.
This commit is contained in:
parent
2ca426a8d1
commit
80d3b96869
@ -246,11 +246,14 @@ func (f *Formatter) styleToCSS(style *chroma.Style) map[chroma.TokenType]string
|
|||||||
classes := map[chroma.TokenType]string{}
|
classes := map[chroma.TokenType]string{}
|
||||||
bg := style.Get(chroma.Background)
|
bg := style.Get(chroma.Background)
|
||||||
// Convert the style.
|
// Convert the style.
|
||||||
for _, t := range style.Types() {
|
for t := range chroma.StandardTypes {
|
||||||
entry := style.Get(t)
|
entry := style.Get(t)
|
||||||
if t != chroma.Background {
|
if t != chroma.Background {
|
||||||
entry = entry.Sub(bg)
|
entry = entry.Sub(bg)
|
||||||
}
|
}
|
||||||
|
if entry.IsZero() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
classes[t] = StyleEntryToCSS(entry)
|
classes[t] = StyleEntryToCSS(entry)
|
||||||
}
|
}
|
||||||
classes[chroma.Background] += f.tabWidthStyle()
|
classes[chroma.Background] += f.tabWidthStyle()
|
||||||
|
@ -13,8 +13,8 @@ func TestRemappingLexer(t *testing.T) {
|
|||||||
{`\w+`, Name, nil},
|
{`\w+`, Name, nil},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
lexer = TypeRemappingLexer(lexer, TypeRemappingMap{
|
lexer = TypeRemappingLexer(lexer, TypeMapping{
|
||||||
{Name, Keyword}: {"if", "else"},
|
{Name, Keyword, []string{"if", "else"}},
|
||||||
})
|
})
|
||||||
|
|
||||||
it, err := lexer.Tokenise(nil, `if true then print else end`)
|
it, err := lexer.Tokenise(nil, `if true then print else end`)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user