1 JSDOC
.PluginManager
.registerPlugin(
2 "JSDOC.publishSrcHilite",
4 onPublishSrc
: function(src
) {
5 if (src
.path
in JsHilite
.cache
) {
6 return; // already generated src code
8 else JsHilite
.cache
[src
.path
] = true;
11 var sourceCode
= IO
.readFile(src
.path
);
18 var hiliter
= new JsHilite(sourceCode
, src
.charset
);
19 src
.hilited
= hiliter
.hilite();
24 function JsHilite(src
, charset
) {
26 var tr
= new JSDOC
.TokenReader();
28 tr
.keepComments
= true;
32 this.tokens
= tr
.tokenize(new JSDOC
.TextStream(src
));
34 // TODO is redefining toString() the best way?
35 JSDOC
.Token
.prototype.toString
= function() {
36 return "<span class=\""+this.type
+"\">"+this.data
.replace(/</g, "<")+"</span>";
39 if (!charset
) charset
= "utf-8";
41 this.header
= '<html><head><meta http-equiv="content-type" content="text/html; charset='+charset
+'"> '+
43 .KEYW {color: #933;}\n\
44 .COMM {color: #bbb; font-style: italic;}\n\
45 .NUMB {color: #393;}\n\
46 .STRN {color: #393;}\n\
47 .REGX {color: #339;}\n\
48 .line {border-right: 1px dotted #666; color: #666; font-style: normal;}\n\
49 </style></head><body><pre>";
50 this.footer
= "</pre></body></html>";
51 this.showLinenumbers
= true;
56 JsHilite
.prototype.hilite
= function() {
57 var hilited
= this.tokens
.join("");
59 if (this.showLinenumbers
) hilited
= hilited
.replace(/(^|\n)/g, function(m
){return m
+"<span class='line'>"+((line
<10)? " ":"")+((line
<100)? " ":"")+(line
++)+"</span> "});
61 return this.header
+hilited
+this.footer
;