Commit e642a222be9111e9c046fd769270314208edea21

Tzu-ping Chung 2015-09-15T13:32:16

Add diff syntax definition

diff --git a/components.js b/components.js
index 46c2fae..5703718 100644
--- a/components.js
+++ b/components.js
@@ -136,6 +136,10 @@ var components = {
 			"require": "clike",
 			"owner": "Golmote"
 		},
+		"diff": {
+			"title": "Diff",
+			"owner": "uranusjr"
+		},
 		"docker": {
 			"title": "Docker",
 			"owner": "JustinBeckwith"
diff --git a/components/prism-diff.js b/components/prism-diff.js
new file mode 100644
index 0000000..f01858d
--- /dev/null
+++ b/components/prism-diff.js
@@ -0,0 +1,20 @@
+Prism.languages.diff = {
+	'coord': [
+		// Match all kinds of coord lines (prefixed by "+++", "---" or "***").
+		/^(\*{3}|-{3}|\+{3}).*$/m,
+		// Match "@@ ... @@" coord lines in unified diff.
+		/^@@.*@@$/m,
+		// Match coord lines in normal diff (starts with a number).
+		/^\d+.*$/m,
+	],
+
+	// Match inserted and deleted lines. Support both +/- and >/< styles.
+	'deleted': /^[-<].+$/m,
+	'inserted': /^[+>].+$/m,
+
+	// Match "different" lines (prefixed with "!") in context diff.
+	'diff': {
+		'pattern': /^\!(?!\!).+$/m,
+		'alias': 'important'
+	}
+}
diff --git a/components/prism-diff.min.js b/components/prism-diff.min.js
new file mode 100644
index 0000000..57cc657
--- /dev/null
+++ b/components/prism-diff.min.js
@@ -0,0 +1 @@
+Prism.languages.diff={coord:[/^(\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d+.*$/m],deleted:/^[-<].+$/m,inserted:/^[+>].+$/m,diff:{pattern:/^\!(?!\!).+$/m,alias:"important"}};
\ No newline at end of file
diff --git a/examples/prism-diff.html b/examples/prism-diff.html
new file mode 100644
index 0000000..0bc7723
--- /dev/null
+++ b/examples/prism-diff.html
@@ -0,0 +1,36 @@
+<h1>Diff</h1>
+<p>To use this language, use the class "language-diff".</p>
+
+<h2>Normal Diff</h2>
+<pre><code>7c7
+&lt; qt: core
+---
+&gt; qt: core quick</code></pre>
+
+<h2>Context Diff</h2>
+<pre><code>*** qcli.yml	2014-12-16 11:43:41.000000000 +0800
+--- /Users/uranusjr/Desktop/qcli.yml	2014-12-31 11:28:08.000000000 +0800
+***************
+*** 4,8 ****
+  project:
+      sources: "src/*.cpp"
+      headers: "src/*.h"
+!     qt: core
+  public_headers: "src/*.h"
+--- 4,8 ----
+  project:
+      sources: "src/*.cpp"
+      headers: "src/*.h"
+!     qt: core gui
+  public_headers: "src/*.h"</code></pre>
+
+<h2>Unified Diff</h2>
+<pre><code>--- qcli.yml	2014-12-16 11:43:41.000000000 +0800
++++ /Users/uranusjr/Desktop/qcli.yml	2014-12-31 11:28:08.000000000 +0800
+@@ -4,5 +4,5 @@
+ project:
+     sources: "src/*.cpp"
+     headers: "src/*.h"
+-    qt: core
++    qt: core gui
+ public_headers: "src/*.h"</code></pre>
\ No newline at end of file