From 02c4adc0664a104c4ea91c6c3a41a91b93bbd9ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sat, 14 Oct 2017 11:02:40 +0200 Subject: [PATCH] Add a chroma class wrapper when in "table mode" (#63) This commits adds a div wrapper when linenumbers are formatted in table, to get the correct CSS matchers. This commit also fixes some CSS table issues when tables are put into a larger context with other stylesheets: * No borders. * Overflow to fit in potentially narrower containers. Fixes #62 --- 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 3390feb2a..42636041f 100644 --- a/formatters/html/html.go +++ b/formatters/html/html.go @@ -155,6 +155,7 @@ func (f *Formatter) writeHTML(w io.Writer, style *chroma.Style, tokens []*chroma if wrapInTable { // List line numbers in its own + fmt.Fprintf(w, "\n", f.styleAttr(css, chroma.Background)) fmt.Fprintf(w, "", f.styleAttr(css, chroma.LineTable)) fmt.Fprintf(w, "\n", f.styleAttr(css, chroma.LineTableTD)) fmt.Fprintf(w, "", f.styleAttr(css, chroma.Background)) @@ -212,6 +213,7 @@ func (f *Formatter) writeHTML(w io.Writer, style *chroma.Style, tokens []*chroma if wrapInTable { fmt.Fprint(w, "\n") + fmt.Fprint(w, "\n") } if f.standalone { @@ -317,10 +319,10 @@ func (f *Formatter) styleToCSS(style *chroma.Style) map[chroma.TokenType]string classes[chroma.Background] += f.tabWidthStyle() lineNumbersStyle := "; margin-right: 0.4em; padding: 0 0.4em 0 0.4em;" classes[chroma.LineNumbers] += lineNumbersStyle - classes[chroma.LineNumbersTable] += lineNumbersStyle + "; display: block" + classes[chroma.LineNumbersTable] += lineNumbersStyle + " display: block;" classes[chroma.LineHighlight] += "; display: block; width: 100%" - classes[chroma.LineTable] += "; border-spacing: 0; padding: 0; margin: 0;" - classes[chroma.LineTableTD] += "; vertical-align: top; padding: 0; margin: 0;" + classes[chroma.LineTable] += "; border-spacing: 0; padding: 0; margin: 0; border: 0; width: 100%; overflow: auto; display: block;" + classes[chroma.LineTableTD] += "; vertical-align: top; padding: 0; margin: 0; border: 0;" return classes }