Commit 1758634b82d8d1cb53e495a57a861feb483ac4db

Lea Verou 2014-04-21T06:29:13

Merge pull request #179 from geraintluff/gh-pages Add Node.js support

diff --git a/components/prism-core.js b/components/prism-core.js
index f545d4c..b7690aa 100644
--- a/components/prism-core.js
+++ b/components/prism-core.js
@@ -1,10 +1,12 @@
+var self = (typeof window !== 'undefined') ? window : {};
+
 /**
  * Prism: Lightweight, robust, elegant syntax highlighting
  * MIT license http://www.opensource.org/licenses/mit-license.php/
  * @author Lea Verou http://lea.verou.me
  */
 
-(function(){
+var Prism = (function(){
 
 // Private helper vars
 var lang = /\blang(?:uage)?-(?!\*)(\w+)\b/i;
@@ -323,7 +325,11 @@ Token.stringify = function(o, language, parent) {
 };
 
 if (!self.document) {
-	// In worker
+	if (!self.addEventListener) {
+		// in Node.js
+		return self.Prism;
+	}
+ 	// In worker
 	self.addEventListener('message', function(evt) {
 		var message = JSON.parse(evt.data),
 		    lang = message.language,
@@ -333,7 +339,7 @@ if (!self.document) {
 		self.close();
 	}, false);
 	
-	return;
+	return self.Prism;
 }
 
 // Get current script and highlight
@@ -349,4 +355,10 @@ if (script) {
 	}
 }
 
-})();
\ No newline at end of file
+return self.Prism;
+
+})();
+
+if (typeof module !== 'undefined' && module.exports) {
+	module.exports = Prism;
+}
\ No newline at end of file
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..ab44eac
--- /dev/null
+++ b/package.json
@@ -0,0 +1,20 @@
+{
+  "name": "prism",
+  "version": "0.0.0",
+  "description": "Lightweight, robust, elegant syntax highlighting. A spin-off project from Dabblet.",
+  "main": "prism.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/LeaVerou/prism.git"
+  },
+  "keywords": [
+    "prism",
+    "highlight"
+  ],
+  "author": "Lea Verou",
+  "license": "MIT",
+  "readmeFilename": "README.md"
+}
diff --git a/prism.js b/prism.js
index 19b7146..7a7b913 100644
--- a/prism.js
+++ b/prism.js
@@ -4,13 +4,15 @@
      Begin prism-core.js
 ********************************************** */
 
+var self = (typeof window !== 'undefined') ? window : {};
+
 /**
  * Prism: Lightweight, robust, elegant syntax highlighting
  * MIT license http://www.opensource.org/licenses/mit-license.php/
  * @author Lea Verou http://lea.verou.me
  */
 
-(function(){
+var Prism = (function(){
 
 // Private helper vars
 var lang = /\blang(?:uage)?-(?!\*)(\w+)\b/i;
@@ -329,7 +331,11 @@ Token.stringify = function(o, language, parent) {
 };
 
 if (!self.document) {
-	// In worker
+	if (!self.addEventListener) {
+		// in Node.js
+		return self.Prism;
+	}
+ 	// In worker
 	self.addEventListener('message', function(evt) {
 		var message = JSON.parse(evt.data),
 		    lang = message.language,
@@ -339,7 +345,7 @@ if (!self.document) {
 		self.close();
 	}, false);
 	
-	return;
+	return self.Prism;
 }
 
 // Get current script and highlight
@@ -355,8 +361,14 @@ if (script) {
 	}
 }
 
+return self.Prism;
+
 })();
 
+if (typeof module !== 'undefined' && module.exports) {
+	module.exports = Prism;
+}
+
 /* **********************************************
      Begin prism-markup.js
 ********************************************** */