1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-07-01 00:35:06 +02:00

Add newlines in line number spans when wrapping in an HTML table.

Since these are wrapped in a `<pre>`, newlines hint the browser that the
line numbers should be on separate lines. This helps when rendering
content with broken CSS, or in a text-only browser.
This commit is contained in:
John Millikin
2018-02-24 17:34:34 -08:00
committed by Alec Thomas
parent 10c530a975
commit d7ee3c10b0
2 changed files with 21 additions and 2 deletions

View File

@ -92,3 +92,22 @@ func TestClassPrefix(t *testing.T) {
t.Error("Stylesheets should have a class prefix")
}
}
func TestTableLineNumberNewlines(t *testing.T) {
f := New(WithClasses(), WithLineNumbers(), LineNumbersInTable())
it, err := lexers.Get("go").Tokenise(nil, "package main\nfunc main()\n{\nprintln(`hello world`)\n}\n")
assert.NoError(t, err)
var buf bytes.Buffer
err = f.Format(&buf, styles.Fallback, it)
assert.NoError(t, err)
// Don't bother testing the whole output, just verify it's got line numbers
// in a <pre>-friendly format.
// Note: placing the newlines inside the <span> lets browser selections look
// better, instead of "skipping" over the span margin.
assert.Contains(t, buf.String(), `<span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span>`)
}