Skip to content

Commit

Permalink
Fix rouge-ruby#1022 by supporting diffs other than unified. (#36)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pyrmont committed May 12, 2019
1 parent 5f61574 commit e884b51
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/rouge/lexers/diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ def self.detect?(text)

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]*\n)/) do
groups Punctuation, Text
end
rule(/^\w.*$\n?/, Punctuation)
rule(/^=.*$\n?/, Generic::Heading)
rule(/.*$\n?/, Text)
rule(/\s.*$\n?/, Text)
end
end
end
Expand Down

0 comments on commit e884b51

Please sign in to comment.