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 syntax highlight doesn't handle all cases #1022
Comments
Thanks. In fact the current rouge diff lexer only handles unified diffs (-u flag). This is the default with git as well, which I presume is why it's not been fixed. This will fix it; I'll prepare a pull-request as well: diff --git adiff --git a/lib/rouge/lexers/diff.rb b/lib/rouge/lexers/diff.rb
index 0f44832..28d2ded 100644
--- a/lib/rouge/lexers/diff.rb
+++ b/lib/rouge/lexers/diff.rb
@@ -19,14 +19,18 @@ module Rouge
state :root do
rule(/^ .*$\n?/, Text)
- rule(/^---$\n?/, Text)
+ rule(/^---$\n?/, Punctuation)
+ rule(/^[+>]+.*$\n?/, Generic::Inserted)
rule(/^\+.*$\n?/, Generic::Inserted)
- rule(/^-+.*$\n?/, Generic::Deleted)
+ rule(/^[-<]+.*$\n?/, Generic::Deleted)
rule(/^!.*$\n?/, Generic::Strong)
- rule(/^@.*$\n?/, Generic::Subheading)
rule(/^([Ii]ndex|diff).*$\n?/, Generic::Heading)
+ rule(/^(@@[^@]*@@)(.*)$\n?/) do
+ groups Punctuation, Text
+ end
+ rule(/^\w.*$\n?/, Punctuation)
rule(/^=.*$\n?/, Generic::Heading)
- rule(/.*$\n?/, Text)
+ rule(/\s.*$\n?/, Text)
end
end
end |
vidarh
added a commit
to vidarh/rouge
that referenced
this issue
Jan 18, 2019
Close rouge-ruby#846 as it conflicts and this commit differentiates further.
pyrmont
added a commit
to pyrmont/rouge
that referenced
this issue
May 12, 2019
In addition to handling diffs done without the `-u` flag, this also more closely matches `git diff` output for unified diffs by treating `@@ [reference ] @@` as punctuation and the rest of the line as text, making `---` punctuation, and making the diff/index lines at the top headings.
pyrmont
pushed a commit
to pyrmont/rouge
that referenced
this issue
May 17, 2019
This fixes rouge-ruby#1022. It also close rouge-ruby#846 as that PR is incompatible with this one.
pyrmont
pushed a commit
that referenced
this issue
May 28, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For example this diff is not syntax highlighted (but GitHub handles it just fine):
The text was updated successfully, but these errors were encountered: