id: 222f483f-c2d5-4e86-aaa0-e79afe87fe9d title: 'file pages: phantom final line for trailing newline / CRLF' state: closed labels:
- ui assignees: [] milestone: null created: 2026-10-27T17:24:52.473238063Z updated: 2026-10-27T17:45:41.740845856Z
What
render_text_pre (src/build.rs:1028) splits on \n without dropping the trailing terminator or \r.
- a 403-line file ending in
\nrenders 404 numbered lines (last one empty) while the toolbar says “403 lines” - CRLF files keep
\rin the output and also get the phantom line
Reproduced
wc -l src/highlight.rs # 403
grep -o 'id="L[0-9]*"' dist/files/src/highlight.rs.html | tail -1 # L404
Impact
Visible off-by-one gutter and anchor; copy-paste on CRLF files carries stray CR.
Fix
Normalize \r\n/\r to \n, strip one trailing \n, then split. Keep the empty-file special case. Test a trailing-newline file and a CRLF file for exact line count and no empty last line.