Merge pull request #179 from geraintluff/gh-pages Add Node.js support
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
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
********************************************** */