Git: Add support for unified diff. Fixes #769, fixes #357, closes #401
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
diff --git a/components/prism-git.js b/components/prism-git.js
index 0d2ecb1..e5cc4ce 100644
--- a/components/prism-git.js
+++ b/components/prism-git.js
@@ -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)
@@ -49,12 +55,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:
* $ git log
diff --git a/components/prism-git.min.js b/components/prism-git.min.js
index 44468b9..e4b5da4 100644
--- a/components/prism-git.min.js
+++ b/components/prism-git.min.js
@@ -1 +1 @@
-Prism.languages.git={comment:/^#.*$/m,string:/("|')(\\?.)*?\1/m,command:{pattern:/^.*\$ git .*$/m,inside:{parameter:/\s(--|-)\w+/m}},coord:/^@@.*@@$/m,deleted:/^-(?!-).+$/m,inserted:/^\+(?!\+).+$/m,commit_sha1:/^commit \w{40}$/m};
\ No newline at end of file
+Prism.languages.git={comment:/^#.*/m,deleted:/^[-–].*/m,inserted:/^\+.*/m,string:/("|')(\\?.)*?\1/m,command:{pattern:/^.*\$ git .*$/m,inside:{parameter:/\s(--|-)\w+/m}},coord:/^@@.*@@$/m,commit_sha1:/^commit \w{40}$/m};
\ No newline at end of file
diff --git a/tests/languages/git/diff_feature.test b/tests/languages/git/diff_feature.test
index 3c75cca..b93fb18 100644
--- a/tests/languages/git/diff_feature.test
+++ b/tests/languages/git/diff_feature.test
@@ -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", "+"]
]
----------------------------------------------------