mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-03-25 09:05:47 +00:00
tabs -> spaces and remove trailing whitespace
This commit is contained in:
parent
beb7c0fa71
commit
72cb12cf75
6 changed files with 433 additions and 433 deletions
|
|
@ -2,67 +2,67 @@
|
|||
// ;"ALEXLE";
|
||||
window.F = Class.create({
|
||||
initialize: function(options){
|
||||
options = Object.extend( {
|
||||
options = Object.extend( {
|
||||
user_id: 'samsonjs'
|
||||
,repository: SJS.projName
|
||||
,branch: 'master'
|
||||
}, options || {} );
|
||||
|
||||
|
||||
this.ps = [];
|
||||
this.shas = {};
|
||||
|
||||
|
||||
this.u = options.user_id;
|
||||
this.r = options.repository;
|
||||
this.b = options.branch;
|
||||
this.id = options.id;
|
||||
|
||||
this.render(this.id);
|
||||
|
||||
|
||||
this.repo = null;
|
||||
|
||||
/* Prototype RC2 */
|
||||
// document.on('click','a[data-sha]', function( event, element ){
|
||||
// document.on('click','a[data-sha]', function( event, element ){
|
||||
// this.click( element.readAttribute('data-sha'), element );
|
||||
// element.blur();
|
||||
// }.bind(this) );
|
||||
|
||||
document.observe('click', function(e) {
|
||||
|
||||
document.observe('click', function(e) {
|
||||
e = e.findElement();
|
||||
if( !e.readAttribute('data-sha') ) return;
|
||||
this.click( e.readAttribute('data-sha'), e );
|
||||
e.blur();
|
||||
}.bind(this));
|
||||
|
||||
|
||||
var idc = $('in'),
|
||||
s = function() { idc.className = 'on' },
|
||||
h = function() { if( Ajax.activeRequestCount == 0 ) idc.className = 'off' };
|
||||
Ajax.Responders.register( {
|
||||
Ajax.Responders.register( {
|
||||
onException: function(r,x) { console.log(x);h() }
|
||||
,onComplete: h
|
||||
,onCreate: s
|
||||
});
|
||||
|
||||
|
||||
/* init plugins */
|
||||
if( FP )
|
||||
for( var i = 0; i < FP.length; i++ )
|
||||
new FP[i](this);
|
||||
|
||||
|
||||
/* extractURL: if user assigns user_id, repo, branch */
|
||||
this.xU();
|
||||
this.oR(); // open repo
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
,xU: function() {
|
||||
|
||||
}
|
||||
|
||||
,render: function(selector) {
|
||||
|
||||
,render: function(selector) {
|
||||
$(selector || document.body).insert(this.h());
|
||||
this.psW = $('ps_w');
|
||||
this.bW = $('b_w');
|
||||
}
|
||||
|
||||
|
||||
,h: function() {
|
||||
return [
|
||||
'<div id=content>',
|
||||
|
|
@ -79,31 +79,31 @@ window.F = Class.create({
|
|||
'</table>',
|
||||
'</div>', // .p
|
||||
'</div>', // #r_w
|
||||
|
||||
'<div id=b_w>', // browser wrapper
|
||||
|
||||
'<div id=b_w>', // browser wrapper
|
||||
'<div id=ps_w style="width:200px"></div>',
|
||||
'</div>',
|
||||
|
||||
// '<div class=clear></div>',
|
||||
'</div>', // #finder
|
||||
'</div>', // #finder
|
||||
|
||||
'<div id=f_c_w style="display:none">', // file content wrapper
|
||||
'<div class=p>',
|
||||
'<div id=f_h class=big></div>',
|
||||
'</div>',
|
||||
|
||||
|
||||
'<div id=f_c>', // file content
|
||||
'<div class=p>', // padding
|
||||
'<div id=f_w>', // file wrapper
|
||||
'<div id=f></div>', // file
|
||||
'<div id=f></div>', // file
|
||||
'</div>',
|
||||
'<div id=diffoutput></div>',
|
||||
'</div>', // padding
|
||||
'</div>',
|
||||
|
||||
|
||||
'<div class=clear></div>',
|
||||
'</div>', // #f_c_w
|
||||
|
||||
|
||||
'<div id=footer><b><a href=http://github.com/sr3d/GithubFinder>GithubFinder</a></b></div>',
|
||||
'</div>' // # content
|
||||
].join(' ');
|
||||
|
|
@ -112,7 +112,7 @@ window.F = Class.create({
|
|||
/* openRepo */
|
||||
,oR: function(repo) {
|
||||
this.reset()
|
||||
|
||||
|
||||
var u,r,b;
|
||||
if( !repo ) {
|
||||
/* check URL params */
|
||||
|
|
@ -126,7 +126,7 @@ window.F = Class.create({
|
|||
/* if user just come from a github repo ... */
|
||||
var m = (new RegExp("^http://github.com/(.+)","i")).exec(document.referrer),
|
||||
path = m ? m[1].split('/') : [];
|
||||
|
||||
|
||||
if( path[0] && path[1] ) {
|
||||
u = this.u = path[0];
|
||||
r = this.r = path[1];
|
||||
|
|
@ -141,53 +141,53 @@ window.F = Class.create({
|
|||
/* User hits the "Go" button: grabbing the user/repo */
|
||||
repo = repo.split('/');
|
||||
if( repo.length < 2 ) { alert('invalid repository!'); return; }
|
||||
|
||||
|
||||
u = this.u = repo[0];
|
||||
r = this.r = repo[1];
|
||||
b = this.b = ($('brs') ? $F('brs') : b) || 'master';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$('r').innerHTML = u + '/' + r;
|
||||
|
||||
|
||||
/* Load the master branch */
|
||||
GH.Commits.listBranch( u, r, b, {
|
||||
GH.Commits.listBranch( u, r, b, {
|
||||
onData: function(cs) {
|
||||
// if(!cs.commits) { alert('repo not found'); return; }
|
||||
var tree_sha = cs.commits[0].tree;
|
||||
this.renderPanel(tree_sha);
|
||||
}.bind(this)
|
||||
});
|
||||
|
||||
|
||||
/* Show branches info */
|
||||
GH.Repo.listBranches( u, r, {
|
||||
GH.Repo.listBranches( u, r, {
|
||||
onData: function(bes) {
|
||||
this.bes = $H(bes);
|
||||
this.rBs();
|
||||
}.bind(this)
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
,reset: function() {
|
||||
$('f_c_w').hide();
|
||||
this.cI = -1;
|
||||
this.pI = 0;
|
||||
|
||||
|
||||
while(this.ps.length > 0)
|
||||
(this.ps.pop()).dispose();
|
||||
}
|
||||
|
||||
|
||||
,browse: function() {
|
||||
this.oR( $('r').innerHTML );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/* render branches */
|
||||
,rBs: function() {
|
||||
var h = '<select id=brs>';
|
||||
this.bes.each(function(b) {
|
||||
h +=
|
||||
this.bes.each(function(b) {
|
||||
h +=
|
||||
'<option ' + (this.b == b.key ? ' selected=""' : ' ' ) + '>' +
|
||||
b.key +
|
||||
'</option>';
|
||||
|
|
@ -199,7 +199,7 @@ window.F = Class.create({
|
|||
}.bind(this))
|
||||
}
|
||||
|
||||
,renderPanel: function( sh, ix, it ) {
|
||||
,renderPanel: function( sh, ix, it ) {
|
||||
ix = ix || 0;
|
||||
/* clear previously opened panels */
|
||||
for( var i = this.ps.length - 1; i > ix; i-- ) {
|
||||
|
|
@ -207,19 +207,19 @@ window.F = Class.create({
|
|||
}
|
||||
this.open( sh, it );
|
||||
}
|
||||
|
||||
|
||||
,_resizePanelsWrapper: function() {
|
||||
var w = (this.ps.length * 201);
|
||||
this.psW.style.width = w + 'px';
|
||||
|
||||
/* scroll to the last panel */
|
||||
|
||||
/* scroll to the last panel */
|
||||
this.bW.scrollLeft = w;
|
||||
}
|
||||
|
||||
/* request the content of the tree and render the panel */
|
||||
,open: function( tree_sha, item ) {
|
||||
GH.Tree.show( this.u, this.r, this.b, tree_sha, {
|
||||
onData: function(tree) { // tree is already sorted
|
||||
onData: function(tree) { // tree is already sorted
|
||||
/* add all items to cache */
|
||||
for( var i = 0, len = tree.length; i < len; i++ )
|
||||
this.shas[ tree[i].sha ] = tree[i];
|
||||
|
|
@ -228,13 +228,13 @@ window.F = Class.create({
|
|||
// debugger
|
||||
var p = new P( this, { tree: tree, index: this.ps.length, name: name, tree_sha: tree_sha, item: item } );
|
||||
this.ps.push( p );
|
||||
|
||||
|
||||
this._resizePanelsWrapper();
|
||||
|
||||
|
||||
}.bind(this)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @sha: the sha of the object
|
||||
* @e: the source element
|
||||
|
|
@ -256,7 +256,7 @@ window.F = Class.create({
|
|||
if( posTop > p.scrollTop) {
|
||||
//p.scrollTop = posTop ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* current index */
|
||||
this.cI = it.index;
|
||||
|
|
@ -264,25 +264,25 @@ window.F = Class.create({
|
|||
|
||||
/* remember the current selected item */
|
||||
this.ps[ ix ].cI = it.index;
|
||||
|
||||
|
||||
|
||||
/* don't be trigger happy: ptm = preview timer */
|
||||
if(this._p) clearTimeout( this._p );
|
||||
|
||||
/* set a small delay here incase user switches really fast (e.g. keyboard navigation ) */
|
||||
this._p = setTimeout( function(){
|
||||
|
||||
|
||||
if( it.type == 'tree' ) {
|
||||
this.renderPanel( it.sha, ix, it );
|
||||
// don't show file preview panel
|
||||
// don't show file preview panel
|
||||
$('f_c_w').hide();
|
||||
} else {
|
||||
|
||||
|
||||
$('f_c_w').show();
|
||||
if( /text/.test(it.mime_type) ) {
|
||||
$('in').className = 'on';
|
||||
GH.Blob.show( this.u, this.r, it.sha, { onSuccess: function(r) {
|
||||
this.previewTextFile(r.responseText, it);
|
||||
this.previewTextFile(r.responseText, it);
|
||||
}.bind(this)} );
|
||||
}
|
||||
}
|
||||
|
|
@ -293,12 +293,12 @@ window.F = Class.create({
|
|||
$('f_c_w').show();
|
||||
$('f_h').innerHTML = path;
|
||||
}
|
||||
|
||||
|
||||
}.bind(this), (kb ? 350 : 10)); // time out
|
||||
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
|
||||
,previewTextFile: function( text, it ) {
|
||||
text = text.replace(/\r\n/, "\n").split(/\n/);
|
||||
|
|
@ -348,13 +348,13 @@ window.F = Class.create({
|
|||
$('diffoutput').hide();
|
||||
$('in').className = 'off';
|
||||
$('f').update( html.join('') ).show();
|
||||
|
||||
|
||||
/* HACK!! */
|
||||
$('theme').observe('change', function() {
|
||||
$('theme').observe('change', function() {
|
||||
window.f.theme = $F('theme');
|
||||
$('code').removeClassName('Light').removeClassName('Dark').addClassName(window.f.theme);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
,diff:function(){ alert('Diff is disabled.'); }
|
||||
});
|
||||
|
|
@ -4,14 +4,14 @@ window.GH = {
|
|||
,proxy: './proxy.php?url='
|
||||
// ,proxy: ''
|
||||
,api: 'http://github.com/api/v2/json'
|
||||
|
||||
|
||||
/* set the proxy.php url and switch to the correct AR (AjaxRequest) */
|
||||
,setProxy: function(p) {
|
||||
,setProxy: function(p) {
|
||||
this.proxy = p;
|
||||
// window.AR = p.indexOf('./') == 0 ? Ajax.Request : JSP;
|
||||
window.AR = JSP;
|
||||
}
|
||||
|
||||
|
||||
,Commits: {
|
||||
_cache: []
|
||||
/* list all commits for a specific branch */
|
||||
|
|
@ -23,12 +23,12 @@ window.GH = {
|
|||
}
|
||||
new JSP( url, o );
|
||||
}
|
||||
|
||||
|
||||
,list: function( u, r, b, path, o ) {
|
||||
var self = this,
|
||||
url = GH.api + '/commits/list/' + u + '/' + r + '/' + b + path,
|
||||
onData = o.onData;
|
||||
|
||||
|
||||
o.onSuccess = function(res) {
|
||||
var cs = res.responseText.commits;
|
||||
// if(!cs) { alert('not found'); return;}
|
||||
|
|
@ -36,7 +36,7 @@ window.GH = {
|
|||
self._cache[ url ] = cs;
|
||||
onData( cs );
|
||||
}
|
||||
|
||||
|
||||
/* hit the cache first */
|
||||
if( this._cache[ url ] ) {
|
||||
onData( this._cache[ url ] );
|
||||
|
|
@ -45,7 +45,7 @@ window.GH = {
|
|||
|
||||
new JSP( url, o );
|
||||
}
|
||||
|
||||
|
||||
,show: function( u, r, sha, o ) {
|
||||
var self = this,
|
||||
url = GH.api + '/commits/show/' + u + '/' + r + '/' + sha,
|
||||
|
|
@ -67,38 +67,38 @@ window.GH = {
|
|||
new JSP( url, o );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
,Tree: {
|
||||
_cache: {}
|
||||
,show: function( u, r, b, tree_sha, o ) {
|
||||
var self = this,
|
||||
url = GH.api + '/tree/show/' + u +'/' + r +'/' + tree_sha,
|
||||
onData = o.onData;
|
||||
|
||||
|
||||
o.onSuccess = function(res) {
|
||||
var tree = res.responseText.tree;
|
||||
// if(!tree) { alert('not found'); return;}
|
||||
tree = tree.sort(function(a,b){
|
||||
// blobs always lose to tree
|
||||
if( a.type == 'blob' && b.type == 'tree' )
|
||||
return 1;
|
||||
if( a.type == 'blob' && b.type == 'tree' )
|
||||
return 1;
|
||||
if( a.type == 'tree' && b.type == 'blob' )
|
||||
return -1;
|
||||
return a.name > b.name ? 1 : ( a.name < b.name ? - 1 : 0 );
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/* add the index to the item */
|
||||
for( var i = 0, len = tree.length; i < len; i++ ) {
|
||||
tree[i].index = i;
|
||||
}
|
||||
|
||||
|
||||
/* cache the tree so that we don't have to re-request every time */
|
||||
self._cache[ tree_sha ] = tree;
|
||||
|
||||
|
||||
onData(tree);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* hit the cache first */
|
||||
if( this._cache[ tree_sha ] ) {
|
||||
onData( this._cache[ tree_sha ] );
|
||||
|
|
@ -108,13 +108,13 @@ window.GH = {
|
|||
new JSP( url, o);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
,Blob: {
|
||||
show: function( u, r, sha, o ) {
|
||||
var url = GH.api + '/blob/show/' + u + '/' + r + '/' + sha;
|
||||
new AR( GH.proxy + url, o );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* u,r,b: user, repo, branch
|
||||
* fn: filename
|
||||
|
|
@ -125,7 +125,7 @@ window.GH = {
|
|||
new AR( GH.proxy + url, o );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
,Repo: {
|
||||
show: function( u, r, o ) {
|
||||
var url = GH.api + '/repos/show/' + u + '/' + r,
|
||||
|
|
@ -136,10 +136,10 @@ window.GH = {
|
|||
}
|
||||
new JSP( url, o );
|
||||
}
|
||||
|
||||
|
||||
,listBranches: function( u, r, o ) {
|
||||
var url = GH.api + '/repos/show/' + u + '/' + r + '/branches',
|
||||
onData = o.onData;
|
||||
onData = o.onData;
|
||||
o.onSuccess = function(res) {
|
||||
var branches = res.responseText.branches;
|
||||
onData(branches);
|
||||
|
|
@ -147,7 +147,7 @@ window.GH = {
|
|||
new JSP( url, o );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
,Raw: {
|
||||
loadBlobAtCommit: function( u, r, commitId, path, options ) {
|
||||
//http://github.com/:user_id/:repo/raw/:commit_id/:path
|
||||
|
|
|
|||
|
|
@ -1,94 +1,94 @@
|
|||
var Keyboard = Class.create( PluginBase, {
|
||||
var Keyboard = Class.create( PluginBase, {
|
||||
initialize: function($super, f) {
|
||||
// $super(f);
|
||||
|
||||
document.observe('keydown', function(e) {
|
||||
|
||||
document.observe('keydown', function(e) {
|
||||
if(e.findElement().tagName == 'INPUT') return; // user has focus in something, bail out.
|
||||
|
||||
|
||||
// var k = e.which ? e.which : e.keyCode; // keycode
|
||||
var k = e.which || e.keyCode; // keycode
|
||||
|
||||
|
||||
var cI = f.cI,
|
||||
pI = f.pI;
|
||||
|
||||
|
||||
var p = f.ps[pI]; // panel
|
||||
var t = p.tree; // the panel's tree
|
||||
|
||||
|
||||
var d = function() {
|
||||
|
||||
var d = function() {
|
||||
if( t[ ++cI ] ) {
|
||||
var item = t[cI];
|
||||
var item = t[cI];
|
||||
// debugger
|
||||
f.click( item.sha, $$('#p' + pI + ' a')[cI], true );
|
||||
} else {
|
||||
cI--;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var u = function() {
|
||||
if( t[ --cI ] ) {
|
||||
var item = t[cI];
|
||||
var item = t[cI];
|
||||
f.click( item.sha, $$('#p' + pI + ' a')[cI], true );
|
||||
} else {
|
||||
cI++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var l = function() {
|
||||
if( f.ps[--pI] ) {
|
||||
// debugger
|
||||
t = f.ps[pI].tree;
|
||||
// get index of the previously selected item
|
||||
cI = f.ps[pI].cI;
|
||||
// var item = f.ps[pI];
|
||||
// var item = f.ps[pI];
|
||||
f.click( t[cI].sha, $$('#p' + pI + ' a')[cI], true );
|
||||
|
||||
|
||||
} else {
|
||||
pI++; // undo
|
||||
}
|
||||
pI++; // undo
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
var r = function() {
|
||||
if( !t[cI] || t[cI].type != 'tree' ) return;
|
||||
|
||||
|
||||
if( f.ps[++pI] ) {
|
||||
t = f.ps[pI].tree;
|
||||
cI = -1;
|
||||
d(); // down!
|
||||
|
||||
} else {
|
||||
pI--; // undo
|
||||
}
|
||||
pI--; // undo
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// k == 40 ? d() : ( k == 39 ? r() : ( k == 38 ? u() : ( k == 37 ? l() : '';
|
||||
switch( k ) {
|
||||
case 40: // key down
|
||||
d();
|
||||
break;
|
||||
|
||||
|
||||
case 38: // up
|
||||
u();
|
||||
break;
|
||||
|
||||
|
||||
case 37: //left
|
||||
l();
|
||||
break
|
||||
|
||||
|
||||
case 39: // right
|
||||
r();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// console.log("keypress");
|
||||
|
||||
|
||||
if( k >= 37 && k <= 40)
|
||||
e.stop();
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* Panel */
|
||||
window.P = Class.create({
|
||||
initialize: function(f, options) {
|
||||
initialize: function(f, options) {
|
||||
this.f = f;
|
||||
this.tree = options.tree || [];
|
||||
this.index = options.index || 0 ;
|
||||
|
|
@ -9,16 +9,16 @@ window.P = Class.create({
|
|||
|
||||
this.r();
|
||||
}
|
||||
|
||||
|
||||
,dispose: function() {
|
||||
$('p' + this.index ).remove();
|
||||
this.p = null;
|
||||
}
|
||||
|
||||
|
||||
,r: function() {
|
||||
this.f.psW.insert({ bottom: this.h() });
|
||||
}
|
||||
|
||||
|
||||
,h: function() {
|
||||
var it, css, recent, ix=this.index, t=this.tree,bH = this.f.bW.offsetHeight,
|
||||
h = '<ul class=files>';
|
||||
|
|
@ -26,12 +26,12 @@ window.P = Class.create({
|
|||
for( var i = 0; i < t.length; i++ ) {
|
||||
it = t[i];
|
||||
|
||||
h += '<li class=' + it.type + '>' +
|
||||
h += '<li class=' + it.type + '>' +
|
||||
'<span class="ico">' +
|
||||
'<a href="#" data-sha="' + it.sha + '" data-name="' + it.name + '" onclick="return false">' +
|
||||
'<a href="#" data-sha="' + it.sha + '" data-name="' + it.name + '" onclick="return false">' +
|
||||
it.name +
|
||||
'</a>' +
|
||||
'</span>'+
|
||||
'</a>' +
|
||||
'</span>'+
|
||||
'</li>';
|
||||
}
|
||||
h += '</ul>';
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
/* code highliter */
|
||||
var CH = Class.create( PluginBase, {
|
||||
var CH = Class.create( PluginBase, {
|
||||
initialize: function($super, f) {
|
||||
$super(f);
|
||||
|
||||
|
||||
f.theme = 'Light';
|
||||
// f.theme = 'Dark';
|
||||
|
||||
var hlt = CodeHighlighter;
|
||||
|
||||
|
||||
var getFiletype = function(filename,text) {
|
||||
var fileType,
|
||||
matchingRules = {
|
||||
matchingRules = {
|
||||
'ruby': [ /\.rb$/i, /\.ru$/i, /\bRakefile\b/i, /\bGemfile\b/i, /\.gemspec\b/i, /\bconsole\b/i, /\.rake$/i ]
|
||||
,'css': [ /\.css/i ]
|
||||
,'html': [ /\.html?$/i, /\.aspx$/i, /\.php$/i, /\.erb$/i ]
|
||||
|
|
@ -20,11 +20,11 @@ var CH = Class.create( PluginBase, {
|
|||
,'yaml': [ /\.yml$/i ]
|
||||
,'cpp': [ /\.c$/i, /\.cpp$/i, /\.h$/i ]
|
||||
,'clojure': [ /\.clj$/i ]
|
||||
,'haskell': [ /\.hs$/i ]
|
||||
,'haskell': [ /\.hs$/i ]
|
||||
};
|
||||
|
||||
|
||||
$H(matchingRules).each(function(type) {
|
||||
|
||||
|
||||
$H(matchingRules).each(function(type) {
|
||||
for( var i = 0; i < type.value.length; i++ ) {
|
||||
if( type.value[i].match(filename) ) {
|
||||
fileType = type.key;
|
||||
|
|
@ -32,43 +32,43 @@ var CH = Class.create( PluginBase, {
|
|||
}
|
||||
}
|
||||
} );
|
||||
|
||||
|
||||
// debugger
|
||||
|
||||
|
||||
/* attempt to futher detect the fileType */
|
||||
if( !fileType ) {
|
||||
text = text.replace(/\r\n/, "\n").split(/\n/)[0];
|
||||
fileType = /ruby/i.test(text) ? 'ruby' :
|
||||
/python/i.test(text) ? 'python' :
|
||||
/php/i.test(text) ? 'php' :
|
||||
fileType = /ruby/i.test(text) ? 'ruby' :
|
||||
/python/i.test(text) ? 'python' :
|
||||
/php/i.test(text) ? 'php' :
|
||||
'';
|
||||
}
|
||||
|
||||
|
||||
return fileType;
|
||||
}
|
||||
|
||||
|
||||
var old = f.previewTextFile;
|
||||
f.previewTextFile = function( text, item ) {
|
||||
f.previewTextFile = function( text, item ) {
|
||||
old(text,item);
|
||||
var codeEl = $('code');
|
||||
codeEl.className = f.theme; // clear previous syntax class
|
||||
codeEl.addClassName(getFiletype(item.name,text));
|
||||
|
||||
|
||||
hlt.init();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* add the link to the stylesheet */
|
||||
// ,addStylesheet: function() {
|
||||
// // <link href="css/code_highlighter.css" media="all" rel="stylesheet" type="text/css" />
|
||||
// // <link href="css/code_highlighter.css" media="all" rel="stylesheet" type="text/css" />
|
||||
// var css = document.createElement('link');
|
||||
// css.href = 'css/code_highlighter.css';
|
||||
// css.rel = 'stylesheet';
|
||||
// css.type = 'text/css';
|
||||
// document.body.appendChild(css);
|
||||
// }
|
||||
|
||||
|
||||
});
|
||||
|
||||
FP.push(CH);
|
||||
586
GithubFinder/javascripts/vendors/code_highlighter.js
vendored
586
GithubFinder/javascripts/vendors/code_highlighter.js
vendored
|
|
@ -1,85 +1,85 @@
|
|||
/* Unobtrustive Code Highlighter By Dan Webb 11/2005
|
||||
Version: 0.4
|
||||
|
||||
Usage:
|
||||
Add a script tag for this script and any stylesets you need to use
|
||||
to the page in question, add correct class names to CODE elements,
|
||||
define CSS styles for elements. That's it!
|
||||
Usage:
|
||||
Add a script tag for this script and any stylesets you need to use
|
||||
to the page in question, add correct class names to CODE elements,
|
||||
define CSS styles for elements. That's it!
|
||||
|
||||
Known to work on:
|
||||
IE 5.5+ PC
|
||||
Firefox/Mozilla PC/Mac
|
||||
Opera 7.23 + PC
|
||||
Safari 2
|
||||
Known to work on:
|
||||
IE 5.5+ PC
|
||||
Firefox/Mozilla PC/Mac
|
||||
Opera 7.23 + PC
|
||||
Safari 2
|
||||
|
||||
Known to degrade gracefully on:
|
||||
IE5.0 PC
|
||||
Known to degrade gracefully on:
|
||||
IE5.0 PC
|
||||
|
||||
Note: IE5.0 fails due to the use of lookahead in some stylesets. To avoid script errors
|
||||
in older browsers use expressions that use lookahead in string format when defining stylesets.
|
||||
Note: IE5.0 fails due to the use of lookahead in some stylesets. To avoid script errors
|
||||
in older browsers use expressions that use lookahead in string format when defining stylesets.
|
||||
|
||||
This script is inspired by star-light by entirely cunning Dean Edwards
|
||||
http://dean.edwards.name/star-light/.
|
||||
This script is inspired by star-light by entirely cunning Dean Edwards
|
||||
http://dean.edwards.name/star-light/.
|
||||
*/
|
||||
|
||||
// replace callback support for safari.
|
||||
if ("a".replace(/a/, function() {return "b"}) != "b") (function(){
|
||||
var default_replace = String.prototype.replace;
|
||||
String.prototype.replace = function(search,replace){
|
||||
// replace is not function
|
||||
if(typeof replace != "function"){
|
||||
return default_replace.apply(this,arguments)
|
||||
}
|
||||
var str = "" + this;
|
||||
var callback = replace;
|
||||
// search string is not RegExp
|
||||
if(!(search instanceof RegExp)){
|
||||
var idx = str.indexOf(search);
|
||||
return (
|
||||
idx == -1 ? str :
|
||||
default_replace.apply(str,[search,callback(search, idx, str)])
|
||||
)
|
||||
}
|
||||
var reg = search;
|
||||
var result = [];
|
||||
var lastidx = reg.lastIndex;
|
||||
var re;
|
||||
while((re = reg.exec(str)) != null){
|
||||
var idx = re.index;
|
||||
var args = re.concat(idx, str);
|
||||
result.push(
|
||||
str.slice(lastidx,idx),
|
||||
callback.apply(null,args).toString()
|
||||
);
|
||||
if(!reg.global){
|
||||
lastidx += RegExp.lastMatch.length;
|
||||
break
|
||||
}else{
|
||||
lastidx = reg.lastIndex;
|
||||
}
|
||||
}
|
||||
result.push(str.slice(lastidx));
|
||||
return result.join("")
|
||||
// replace is not function
|
||||
if(typeof replace != "function"){
|
||||
return default_replace.apply(this,arguments)
|
||||
}
|
||||
var str = "" + this;
|
||||
var callback = replace;
|
||||
// search string is not RegExp
|
||||
if(!(search instanceof RegExp)){
|
||||
var idx = str.indexOf(search);
|
||||
return (
|
||||
idx == -1 ? str :
|
||||
default_replace.apply(str,[search,callback(search, idx, str)])
|
||||
)
|
||||
}
|
||||
var reg = search;
|
||||
var result = [];
|
||||
var lastidx = reg.lastIndex;
|
||||
var re;
|
||||
while((re = reg.exec(str)) != null){
|
||||
var idx = re.index;
|
||||
var args = re.concat(idx, str);
|
||||
result.push(
|
||||
str.slice(lastidx,idx),
|
||||
callback.apply(null,args).toString()
|
||||
);
|
||||
if(!reg.global){
|
||||
lastidx += RegExp.lastMatch.length;
|
||||
break
|
||||
}else{
|
||||
lastidx = reg.lastIndex;
|
||||
}
|
||||
}
|
||||
result.push(str.slice(lastidx));
|
||||
return result.join("")
|
||||
}
|
||||
})();
|
||||
|
||||
var CodeHighlighter = { styleSets : new Array };
|
||||
|
||||
CodeHighlighter.addStyle = function(name, rules) {
|
||||
// using push test to disallow older browsers from adding styleSets
|
||||
if ([].push) this.styleSets.push({
|
||||
name : name,
|
||||
rules : rules,
|
||||
ignoreCase : arguments[2] || false
|
||||
})
|
||||
// using push test to disallow older browsers from adding styleSets
|
||||
if ([].push) this.styleSets.push({
|
||||
name : name,
|
||||
rules : rules,
|
||||
ignoreCase : arguments[2] || false
|
||||
})
|
||||
|
||||
// function setEvent() {
|
||||
// // set highlighter to run on load (use LowPro if present)
|
||||
// if (typeof Event != 'undefined' && typeof Event.onReady == 'function')
|
||||
// return Event.onReady(CodeHighlighter.init.bind(CodeHighlighter));
|
||||
//
|
||||
//
|
||||
// var old = window.onload;
|
||||
//
|
||||
//
|
||||
// if (typeof window.onload != 'function') {
|
||||
// window.onload = function() { CodeHighlighter.init() };
|
||||
// } else {
|
||||
|
|
@ -89,306 +89,306 @@ CodeHighlighter.addStyle = function(name, rules) {
|
|||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // only set the event when the first style is added
|
||||
// if (this.styleSets.length==1) setEvent();
|
||||
}
|
||||
|
||||
CodeHighlighter.init = function() {
|
||||
if (!document.getElementsByTagName) return;
|
||||
if ("a".replace(/a/, function() {return "b"}) != "b") return; // throw out Safari versions that don't support replace function
|
||||
// throw out older browsers
|
||||
if (!document.getElementsByTagName) return;
|
||||
if ("a".replace(/a/, function() {return "b"}) != "b") return; // throw out Safari versions that don't support replace function
|
||||
// throw out older browsers
|
||||
|
||||
// var codeEls = document.getElementsByTagName("CODE");
|
||||
|
||||
// HACK:
|
||||
|
||||
// HACK:
|
||||
var codeEls = [$('code')];
|
||||
|
||||
// collect array of all pre elements
|
||||
codeEls.filter = function(f) {
|
||||
var a = new Array;
|
||||
for (var i = 0; i < this.length; i++)
|
||||
if (f(this[i]))
|
||||
a[a.length] = this[i];
|
||||
return a;
|
||||
}
|
||||
|
||||
var rules = new Array;
|
||||
rules.toString = function() {
|
||||
// joins regexes into one big parallel regex
|
||||
var exps = new Array;
|
||||
for (var i = 0; i < this.length; i++) exps.push(this[i].exp);
|
||||
return exps.join("|");
|
||||
}
|
||||
// collect array of all pre elements
|
||||
codeEls.filter = function(f) {
|
||||
var a = new Array;
|
||||
for (var i = 0; i < this.length; i++)
|
||||
if (f(this[i]))
|
||||
a[a.length] = this[i];
|
||||
return a;
|
||||
}
|
||||
|
||||
function addRule(className, rule) {
|
||||
// add a replace rule
|
||||
var exp = (typeof rule.exp != "string")?String(rule.exp).substr(1, String(rule.exp).length-2):rule.exp;
|
||||
// converts regex rules to strings and chops of the slashes
|
||||
rules.push({
|
||||
className : className,
|
||||
exp : "(" + exp + ")",
|
||||
length : (exp.match(/(^|[^\\])\([^?]/g) || "").length + 1, // number of subexps in rule
|
||||
replacement : rule.replacement || null
|
||||
});
|
||||
}
|
||||
var rules = new Array;
|
||||
rules.toString = function() {
|
||||
// joins regexes into one big parallel regex
|
||||
var exps = new Array;
|
||||
for (var i = 0; i < this.length; i++) exps.push(this[i].exp);
|
||||
return exps.join("|");
|
||||
}
|
||||
|
||||
function parse(text, ignoreCase) {
|
||||
// main text parsing and replacement
|
||||
return text.replace(new RegExp(rules, (ignoreCase)?"gi":"g"), function() {
|
||||
var i = 0, j = 1, rule;
|
||||
while (rule = rules[i++]) {
|
||||
if (arguments[j]) {
|
||||
// if no custom replacement defined do the simple replacement
|
||||
if (!rule.replacement) return "<span class=\"" + rule.className + "\">" + arguments[0] + "</span>";
|
||||
else {
|
||||
// replace $0 with the className then do normal replaces
|
||||
var str = rule.replacement.replace("$0", rule.className);
|
||||
for (var k = 1; k <= rule.length - 1; k++) str = str.replace("$" + k, arguments[j + k]);
|
||||
return str;
|
||||
}
|
||||
} else j+= rule.length;
|
||||
}
|
||||
});
|
||||
}
|
||||
function addRule(className, rule) {
|
||||
// add a replace rule
|
||||
var exp = (typeof rule.exp != "string")?String(rule.exp).substr(1, String(rule.exp).length-2):rule.exp;
|
||||
// converts regex rules to strings and chops of the slashes
|
||||
rules.push({
|
||||
className : className,
|
||||
exp : "(" + exp + ")",
|
||||
length : (exp.match(/(^|[^\\])\([^?]/g) || "").length + 1, // number of subexps in rule
|
||||
replacement : rule.replacement || null
|
||||
});
|
||||
}
|
||||
|
||||
function parse(text, ignoreCase) {
|
||||
// main text parsing and replacement
|
||||
return text.replace(new RegExp(rules, (ignoreCase)?"gi":"g"), function() {
|
||||
var i = 0, j = 1, rule;
|
||||
while (rule = rules[i++]) {
|
||||
if (arguments[j]) {
|
||||
// if no custom replacement defined do the simple replacement
|
||||
if (!rule.replacement) return "<span class=\"" + rule.className + "\">" + arguments[0] + "</span>";
|
||||
else {
|
||||
// replace $0 with the className then do normal replaces
|
||||
var str = rule.replacement.replace("$0", rule.className);
|
||||
for (var k = 1; k <= rule.length - 1; k++) str = str.replace("$" + k, arguments[j + k]);
|
||||
return str;
|
||||
}
|
||||
} else j+= rule.length;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function highlightCode(styleSet) {
|
||||
// clear rules array
|
||||
var parsed, clsRx = new RegExp("(\\s|^)" + styleSet.name + "(\\s|$)");
|
||||
rules.length = 0;
|
||||
|
||||
function highlightCode(styleSet) {
|
||||
// clear rules array
|
||||
var parsed, clsRx = new RegExp("(\\s|^)" + styleSet.name + "(\\s|$)");
|
||||
rules.length = 0;
|
||||
|
||||
// // get stylable elements by filtering out all code elements without the correct className
|
||||
var stylableEls = codeEls.filter(function(item) { return clsRx.test(item.className) });
|
||||
// var stylableEls = codeEls;
|
||||
|
||||
// add style rules to parser
|
||||
for (var className in styleSet.rules) addRule(className, styleSet.rules[className]);
|
||||
|
||||
// add style rules to parser
|
||||
for (var className in styleSet.rules) addRule(className, styleSet.rules[className]);
|
||||
|
||||
|
||||
// replace for all elements
|
||||
for (var i = 0; i < stylableEls.length; i++) {
|
||||
// EVIL hack to fix IE whitespace badness if it's inside a <pre>
|
||||
if (/MSIE/.test(navigator.appVersion) && stylableEls[i].parentNode.nodeName == 'PRE') {
|
||||
stylableEls[i] = stylableEls[i].parentNode;
|
||||
// replace for all elements
|
||||
for (var i = 0; i < stylableEls.length; i++) {
|
||||
// EVIL hack to fix IE whitespace badness if it's inside a <pre>
|
||||
if (/MSIE/.test(navigator.appVersion) && stylableEls[i].parentNode.nodeName == 'PRE') {
|
||||
stylableEls[i] = stylableEls[i].parentNode;
|
||||
|
||||
parsed = stylableEls[i].innerHTML.replace(/(<code[^>]*>)([^<]*)<\/code>/i, function() {
|
||||
return arguments[1] + parse(arguments[2], styleSet.ignoreCase) + "</code>"
|
||||
});
|
||||
parsed = parsed.replace(/\n( *)/g, function() {
|
||||
var spaces = "";
|
||||
for (var i = 0; i < arguments[1].length; i++) spaces+= " ";
|
||||
return "\n" + spaces;
|
||||
});
|
||||
parsed = parsed.replace(/\t/g, " ");
|
||||
parsed = parsed.replace(/\n(<\/\w+>)?/g, "<br />$1").replace(/<br \/>[\n\r\s]*<br \/>/g, "<p><br></p>");
|
||||
parsed = stylableEls[i].innerHTML.replace(/(<code[^>]*>)([^<]*)<\/code>/i, function() {
|
||||
return arguments[1] + parse(arguments[2], styleSet.ignoreCase) + "</code>"
|
||||
});
|
||||
parsed = parsed.replace(/\n( *)/g, function() {
|
||||
var spaces = "";
|
||||
for (var i = 0; i < arguments[1].length; i++) spaces+= " ";
|
||||
return "\n" + spaces;
|
||||
});
|
||||
parsed = parsed.replace(/\t/g, " ");
|
||||
parsed = parsed.replace(/\n(<\/\w+>)?/g, "<br />$1").replace(/<br \/>[\n\r\s]*<br \/>/g, "<p><br></p>");
|
||||
|
||||
} else parsed = parse(stylableEls[i].innerHTML, styleSet.ignoreCase);
|
||||
} else parsed = parse(stylableEls[i].innerHTML, styleSet.ignoreCase);
|
||||
|
||||
stylableEls[i].innerHTML = parsed;
|
||||
}
|
||||
}
|
||||
stylableEls[i].innerHTML = parsed;
|
||||
}
|
||||
}
|
||||
|
||||
// run highlighter on all stylesets
|
||||
for (var i=0; i < this.styleSets.length; i++) {
|
||||
highlightCode(this.styleSets[i]);
|
||||
}
|
||||
// run highlighter on all stylesets
|
||||
for (var i=0; i < this.styleSets.length; i++) {
|
||||
highlightCode(this.styleSets[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
CodeHighlighter.addStyle("css", {
|
||||
comment : {
|
||||
exp : /\/\*[^*]*\*+([^\/][^*]*\*+)*\//
|
||||
},
|
||||
keywords : {
|
||||
exp : /@\w[\w\s]*/
|
||||
},
|
||||
selectors : {
|
||||
exp : "([\\w-:\\[.#][^{};>]*)(?={)"
|
||||
},
|
||||
properties : {
|
||||
exp : "([\\w-]+)(?=\\s*:)"
|
||||
},
|
||||
units : {
|
||||
exp : /([0-9])(em|en|px|%|pt)\b/,
|
||||
replacement : "$1<span class=\"$0\">$2</span>"
|
||||
},
|
||||
urls : {
|
||||
exp : /url\([^\)]*\)/
|
||||
}
|
||||
comment : {
|
||||
exp : /\/\*[^*]*\*+([^\/][^*]*\*+)*\//
|
||||
},
|
||||
keywords : {
|
||||
exp : /@\w[\w\s]*/
|
||||
},
|
||||
selectors : {
|
||||
exp : "([\\w-:\\[.#][^{};>]*)(?={)"
|
||||
},
|
||||
properties : {
|
||||
exp : "([\\w-]+)(?=\\s*:)"
|
||||
},
|
||||
units : {
|
||||
exp : /([0-9])(em|en|px|%|pt)\b/,
|
||||
replacement : "$1<span class=\"$0\">$2</span>"
|
||||
},
|
||||
urls : {
|
||||
exp : /url\([^\)]*\)/
|
||||
}
|
||||
});
|
||||
|
||||
CodeHighlighter.addStyle("ruby",{
|
||||
comment : {
|
||||
exp : /#[^\n]*/
|
||||
},
|
||||
brackets : {
|
||||
exp : /\(|\)/
|
||||
},
|
||||
string : {
|
||||
exp : /'[^'\\]*(\\.[^'\\]*)*'|"[^"\\]*(\\.[^"\\]*)*"|\%w\(.*\)|`[^`\\]*(\\.[^`\\]*)*`/
|
||||
},
|
||||
keywords : {
|
||||
exp : /\b(do|end|self|class|def|if|module|yield|then|else|for|until|unless|while|elsif|case|when|break|retry|redo|rescue|require|raise|extend)\b/
|
||||
},
|
||||
/* Added by Shelly Fisher (shelly@agileevolved.com) */
|
||||
symbol : {
|
||||
exp : /([^:])(:[A-Za-z0-9_!?]+)/
|
||||
}
|
||||
comment : {
|
||||
exp : /#[^\n]*/
|
||||
},
|
||||
brackets : {
|
||||
exp : /\(|\)/
|
||||
},
|
||||
string : {
|
||||
exp : /'[^'\\]*(\\.[^'\\]*)*'|"[^"\\]*(\\.[^"\\]*)*"|\%w\(.*\)|`[^`\\]*(\\.[^`\\]*)*`/
|
||||
},
|
||||
keywords : {
|
||||
exp : /\b(do|end|self|class|def|if|module|yield|then|else|for|until|unless|while|elsif|case|when|break|retry|redo|rescue|require|raise|extend)\b/
|
||||
},
|
||||
/* Added by Shelly Fisher (shelly@agileevolved.com) */
|
||||
symbol : {
|
||||
exp : /([^:])(:[A-Za-z0-9_!?]+)/
|
||||
}
|
||||
});
|
||||
|
||||
CodeHighlighter.addStyle("html", {
|
||||
comment : {
|
||||
exp: /<!\s*(--([^-]|[\r\n]|-[^-])*--\s*)>/
|
||||
},
|
||||
tag : {
|
||||
exp: /(<\/?)([a-zA-Z1-9]+\s?)/,
|
||||
replacement: "$1<span class=\"$0\">$2"
|
||||
},
|
||||
string : {
|
||||
exp : /'[^']*'|"[^"]*"/
|
||||
},
|
||||
attribute : {
|
||||
exp: /\b([a-zA-Z-:]+)(=)/,
|
||||
replacement: "<span class=\"$0\">$1$2"
|
||||
},
|
||||
doctype : {
|
||||
exp: /<!DOCTYPE([^&]|&[^g]|&g[^t])*>/
|
||||
}
|
||||
comment : {
|
||||
exp: /<!\s*(--([^-]|[\r\n]|-[^-])*--\s*)>/
|
||||
},
|
||||
tag : {
|
||||
exp: /(<\/?)([a-zA-Z1-9]+\s?)/,
|
||||
replacement: "$1<span class=\"$0\">$2"
|
||||
},
|
||||
string : {
|
||||
exp : /'[^']*'|"[^"]*"/
|
||||
},
|
||||
attribute : {
|
||||
exp: /\b([a-zA-Z-:]+)(=)/,
|
||||
replacement: "<span class=\"$0\">$1$2"
|
||||
},
|
||||
doctype : {
|
||||
exp: /<!DOCTYPE([^&]|&[^g]|&g[^t])*>/
|
||||
}
|
||||
});
|
||||
|
||||
CodeHighlighter.addStyle("javascript",{
|
||||
comment : {
|
||||
exp : /(\/\/[^\n]*(\n|$))|(\/\*[^*]*\*+([^\/][^*]*\*+)*\/)/
|
||||
},
|
||||
parameter: {
|
||||
exp: /\bfunction\s?\((.+)\)/
|
||||
comment : {
|
||||
exp : /(\/\/[^\n]*(\n|$))|(\/\*[^*]*\*+([^\/][^*]*\*+)*\/)/
|
||||
},
|
||||
parameter: {
|
||||
exp: /\bfunction\s?\((.+)\)/
|
||||
// ,replacement: "<span class='parameter'>$1</span>"
|
||||
},
|
||||
|
||||
brackets : {
|
||||
exp : /\(|\)/
|
||||
},
|
||||
string : {
|
||||
exp : /'[^']*'|"[^"]*"/
|
||||
},
|
||||
keywords : {
|
||||
exp : /\b(arguments|break|case|continue|default|delete|do|else|false|for|function|if|in|instanceof|new|null|return|switch|this|true|typeof|var|void|while|with)\b/
|
||||
},
|
||||
global : {
|
||||
exp : /\b(toString|valueOf|window|element|prototype|constructor|document|escape|unescape|parseInt|parseFloat|setTimeout|clearTimeout|setInterval|clearInterval|NaN|isNaN|Infinity|String|Numeric|Array)\b/
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
brackets : {
|
||||
exp : /\(|\)/
|
||||
},
|
||||
string : {
|
||||
exp : /'[^']*'|"[^"]*"/
|
||||
},
|
||||
keywords : {
|
||||
exp : /\b(arguments|break|case|continue|default|delete|do|else|false|for|function|if|in|instanceof|new|null|return|switch|this|true|typeof|var|void|while|with)\b/
|
||||
},
|
||||
global : {
|
||||
exp : /\b(toString|valueOf|window|element|prototype|constructor|document|escape|unescape|parseInt|parseFloat|setTimeout|clearTimeout|setInterval|clearInterval|NaN|isNaN|Infinity|String|Numeric|Array)\b/
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
CodeHighlighter.addStyle("yaml", {
|
||||
keyword : {
|
||||
exp : /\/\*[^*]*\*+([^\/][^*]*\*+)*\//
|
||||
},
|
||||
value : {
|
||||
exp : /@\w[\w\s]*/
|
||||
}
|
||||
keyword : {
|
||||
exp : /\/\*[^*]*\*+([^\/][^*]*\*+)*\//
|
||||
},
|
||||
value : {
|
||||
exp : /@\w[\w\s]*/
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
CodeHighlighter.addStyle("python",{
|
||||
comment : {
|
||||
exp : /#[^\n]+/
|
||||
},
|
||||
brackets : {
|
||||
exp : /\(|\)/
|
||||
},
|
||||
string : {
|
||||
exp : /'[^'\\]*(\\.[^'\\]*)*'|"[^"\\]*(\\.[^"\\]*)*"|""".*"""/
|
||||
},
|
||||
keywords : {
|
||||
exp : /\b(and|assert|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|not|or|pass|print|raise|return|try|while|yield|as|None)\b/
|
||||
}
|
||||
comment : {
|
||||
exp : /#[^\n]+/
|
||||
},
|
||||
brackets : {
|
||||
exp : /\(|\)/
|
||||
},
|
||||
string : {
|
||||
exp : /'[^'\\]*(\\.[^'\\]*)*'|"[^"\\]*(\\.[^"\\]*)*"|""".*"""/
|
||||
},
|
||||
keywords : {
|
||||
exp : /\b(and|assert|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|not|or|pass|print|raise|return|try|while|yield|as|None)\b/
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
CodeHighlighter.addStyle("applescript",{
|
||||
comment : {
|
||||
exp : /--[^\n]+|#![^\n]+/
|
||||
},
|
||||
brackets : {
|
||||
exp : /\(|\)/
|
||||
},
|
||||
string : {
|
||||
exp : /"[^"\\]*(\\.[^"\\]*)*"/
|
||||
},
|
||||
keywords : {
|
||||
exp : /\b(about|above|after|against|and|apart[\s]+from|around|as|aside[\s]+from|at|back|before|beginning|behind|below|beneath|beside|between|but|by|considering|contain|contains|contains|continue|copy|div|does|eighth|else|end|equal|equals|error|every|exit|false|fifth|first|for|fourth|from|front|get|given|global|if|ignoring|in|instead[\s]+of|into|is|it|its|last|local|me|middle|mod|my|ninth|not|of|on|onto|or|out[\s]+of|over|prop|property|put|ref|reference|repeat|return|returning|script|second|set|seventh|since|sixth|some|tell|tenth|that|the|then|third|through|thru|timeout|times|to|transaction|true|try|until|where|while|whose|with|without)\b/
|
||||
},
|
||||
global : {
|
||||
exp : /\b(AppleScript('s)?|current[\s]+application|missing[\s]+value|false|pi|true|version)\b/
|
||||
}
|
||||
comment : {
|
||||
exp : /--[^\n]+|#![^\n]+/
|
||||
},
|
||||
brackets : {
|
||||
exp : /\(|\)/
|
||||
},
|
||||
string : {
|
||||
exp : /"[^"\\]*(\\.[^"\\]*)*"/
|
||||
},
|
||||
keywords : {
|
||||
exp : /\b(about|above|after|against|and|apart[\s]+from|around|as|aside[\s]+from|at|back|before|beginning|behind|below|beneath|beside|between|but|by|considering|contain|contains|contains|continue|copy|div|does|eighth|else|end|equal|equals|error|every|exit|false|fifth|first|for|fourth|from|front|get|given|global|if|ignoring|in|instead[\s]+of|into|is|it|its|last|local|me|middle|mod|my|ninth|not|of|on|onto|or|out[\s]+of|over|prop|property|put|ref|reference|repeat|return|returning|script|second|set|seventh|since|sixth|some|tell|tenth|that|the|then|third|through|thru|timeout|times|to|transaction|true|try|until|where|while|whose|with|without)\b/
|
||||
},
|
||||
global : {
|
||||
exp : /\b(AppleScript('s)?|current[\s]+application|missing[\s]+value|false|pi|true|version)\b/
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
CodeHighlighter.addStyle("cpp",{
|
||||
comment : {
|
||||
exp : /(\/\/[^\n]*(\n|$))|(\/\*[^*]*\*+([^\/][^*]*\*+)*\/)/
|
||||
},
|
||||
brackets : {
|
||||
exp : /\(|\)/
|
||||
},
|
||||
string : {
|
||||
exp : /"[^"\\]*(\\.[^"\\]*)*"/
|
||||
},
|
||||
keywords : {
|
||||
exp : /\b(break|case|catch|class|const|__finally|__exception|__try|const_cast|continue|private|public|protected|__declspec|default|delete|deprecated|dllexport|dllimport|do|dynamic_cast|else|enum|explicit|extern|if|for|friend|goto|inline|mutable|naked|namespace|new|noinline|noreturn|nothrow|register|reinterpret_cast|return|selectany|sizeof|static|static_cast|struct|switch|template|this|thread|throw|true|false|try|typedef|typeid|typename|union|using|uuid|virtual|void|volatile|whcar_t|while)\b/
|
||||
},
|
||||
|
||||
datatype: {
|
||||
exp : /\b(ATOM|BOOL|BOOLEAN|BYTE|CHAR|COLORREF|DWORD|DWORDLONG|DWORD_PTR|DWORD32|DWORD64|FLOAT|HACCEL|HALF_PTR|HANDLE|HBITMAP|HBRUSH|HCOLORSPACE|HCONV|HCONVLIST|HCURSOR|HDC|HDDEDATA|HDESK|HDROP|HDWP|HENHMETAFILE|HFILE|HFONT|HGDIOBJ|HGLOBAL|HHOOK|HICON|HINSTANCE|HKEY|HKL|HLOCAL|HMENU|HMETAFILE|HMODULE|HMONITOR|HPALETTE|HPEN|HRESULT|HRGN|HRSRC|HSZ|HWINSTA|HWND|INT|INT_PTR|INT32|INT64|LANGID|LCID|LCTYPE|LGRPID|LONG|LONGLONG|LONG_PTR|LONG32|LONG64|LPARAM|LPBOOL|LPBYTE|LPCOLORREF|LPCSTR|LPCTSTR|LPCVOID|LPCWSTR|LPDWORD|LPHANDLE|LPINT|LPLONG|LPSTR|LPTSTR|LPVOID|LPWORD|LPWSTR|LRESULT|PBOOL|PBOOLEAN|PBYTE|PCHAR|PCSTR|PCTSTR|PCWSTR|PDWORDLONG|PDWORD_PTR|PDWORD32|PDWORD64|PFLOAT|PHALF_PTR|PHANDLE|PHKEY|PINT|PINT_PTR|PINT32|PINT64|PLCID|PLONG|PLONGLONG|PLONG_PTR|PLONG32|PLONG64|POINTER_32|POINTER_64|PSHORT|PSIZE_T|PSSIZE_T|PSTR|PTBYTE|PTCHAR|PTSTR|PUCHAR|PUHALF_PTR|PUINT|PUINT_PTR|PUINT32|PUINT64|PULONG|PULONGLONG|PULONG_PTR|PULONG32|PULONG64|PUSHORT|PVOID|PWCHAR|PWORD|PWSTR|SC_HANDLE|SC_LOCK|SERVICE_STATUS_HANDLE|SHORT|SIZE_T|SSIZE_T|TBYTE|TCHAR|UCHAR|UHALF_PTR|UINT|UINT_PTR|UINT32|UINT64|ULONG|ULONGLONG|ULONG_PTR|ULONG32|ULONG64|USHORT|USN|VOID|WCHAR|WORD|WPARAM|WPARAM|WPARAM|char|bool|short|int|__int32|__int64|__int8|__int16|long|float|double|__wchar_t|clock_t|_complex|_dev_t|_diskfree_t|div_t|ldiv_t|_exception|_EXCEPTION_POINTERS|FILE|_finddata_t|_finddatai64_t|_wfinddata_t|_wfinddatai64_t|__finddata64_t|__wfinddata64_t|_FPIEEE_RECORD|fpos_t|_HEAPINFO|_HFILE|lconv|intptr_t|jmp_buf|mbstate_t|_off_t|_onexit_t|_PNH|ptrdiff_t|_purecall_handler|sig_atomic_t|size_t|_stat|__stat64|_stati64|terminate_function|time_t|__time64_t|_timeb|__timeb64|tm|uintptr_t|_utimbuf|va_list|wchar_t|wctrans_t|wctype_t|wint_t|signed)\b/
|
||||
},
|
||||
|
||||
preprocessor : {
|
||||
exp : /^ *#.*/gm
|
||||
}
|
||||
comment : {
|
||||
exp : /(\/\/[^\n]*(\n|$))|(\/\*[^*]*\*+([^\/][^*]*\*+)*\/)/
|
||||
},
|
||||
brackets : {
|
||||
exp : /\(|\)/
|
||||
},
|
||||
string : {
|
||||
exp : /"[^"\\]*(\\.[^"\\]*)*"/
|
||||
},
|
||||
keywords : {
|
||||
exp : /\b(break|case|catch|class|const|__finally|__exception|__try|const_cast|continue|private|public|protected|__declspec|default|delete|deprecated|dllexport|dllimport|do|dynamic_cast|else|enum|explicit|extern|if|for|friend|goto|inline|mutable|naked|namespace|new|noinline|noreturn|nothrow|register|reinterpret_cast|return|selectany|sizeof|static|static_cast|struct|switch|template|this|thread|throw|true|false|try|typedef|typeid|typename|union|using|uuid|virtual|void|volatile|whcar_t|while)\b/
|
||||
},
|
||||
|
||||
datatype: {
|
||||
exp : /\b(ATOM|BOOL|BOOLEAN|BYTE|CHAR|COLORREF|DWORD|DWORDLONG|DWORD_PTR|DWORD32|DWORD64|FLOAT|HACCEL|HALF_PTR|HANDLE|HBITMAP|HBRUSH|HCOLORSPACE|HCONV|HCONVLIST|HCURSOR|HDC|HDDEDATA|HDESK|HDROP|HDWP|HENHMETAFILE|HFILE|HFONT|HGDIOBJ|HGLOBAL|HHOOK|HICON|HINSTANCE|HKEY|HKL|HLOCAL|HMENU|HMETAFILE|HMODULE|HMONITOR|HPALETTE|HPEN|HRESULT|HRGN|HRSRC|HSZ|HWINSTA|HWND|INT|INT_PTR|INT32|INT64|LANGID|LCID|LCTYPE|LGRPID|LONG|LONGLONG|LONG_PTR|LONG32|LONG64|LPARAM|LPBOOL|LPBYTE|LPCOLORREF|LPCSTR|LPCTSTR|LPCVOID|LPCWSTR|LPDWORD|LPHANDLE|LPINT|LPLONG|LPSTR|LPTSTR|LPVOID|LPWORD|LPWSTR|LRESULT|PBOOL|PBOOLEAN|PBYTE|PCHAR|PCSTR|PCTSTR|PCWSTR|PDWORDLONG|PDWORD_PTR|PDWORD32|PDWORD64|PFLOAT|PHALF_PTR|PHANDLE|PHKEY|PINT|PINT_PTR|PINT32|PINT64|PLCID|PLONG|PLONGLONG|PLONG_PTR|PLONG32|PLONG64|POINTER_32|POINTER_64|PSHORT|PSIZE_T|PSSIZE_T|PSTR|PTBYTE|PTCHAR|PTSTR|PUCHAR|PUHALF_PTR|PUINT|PUINT_PTR|PUINT32|PUINT64|PULONG|PULONGLONG|PULONG_PTR|PULONG32|PULONG64|PUSHORT|PVOID|PWCHAR|PWORD|PWSTR|SC_HANDLE|SC_LOCK|SERVICE_STATUS_HANDLE|SHORT|SIZE_T|SSIZE_T|TBYTE|TCHAR|UCHAR|UHALF_PTR|UINT|UINT_PTR|UINT32|UINT64|ULONG|ULONGLONG|ULONG_PTR|ULONG32|ULONG64|USHORT|USN|VOID|WCHAR|WORD|WPARAM|WPARAM|WPARAM|char|bool|short|int|__int32|__int64|__int8|__int16|long|float|double|__wchar_t|clock_t|_complex|_dev_t|_diskfree_t|div_t|ldiv_t|_exception|_EXCEPTION_POINTERS|FILE|_finddata_t|_finddatai64_t|_wfinddata_t|_wfinddatai64_t|__finddata64_t|__wfinddata64_t|_FPIEEE_RECORD|fpos_t|_HEAPINFO|_HFILE|lconv|intptr_t|jmp_buf|mbstate_t|_off_t|_onexit_t|_PNH|ptrdiff_t|_purecall_handler|sig_atomic_t|size_t|_stat|__stat64|_stati64|terminate_function|time_t|__time64_t|_timeb|__timeb64|tm|uintptr_t|_utimbuf|va_list|wchar_t|wctrans_t|wctype_t|wint_t|signed)\b/
|
||||
},
|
||||
|
||||
preprocessor : {
|
||||
exp : /^ *#.*/gm
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// http://www.undermyhat.org/blog/wp-content/uploads/2009/09/shBrushClojure.js
|
||||
CodeHighlighter.addStyle("clojure",{
|
||||
comment : {
|
||||
exp : /;[^\]]+$/
|
||||
},
|
||||
string : {
|
||||
exp : /"[^"\\]*(\\.[^"\\]*)*"/m
|
||||
},
|
||||
functions : {
|
||||
exp : /\b(:arglists|:doc|:file|:line|:macro|:name|:ns|:private|:tag|:test|new|alias|alter|and|apply|assert|class|cond|conj|count|def|defmacro|defn|defstruct|deref|do|doall|dorun|doseq|dosync|eval|filter|finally|find|first|fn|gen-class|gensym|if|import|inc|keys|let|list|loop|map|ns|or|print|println|quote|rand|recur|reduce|ref|repeat|require|rest|send|seq|set|sort|str|struct|sync|take|test|throw|trampoline|try|type|use|var|vec|when|while)\b/gmi
|
||||
},
|
||||
|
||||
keyword : {
|
||||
exp : /\[|\]/g
|
||||
},
|
||||
|
||||
symbols : {
|
||||
exp : /'[a-z][A-Za-z0-9_]*/g
|
||||
},
|
||||
comment : {
|
||||
exp : /;[^\]]+$/
|
||||
},
|
||||
string : {
|
||||
exp : /"[^"\\]*(\\.[^"\\]*)*"/m
|
||||
},
|
||||
functions : {
|
||||
exp : /\b(:arglists|:doc|:file|:line|:macro|:name|:ns|:private|:tag|:test|new|alias|alter|and|apply|assert|class|cond|conj|count|def|defmacro|defn|defstruct|deref|do|doall|dorun|doseq|dosync|eval|filter|finally|find|first|fn|gen-class|gensym|if|import|inc|keys|let|list|loop|map|ns|or|print|println|quote|rand|recur|reduce|ref|repeat|require|rest|send|seq|set|sort|str|struct|sync|take|test|throw|trampoline|try|type|use|var|vec|when|while)\b/gmi
|
||||
},
|
||||
|
||||
keywords: {
|
||||
exp: /(:[a-z][A-Za-z0-9_]*)/g
|
||||
}
|
||||
keyword : {
|
||||
exp : /\[|\]/g
|
||||
},
|
||||
|
||||
symbols : {
|
||||
exp : /'[a-z][A-Za-z0-9_]*/g
|
||||
},
|
||||
|
||||
keywords: {
|
||||
exp: /(:[a-z][A-Za-z0-9_]*)/g
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
CodeHighlighter.addStyle("haskell",{
|
||||
comment : {
|
||||
exp : /(\-\-.*$)|(\{\-[\s\S]*?\-\})/gm
|
||||
},
|
||||
keywords : {
|
||||
exp : /\b(as|case|of|class|data|datafamily|data instance|default|deriving|deriving instance|do|forall|foreign|hiding|if|then|else|import|infix|infixl|infixr|instance|let|in|mdo|module|newtype|proc|qualified|rec|type|type family|type instance|where)\b/
|
||||
},
|
||||
string : {
|
||||
exp : /'[^']*'|"[^"]*"/
|
||||
}
|
||||
comment : {
|
||||
exp : /(\-\-.*$)|(\{\-[\s\S]*?\-\})/gm
|
||||
},
|
||||
keywords : {
|
||||
exp : /\b(as|case|of|class|data|datafamily|data instance|default|deriving|deriving instance|do|forall|foreign|hiding|if|then|else|import|infix|infixl|infixr|instance|let|in|mdo|module|newtype|proc|qualified|rec|type|type family|type instance|where)\b/
|
||||
},
|
||||
string : {
|
||||
exp : /'[^']*'|"[^"]*"/
|
||||
}
|
||||
});
|
||||
Loading…
Reference in a new issue