diff --git a/formatters/html/html.go b/formatters/html/html.go index 74db7ff33..164c842d2 100644 --- a/formatters/html/html.go +++ b/formatters/html/html.go @@ -139,17 +139,17 @@ var ( defaultPreWrapper = preWrapper{ start: func(code bool, styleAttr string) string { if code { - return fmt.Sprintf(`
`, styleAttr)
+				return fmt.Sprintf(`
`, styleAttr)
 			}
 
-			return fmt.Sprintf(`
`, styleAttr) + return fmt.Sprintf(`
`, styleAttr)
 		},
 		end: func(code bool) string {
 			if code {
-				return `
` + return `
` } - return `` + return `
` }, } ) @@ -250,7 +250,7 @@ func (f *Formatter) writeHTML(w io.Writer, style *chroma.Style, tokens []chroma. } // Start of Line - fmt.Fprint(w, ``) // End of CodeLine - fmt.Fprint(w, ``) // End of Line + fmt.Fprint(w, ``) // End of Line } fmt.Fprintf(w, f.preWrapper.End(true)) @@ -454,8 +454,8 @@ func (f *Formatter) styleToCSS(style *chroma.Style) map[chroma.TokenType]string // All rules begin with default rules followed by user provided rules classes[chroma.Line] = `display: flex;` + classes[chroma.Line] classes[chroma.LineNumbers] = lineNumbersStyle + classes[chroma.LineNumbers] - classes[chroma.LineNumbersTable] = `font-family: monospace; font-size: inherit;` + lineNumbersStyle + classes[chroma.LineNumbersTable] - classes[chroma.LineTable] = "border-spacing: 0; padding: 0; margin: 0; border: 0; width: auto; overflow: auto; display: block;" + classes[chroma.LineTable] + classes[chroma.LineNumbersTable] = lineNumbersStyle + classes[chroma.LineNumbersTable] + classes[chroma.LineTable] = "border-spacing: 0; padding: 0; margin: 0; border: 0;" + classes[chroma.LineTable] classes[chroma.LineTableTD] = "vertical-align: top; padding: 0; margin: 0; border: 0;" + classes[chroma.LineTableTD] return classes } diff --git a/formatters/html/html_test.go b/formatters/html/html_test.go index 39575ba3b..346611f76 100644 --- a/formatters/html/html_test.go +++ b/formatters/html/html_test.go @@ -129,7 +129,7 @@ func TestHighlightLines(t *testing.T) { err = f.Format(&buf, styles.Fallback, it) assert.NoError(t, err) - assert.Contains(t, buf.String(), `
`) + assert.Contains(t, buf.String(), ``) } func TestLineNumbers(t *testing.T) { @@ -141,7 +141,7 @@ func TestLineNumbers(t *testing.T) { err = f.Format(&buf, styles.Fallback, it) assert.NoError(t, err) - assert.Contains(t, buf.String(), `
1echo FOO
`) + assert.Contains(t, buf.String(), `1echo FOO`) } func TestPreWrapper(t *testing.T) { @@ -153,7 +153,7 @@ func TestPreWrapper(t *testing.T) { err = f.Format(&buf, styles.Fallback, it) assert.NoError(t, err) - assert.Regexp(t, "\n
echo FOO
\n\n", buf.String()) + assert.Regexp(t, "\necho FOO\n\n", buf.String()) assert.Regexp(t, `\.bg { .+ }`, buf.String()) assert.Regexp(t, `\.chroma { .+ }`, buf.String()) } @@ -252,17 +252,17 @@ func TestWithPreWrapper(t *testing.T) { t.Run("Regular", func(t *testing.T) { s := format(New(WithClasses(true))) - assert.Equal(t, s, `
echo FOO
`) + assert.Equal(t, s, `
echo FOO
`) }) t.Run("PreventSurroundingPre", func(t *testing.T) { s := format(New(PreventSurroundingPre(true), WithClasses(true))) - assert.Equal(t, s, `
echo FOO
`) + assert.Equal(t, s, `echo FOO`) }) t.Run("Wrapper", func(t *testing.T) { s := format(New(WithPreWrapper(wrapper), WithClasses(true))) - assert.Equal(t, s, `
echo FOO
`) + assert.Equal(t, s, `echo FOO`) }) t.Run("Wrapper, LineNumbersInTable", func(t *testing.T) { @@ -273,7 +273,7 @@ func TestWithPreWrapper(t *testing.T) { 1 -
echo FOO
+echo FOO
`) }) @@ -296,7 +296,7 @@ func TestReconfigureOptions(t *testing.T) { err = f.Format(&buf, styles.Fallback, it) assert.NoError(t, err) - assert.Equal(t, `
echo FOO
`, buf.String()) + assert.Equal(t, `
echo FOO
`, buf.String()) } func TestWriteCssWithAllClasses(t *testing.T) {