Sha256: 949fbff78c632f5421810fe21490b3995823bf9f748734c47fdee909e025dd46

Contents?: true

Size: 1.68 KB

Versions: 10

Compression:

Stored size: 1.68 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 = '<html><head><meta http-equiv="content-type" content="text/html; charset='+charset+'"> '+
  "<style>\n\
  .KEYW {color: #933;}\n\
  .COMM {color: #bbb; font-style: italic;}\n\
  .NUMB {color: #393;}\n\
  .STRN {color: #393;}\n\
  .REGX {color: #339;}\n\
  .line {border-right: 1px dotted #666; color: #666; font-style: normal;}\n\
  </style></head><body><pre>";
  this.footer = "</pre></body></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

10 entries across 10 versions & 1 rubygems

Version Path
sproutcore-0.9.15 jsdoc/app/plugins/publishSrcHilite.js
sproutcore-0.9.14 jsdoc/app/plugins/publishSrcHilite.js
sproutcore-0.9.19 jsdoc/app/plugins/publishSrcHilite.js
sproutcore-0.9.17 jsdoc/app/plugins/publishSrcHilite.js
sproutcore-0.9.16 jsdoc/app/plugins/publishSrcHilite.js
sproutcore-0.9.18 jsdoc/app/plugins/publishSrcHilite.js
sproutcore-0.9.23 jsdoc/app/plugins/publishSrcHilite.js
sproutcore-0.9.21 jsdoc/app/plugins/publishSrcHilite.js
sproutcore-0.9.22 jsdoc/app/plugins/publishSrcHilite.js
sproutcore-0.9.20 jsdoc/app/plugins/publishSrcHilite.js