1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-01-12 01:22:30 +02:00

Don't output trailing \n for HTML-only fragment.

See #47.
This commit is contained in:
Alec Thomas 2017-09-30 14:45:13 +10:00
parent ce3d6bf527
commit 0e0960930d

View File

@ -174,9 +174,9 @@ func (f *Formatter) writeHTML(w io.Writer, style *chroma.Style, tokens []*chroma
}
}
fmt.Fprint(w, "</pre>\n")
fmt.Fprint(w, "</pre>")
if f.standalone {
fmt.Fprint(w, "</body>\n")
fmt.Fprint(w, "\n</body>\n")
fmt.Fprint(w, "</html>\n")
}
@ -196,7 +196,11 @@ func (f *Formatter) class(t chroma.TokenType) string {
func (f *Formatter) styleAttr(styles map[chroma.TokenType]string, tt chroma.TokenType) string {
if f.classes {
return string(fmt.Sprintf(` class="%s"`, f.class(tt)))
cls := f.class(tt)
if cls == "" {
return ""
}
return string(fmt.Sprintf(` class="%s"`, cls))
}
if _, ok := styles[tt]; !ok {
tt = tt.SubCategory()