From e6a56651ad3281f491faa8f5595c070bb44743fc Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Sat, 20 Jul 2019 23:19:20 +1000 Subject: [PATCH] Add width:100% to content when inlining styles. Fixes #225. --- formatters/html/html.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/formatters/html/html.go b/formatters/html/html.go index 93b33b1..c1919a4 100644 --- a/formatters/html/html.go +++ b/formatters/html/html.go @@ -157,7 +157,7 @@ func (f *Formatter) writeHTML(w io.Writer, style *chroma.Style, tokens []chroma. fmt.Fprint(w, "") } fmt.Fprint(w, "\n") - fmt.Fprintf(w, "\n", f.styleAttr(css, chroma.LineTableTD)) + fmt.Fprintf(w, "\n", f.styleAttr(css, chroma.LineTableTD, "width:100%")) } if !f.preventSurroundingPre { @@ -240,7 +240,7 @@ func (f *Formatter) class(t chroma.TokenType) string { return "" } -func (f *Formatter) styleAttr(styles map[chroma.TokenType]string, tt chroma.TokenType) string { +func (f *Formatter) styleAttr(styles map[chroma.TokenType]string, tt chroma.TokenType, extraCSS ...string) string { if f.Classes { cls := f.class(tt) if cls == "" { @@ -257,7 +257,9 @@ func (f *Formatter) styleAttr(styles map[chroma.TokenType]string, tt chroma.Toke } } } - return fmt.Sprintf(` style="%s"`, styles[tt]) + css := []string{styles[tt]} + css = append(css, extraCSS...) + return fmt.Sprintf(` style="%s"`, strings.Join(css, ";")) } func (f *Formatter) tabWidthStyle() string {