Sha256: 309a1068ee9ec59d666264830e2ad6fc260168ea057dce945f8bfccaffc57110

Contents?: true

Size: 1.33 KB

Versions: 43

Compression:

Stored size: 1.33 KB

Contents

JSDOC.PluginManager.registerPlugin(
	"JSDOC.publishSrcHilite",
	{
		onPublishSrc: function(src) {
			if (src.path in JsHilite.cache) {
				return; // already generated src code
			}
			else JsHilite.cache[src.path] = true;
		
			try {
				var sourceCode = IO.readFile(src.path);
			}
			catch(e) {
				print(e.message);
				quit();
			}

			var hiliter = new JsHilite(sourceCode, src.charset);
			src.hilited = hiliter.hilite();
		}
	}
);

function JsHilite(src, charset) {

	var tr = new JSDOC.TokenReader();
	
	tr.keepComments = true;
	tr.keepDocs = true;
	tr.keepWhite = true;
	
	this.tokens = tr.tokenize(new JSDOC.TextStream(src));
	
	// TODO is redefining toString() the best way?
	JSDOC.Token.prototype.toString = function() { 
		return "<span class=\""+this.type+"\">"+this.data.replace(/</g, "&lt;")+"</span>";
	}
	
	if (!charset) charset = "utf-8";
	
	this.header= IO.readFile(JSDOC.opt.t + "static/code-header.html");
	this.footer= IO.readFile(JSDOC.opt.t + "static/code-footer.html");
	this.showLinenumbers = true;
}

JsHilite.cache = {};

JsHilite.prototype.hilite = function() {
	var hilited = this.tokens.join("");
	var line = 1;
	if (this.showLinenumbers) hilited = hilited.replace(/(^|\n)/g, function(m){return m+"<span class='line'>"+((line<10)? " ":"")+((line<100)? " ":"")+(line++)+"</span> "});
	
	return this.header+hilited+this.footer;
}

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
distil-0.14.5.a vendor/jsdoc-toolkit/app/plugins/publishSrcHilite.js
distil-0.14.4 vendor/jsdoc-toolkit/app/plugins/publishSrcHilite.js
distil-0.14.3 vendor/jsdoc-toolkit/app/plugins/publishSrcHilite.js
distil-0.14.2 vendor/jsdoc-toolkit/app/plugins/publishSrcHilite.js
distil-0.14.2.a vendor/jsdoc-toolkit/app/plugins/publishSrcHilite.js
distil-0.14.1 vendor/jsdoc-toolkit/app/plugins/publishSrcHilite.js
distil-0.14.1.a vendor/jsdoc-toolkit/app/plugins/publishSrcHilite.js
distil-0.14.0 vendor/jsdoc-toolkit/app/plugins/publishSrcHilite.js
distil-0.14.0.i vendor/jsdoc-toolkit/app/plugins/publishSrcHilite.js
distil-0.14.0.h vendor/jsdoc-toolkit/app/plugins/publishSrcHilite.js
distil-0.14.0.g vendor/jsdoc-toolkit/app/plugins/publishSrcHilite.js
distil-0.14.0.d vendor/jsdoc-toolkit/app/plugins/publishSrcHilite.js
distil-0.14.0.c vendor/jsdoc-toolkit/app/plugins/publishSrcHilite.js
distil-0.14.0.b vendor/jsdoc-toolkit/app/plugins/publishSrcHilite.js
distil-0.13.6 vendor/jsdoc-toolkit/app/plugins/publishSrcHilite.js
distil-0.13.5 vendor/jsdoc-toolkit/app/plugins/publishSrcHilite.js
distil-0.13.4 vendor/jsdoc-toolkit/app/plugins/publishSrcHilite.js
distil-0.13.3 vendor/jsdoc-toolkit/app/plugins/publishSrcHilite.js
distil-0.13.2 vendor/jsdoc-toolkit/app/plugins/publishSrcHilite.js
distil-0.13.1 vendor/jsdoc-toolkit/app/plugins/publishSrcHilite.js