Skip to content

html linewise formatter inside html table formatter handles missing trailing newline#2274

Open
UlyssesZh wants to merge 1 commit intorouge-ruby:mainfrom
UlyssesZh:linewise-table-trailing
Open

html linewise formatter inside html table formatter handles missing trailing newline#2274
UlyssesZh wants to merge 1 commit intorouge-ruby:mainfrom
UlyssesZh:linewise-table-trailing

Conversation

@UlyssesZh
Copy link
Copy Markdown
Contributor

No description provided.

@jneen
Copy link
Copy Markdown
Member

jneen commented Apr 17, 2026

Is this necessary? The <div> should already break lines. (well, really the <tr>)

@UlyssesZh
Copy link
Copy Markdown
Contributor Author

This is absolutely necessary because otherwise the lines count would be wrong. Suppose that the tokens are foo\nbar and that they become <div>foo\n</div><div>bar\n</div>. Because there are two \ns, the line numbers in the gutter would be 1\n2\n. However, because it does not end with \n, a new \n is appended to make it <div>foo\n</div><div>bar\n</div>\n, which is three lines. What I did is to prevent this excessive \n in the end.

@jneen
Copy link
Copy Markdown
Member

jneen commented Apr 17, 2026

Would it be possible just to count the newlines better rather than munge the string? Newline handling is complicated and probably requires a test on Edge with a file that has windows-style line endings.

@jneen
Copy link
Copy Markdown
Member

jneen commented Apr 17, 2026

Also, could you provide a screenshot here of the before/after?

@UlyssesZh
Copy link
Copy Markdown
Contributor Author

Would it be possible just to count the newlines better rather than munge the string?

The lines count is 2 for foo\nbar, which is correct. It cannot be better. Counting it to 3 is wrong.

Newline handling is complicated and probably requires a test on Edge with a file that has windows-style line endings.

I guess that cannot be helped. We just have to include more tests. However I don't think CRLF line endings will break this case because CRLF still ends with \n.

Also, could you provide a screenshot here of the before/after?

image
.lineno {
	background-color: orange;
}
.rouge-code pre {
	background-color: pink;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants