Skip to content

Commit

Permalink
Git: Add support for unified diff. Fixes #769, fixes #357, closes #401
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Sep 14, 2015
1 parent 112e0e8 commit 3aadd5d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
14 changes: 7 additions & 7 deletions components/prism-git.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ Prism.languages.git = {
* # and have 1 and 2 different commits each, respectively.
* nothing to commit (working directory clean)
*/
'comment': /^#.*$/m,
'comment': /^#.*/m,

/*
* Regexp to match the changed lines in a git diff output. Check the example below.
*/
'deleted': /^[-–].*/m,
'inserted': /^\+.*/m,

/*
* a string (double and simple quote)
Expand Down Expand Up @@ -48,12 +54,6 @@ Prism.languages.git = {
*/
'coord': /^@@.*@@$/m,

/*
* Regexp to match the changed lines in a git diff output. Check the example above.
*/
'deleted': /^-(?!-).+$/m,
'inserted': /^\+(?!\+).+$/m,

/*
* Match a "commit [SHA1]" line in a git log output.
* For instance:
Expand Down
2 changes: 1 addition & 1 deletion components/prism-git.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion tests/languages/git/diff_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@
+Here's my text file
+And this is the second line

––– a/web/js/lazy.js
+++ b/web/js/lazy.js

- if (url !== null && url !== '' && typeof url !== 'undefined') {
+ if (url === null || url === '' || typeof url === 'undefined') {
+ return;
+ }
+

----------------------------------------------------

[
["deleted", "-Here's my tetx file"],
["inserted", "+Here's my text file"],
["inserted", "+And this is the second line"]
["inserted", "+And this is the second line"],
["deleted", "––– a/web/js/lazy.js"],
["inserted", "+++ b/web/js/lazy.js"],
["deleted", "- if (url !== null && url !== '' && typeof url !== 'undefined') {"],
["inserted", "+ if (url === null || url === '' || typeof url === 'undefined') {"],
["inserted", "+ return;"],
["inserted", "+ }"],
["inserted", "+"]
]

----------------------------------------------------
Expand Down

0 comments on commit 3aadd5d

Please sign in to comment.