thirdparty/jsdoctoolkit/app/plugins/publishSrcHilite.js
author Lennard de Rijk <ljvderijk@gmail.com>
Sun, 25 Oct 2009 18:45:58 -0700
changeset 3052 6907a33ca0a2
parent 3041 c8f47f0b6697
permissions -rw-r--r--
Removed now unused method from Role Logic.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3041
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
     1
JSDOC.PluginManager.registerPlugin(
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
     2
	"JSDOC.publishSrcHilite",
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
     3
	{
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
     4
		onPublishSrc: function(src) {
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
     5
			if (src.path in JsHilite.cache) {
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
     6
				return; // already generated src code
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
     7
			}
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
     8
			else JsHilite.cache[src.path] = true;
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
     9
		
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    10
			try {
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    11
				var sourceCode = IO.readFile(src.path);
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    12
			}
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    13
			catch(e) {
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    14
				print(e.message);
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    15
				quit();
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    16
			}
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    17
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    18
			var hiliter = new JsHilite(sourceCode, src.charset);
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    19
			src.hilited = hiliter.hilite();
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    20
		}
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    21
	}
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    22
);
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    23
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    24
function JsHilite(src, charset) {
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    25
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    26
	var tr = new JSDOC.TokenReader();
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    27
	
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    28
	tr.keepComments = true;
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    29
	tr.keepDocs = true;
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    30
	tr.keepWhite = true;
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    31
	
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    32
	this.tokens = tr.tokenize(new JSDOC.TextStream(src));
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    33
	
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    34
	// TODO is redefining toString() the best way?
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    35
	JSDOC.Token.prototype.toString = function() { 
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    36
		return "<span class=\""+this.type+"\">"+this.data.replace(/</g, "&lt;")+"</span>";
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    37
	}
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    38
	
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    39
	if (!charset) charset = "utf-8";
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    40
	
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    41
	this.header = '<html><head><meta http-equiv="content-type" content="text/html; charset='+charset+'"> '+
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    42
	"<style>\n\
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    43
	.KEYW {color: #933;}\n\
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    44
	.COMM {color: #bbb; font-style: italic;}\n\
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    45
	.NUMB {color: #393;}\n\
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    46
	.STRN {color: #393;}\n\
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    47
	.REGX {color: #339;}\n\
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    48
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}\n\
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    49
	</style></head><body><pre>";
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    50
	this.footer = "</pre></body></html>";
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    51
	this.showLinenumbers = true;
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    52
}
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    53
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    54
JsHilite.cache = {};
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    55
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    56
JsHilite.prototype.hilite = function() {
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    57
	var hilited = this.tokens.join("");
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    58
	var line = 1;
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    59
	if (this.showLinenumbers) hilited = hilited.replace(/(^|\n)/g, function(m){return m+"<span class='line'>"+((line<10)? " ":"")+((line<100)? " ":"")+(line++)+"</span> "});
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    60
	
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    61
	return this.header+hilited+this.footer;
c8f47f0b6697 JSDocToolkit 2.3.0 added to create documentation for JS files.
Mario Ferraro <fadinlight@gmail.com>
parents:
diff changeset
    62
}