mirror of
https://github.com/alecthomas/chroma.git
synced 2025-03-27 21:49:13 +02:00
Ensure that HTML code column expands to full width of container.
Fixes #114.
This commit is contained in:
parent
03fd03809c
commit
e4cd1649a3
@ -159,7 +159,7 @@ func (f *Formatter) writeHTML(w io.Writer, style *chroma.Style, tokens []*chroma
|
|||||||
fmt.Fprintf(w, "<table%s><tr>", f.styleAttr(css, chroma.LineTable))
|
fmt.Fprintf(w, "<table%s><tr>", f.styleAttr(css, chroma.LineTable))
|
||||||
fmt.Fprintf(w, "<td%s>\n", f.styleAttr(css, chroma.LineTableTD))
|
fmt.Fprintf(w, "<td%s>\n", f.styleAttr(css, chroma.LineTableTD))
|
||||||
fmt.Fprintf(w, "<pre%s>", f.styleAttr(css, chroma.Background))
|
fmt.Fprintf(w, "<pre%s>", f.styleAttr(css, chroma.Background))
|
||||||
for index, _ := range lines {
|
for index := range lines {
|
||||||
line := f.baseLineNumber + index
|
line := f.baseLineNumber + index
|
||||||
highlight, next := f.shouldHighlight(highlightIndex, line)
|
highlight, next := f.shouldHighlight(highlightIndex, line)
|
||||||
if next {
|
if next {
|
||||||
@ -267,7 +267,7 @@ func (f *Formatter) styleAttr(styles map[chroma.TokenType]string, tt chroma.Toke
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return string(fmt.Sprintf(` style="%s"`, styles[tt]))
|
return fmt.Sprintf(` style="%s"`, styles[tt])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Formatter) tabWidthStyle() string {
|
func (f *Formatter) tabWidthStyle() string {
|
||||||
@ -284,6 +284,13 @@ func (f *Formatter) WriteCSS(w io.Writer, style *chroma.Style) error {
|
|||||||
if _, err := fmt.Fprintf(w, "/* %s */ .chroma { %s }\n", chroma.Background, css[chroma.Background]); err != nil {
|
if _, err := fmt.Fprintf(w, "/* %s */ .chroma { %s }\n", chroma.Background, css[chroma.Background]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// Special-case code column of table to expand width.
|
||||||
|
if f.lineNumbers && f.lineNumbersInTable {
|
||||||
|
if _, err := fmt.Fprintf(w, "/* %s */ .chroma .%s:last-child { width: 100%%; }",
|
||||||
|
chroma.LineTableTD, f.class(chroma.LineTableTD)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
tts := []int{}
|
tts := []int{}
|
||||||
for tt := range css {
|
for tt := range css {
|
||||||
tts = append(tts, int(tt))
|
tts = append(tts, int(tt))
|
||||||
@ -318,13 +325,12 @@ func (f *Formatter) styleToCSS(style *chroma.Style) map[chroma.TokenType]string
|
|||||||
}
|
}
|
||||||
classes[chroma.Background] += f.tabWidthStyle()
|
classes[chroma.Background] += f.tabWidthStyle()
|
||||||
lineNumbersStyle := "margin-right: 0.4em; padding: 0 0.4em 0 0.4em;"
|
lineNumbersStyle := "margin-right: 0.4em; padding: 0 0.4em 0 0.4em;"
|
||||||
// all rules begin with default rules followed by user provided rules
|
// All rules begin with default rules followed by user provided rules
|
||||||
classes[chroma.LineNumbers] = lineNumbersStyle + classes[chroma.LineNumbers]
|
classes[chroma.LineNumbers] = lineNumbersStyle + classes[chroma.LineNumbers]
|
||||||
classes[chroma.LineNumbersTable] = lineNumbersStyle + " display: block;" + classes[chroma.LineNumbersTable]
|
classes[chroma.LineNumbersTable] = lineNumbersStyle + " display: block;" + classes[chroma.LineNumbersTable]
|
||||||
classes[chroma.LineHighlight] = "display: block; width: 100%;" + classes[chroma.LineHighlight]
|
classes[chroma.LineHighlight] = "display: block; width: 100%;" + classes[chroma.LineHighlight]
|
||||||
classes[chroma.LineTable] = "border-spacing: 0; padding: 0; margin: 0; border: 0; width: 100%; overflow: auto; display: block;" + classes[chroma.LineTable]
|
classes[chroma.LineTable] = "border-spacing: 0; padding: 0; margin: 0; border: 0; width: auto; overflow: auto; display: block;" + classes[chroma.LineTable]
|
||||||
classes[chroma.LineTableTD] = "vertical-align: top; padding: 0; margin: 0; border: 0;" + classes[chroma.LineTableTD]
|
classes[chroma.LineTableTD] = "vertical-align: top; padding: 0; margin: 0; border: 0;" + classes[chroma.LineTableTD]
|
||||||
|
|
||||||
return classes
|
return classes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user