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 ""+this.data.replace(/"; } 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+""+((line<10)? " ":"")+((line<100)? " ":"")+(line++)+" "}); return this.header+hilited+this.footer; }