1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-07-05 00:38:52 +02:00

Highlight the line number targeted by the URL anchor

This currently works only when `html.WithClasses(true)` is used.
The same colors as for the pre-highlighted lines are used.
Only the line number is highlighted, so difficult to notice, but
better than nothing.
This commit is contained in:
Alexandru Băluț
2019-12-18 16:57:09 +01:00
committed by Alec Thomas
parent 110f671e7c
commit 19d5ee688c

View File

@ -345,6 +345,13 @@ func (f *Formatter) WriteCSS(w io.Writer, style *chroma.Style) error {
return err return err
} }
} }
// Special-case line number highlighting when targeted.
if f.lineNumbers || f.lineNumbersInTable {
targetedLineCSS := StyleEntryToCSS(style.Get(chroma.LineHighlight))
for _, tt := range []chroma.TokenType{chroma.LineNumbers, chroma.LineNumbersTable} {
fmt.Fprintf(w, "/* %s targeted by URL anchor */ .%schroma .%s:target { %s }\n", tt, f.prefix, f.class(tt), targetedLineCSS)
}
}
tts := []int{} tts := []int{}
for tt := range css { for tt := range css {
tts = append(tts, int(tt)) tts = append(tts, int(tt))