1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-03-17 20:58:08 +02:00

Ensure class names from default set exist.

This commit is contained in:
Alec Thomas 2017-09-27 22:01:03 +10:00
parent 2ca426a8d1
commit 80d3b96869
2 changed files with 6 additions and 3 deletions

View File

@ -246,11 +246,14 @@ func (f *Formatter) styleToCSS(style *chroma.Style) map[chroma.TokenType]string
classes := map[chroma.TokenType]string{}
bg := style.Get(chroma.Background)
// Convert the style.
for _, t := range style.Types() {
for t := range chroma.StandardTypes {
entry := style.Get(t)
if t != chroma.Background {
entry = entry.Sub(bg)
}
if entry.IsZero() {
continue
}
classes[t] = StyleEntryToCSS(entry)
}
classes[chroma.Background] += f.tabWidthStyle()

View File

@ -13,8 +13,8 @@ func TestRemappingLexer(t *testing.T) {
{`\w+`, Name, nil},
},
})
lexer = TypeRemappingLexer(lexer, TypeRemappingMap{
{Name, Keyword}: {"if", "else"},
lexer = TypeRemappingLexer(lexer, TypeMapping{
{Name, Keyword, []string{"if", "else"}},
})
it, err := lexer.Tokenise(nil, `if true then print else end`)