Commits

wvl committed b0d78fd

npm package suppport.

Following the recommendations for node[1],
I converted the requires to be relative, and added
a main module that wraps SyntaxHighlighter. I also
modified the exports so that the api is a little
simpler to use:

var sh = require('syntaxhighlighter');
var ruby = new sh.Ruby({toolbar: false});

I also added an index.js at the root of the package,
so the code can just be dropped onto the filesystem
and used the same way.

Finally, I added a package.json so that it can be
published to the npm package registry. Once that is
done, it will be installable with a simple:

npm install syntaxhighlighter

[1] - http://nodejs.org/docs/v0.4.4/api/modules.html

Comments (0)

Files changed (30)

+exports.syntaxhighlighter = require('./scripts/syntaxhighlighter');
+{ "name": "syntaxhighlighter"
+, "main": "./scripts/syntaxhighlighter.js"
+, "description": "SyntaxHighlighter is a fully functional self-contained code syntax highlighter developed in JavaScript."
+, "keyword": ["syntax","code","highlight","highlighter"]
+, "homepage": "http://alexgorbatchev.com/SyntaxHighlighter"
+, "author": {
+      "name": "Alex Gorbatchev"
+    , "email": "alex.gorbatchev@gmail.com"
+    , "url": "http://alexgorbatchev.com"
+   }
+, "directories": {"lib": "./scripts"}
+, "repository": {
+      "type": "hg"
+   ,  "url": "https://bitbucket.org/alexg/syntaxhighlighter"
+   }
+}

scripts/shBrushAS3.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushAppleScript.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushBash.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushCSharp.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushColdFusion.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushCpp.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushCss.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushDelphi.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushDiff.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushErlang.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushGroovy.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushJScript.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushJava.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushJavaFX.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushPerl.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushPhp.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushPlain.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushPowerShell.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushPython.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushRuby.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushSass.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushScala.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushSql.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushVb.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shBrushXml.js

 ;(function()
 {
 	// CommonJS
-	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('./shCore').SyntaxHighlighter : null;
 
 	function Brush()
 	{

scripts/shCore.js

 // CommonJS
 if (typeof(require) != 'undefined' && typeof(XRegExp) == 'undefined')
 {
-	XRegExp = require('XRegExp').XRegExp;
+	XRegExp = require('./XRegExp').XRegExp;
 }
 
 // Shortcut object which will be assigned to the SyntaxHighlighter variable.

scripts/syntaxhighlighter.js

+exports.SyntaxHighlighter = require('./shCore').SyntaxHighlighter;
+
+var brushes = [
+		'AS3',
+    'AppleScript',
+    'Bash',
+    'CSharp',
+    'ColdFusion',
+    'Cpp',
+    'Css',
+    'Delphi',
+    'Diff',
+    'Erlang',
+    'Groovy',
+    'JScript',
+    'Java',
+    'JavaFX',
+    'Perl',
+    'Php',
+    'Plain',
+    'PowerShell',
+    'Python',
+    'Ruby',
+    'Sass',
+    'Scala',
+    'Sql',
+    'Vb',
+    'Xml'
+  ];
+
+brushes.forEach(function(name) {
+  var file = './shBrush'+name;
+  exports[name] = function(params) {
+    var Brush = require(file).Brush;
+    var brush = new Brush();
+    if (params) {
+      brush.init(params)
+    }
+    return brush;
+  }
+});
+
+// Aliases
+exports.Javascript = exports.JScript;
+
+

tests/commonjs_tests.js

 /**
  * This is a CommonJS compatibility test. You can run this file with node.
  */
-require.paths.unshift(__dirname + '/../scripts');
 
 var sys = require('sys'),
-	shSyntaxHighlighter = require('shCore').SyntaxHighlighter,
+  sh = require('../scripts/syntaxhighlighter')
 	code = 'test',
 	brushes = [
 		'AS3',
 for (var i = 0; i < brushes.length; i++)
 {
 	var name = brushes[i],
-		brush = require('shBrush' + name).Brush
+		brush = sh[name]
 		;
 		
-	brush = new brush();
-	brush.init({ toolbar: false });
+	brush = new brush({ toolbar: false});
 	
 	var result = brush.getHtml(code);
-	
+
 	sys.puts(name + (result != null ? ': ok' : ': NOT OK'));
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.