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:
committed by
Alec Thomas
parent
10c530a975
commit
d7ee3c10b0
@ -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>`)
|
||||
}
|
||||
|
Reference in New Issue
Block a user