Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diff requires two newlines between diff-blocks to highlight properly #1676

Closed
johannesstricker opened this issue Feb 10, 2021 · 4 comments
Closed
Labels
bugfix-request A request for a bugfix to be developed. stale-issue There has been no activity for a year.

Comments

@johannesstricker
Copy link

Name of the lexer
diff

Code sample

// path/to/file.js

+ this is inserted
+ over multiple lines

- this is removed
- over multiple lines

This is how the output looks:
image
As you can see, it doesn't highlight the first line of a new diff block. It only works when I add an additional newline in between.
Also, why is the // at the beginning of the file wrapped in a <span class="err"> 🤔

@johannesstricker johannesstricker added the bugfix-request A request for a bugfix to be developed. label Feb 10, 2021
@connection-reset
Copy link

I have the same issue and did some investigation. The diff lexer is correct, if strict.
In the unified diff format, there is always at least the prefix character + (plus), - (minus), or ␣ (space).
So apparently empty lines in a diff are not empty, they contain ␣\n (space)(newline).

The diff lexer does not understand empty lines, i.e. lines that only contain \n (newline). It prepends them to the next line and yields that as a text token, i.e. \n+some insert\n.

I am using AsciiDoctor to render AsciiDoc with embedded diffs to HTML.
AsciiDoctor strips whitespace of the whole document before passing code blocks to Rouge, resulting in this issue.
I believe this is a bug in AsciiDoctor.

colinodell added a commit to thephpleague/commonmark that referenced this issue May 26, 2021
@colinodell
Copy link

I encountered this exact same issue using Rouge within Jekyll. It turns out my IDE was stripping trailing whitespace which caused the single space on those "empty" lines to be removed, thus triggering this issue.

@stale
Copy link

stale bot commented Jun 12, 2022

This issue has been automatically marked as stale because it has not had any activity for more than a year. It will be closed if no additional activity occurs within the next 14 days.
If you would like this issue to remain open, please reply and let us know if the issue is still reproducible.

@stale stale bot added the stale-issue There has been no activity for a year. label Jun 12, 2022
@stale stale bot closed this as completed Aug 13, 2022
@tancnle
Copy link
Collaborator

tancnle commented Aug 15, 2022

@johannesstricker As part of #1854, the rule around empty lines has been relaxed, it no longer requires spaces. This issue can be marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix-request A request for a bugfix to be developed. stale-issue There has been no activity for a year.
Projects
None yet
Development

No branches or pull requests

4 participants