Skip to content

Commit

Permalink
Add width:100% to content <td> when inlining styles.
Browse files Browse the repository at this point in the history
Fixes #225.
  • Loading branch information
alecthomas committed Jul 20, 2019
1 parent be3313d commit e6a5665
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions formatters/html/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (f *Formatter) writeHTML(w io.Writer, style *chroma.Style, tokens []chroma.
fmt.Fprint(w, "</pre>")
}
fmt.Fprint(w, "</td>\n")
fmt.Fprintf(w, "<td%s>\n", f.styleAttr(css, chroma.LineTableTD))
fmt.Fprintf(w, "<td%s>\n", f.styleAttr(css, chroma.LineTableTD, "width:100%"))
}

if !f.preventSurroundingPre {
Expand Down Expand Up @@ -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 == "" {
Expand All @@ -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 {
Expand Down

0 comments on commit e6a5665

Please sign in to comment.