Results 1 to 1 of 1
Thread: In Case You Want Colors!
- 08-29-2009, 10:06 PM #1
In Case You Want Colors!

--Fancy Code Tag--
This javascript adds syntax highlighting, line numbers, and replaces tab with spaces in the [code] tags found on forums. Its been tested on Opera 9 and Firefox.
To Use: just copy and paste the below code into the URL of the web browser. Then you can bookmark this url and call on it as a bookmarklet, or use it with Opera or Greesemonkey
* Above code does not work on IE6 because it's too long.Java Code:javascript:TW=['public','private','protected','class','interface','abstract','static','final','void','package','byte','short','int','long','float','char','double','boolean','const','enum','native','synchronized','strictfp','volatile','transient'];IW=['import','new','return','null','instanceof','break','continue','if','else','do','while','for','switch','case','default','true','false','try','catch','finally','throws','throw','assert','extends','implements','super','this','goto'];CW=['Object','String','System','Byte','Integer','Character','Long','Double','Float','Short','Logger','Exception','IOException','JApplet','Applet','toString'];function pct(o,rt,ln){t=document.body.getElementsByTagName(o.t);for(i=0;i<t.length;++i){p=eval("/^"+o.v+"$/g");if(p.test(t[i][o.a])){c=tok(t[i].innerHTML,ln);if(rt)c=c.replace(/\t/g," ");if(ln)c=ar(c);t[i].innerHTML=c;}}}function ar(d){return('<ol><li><tt>'+d.replace(/\r?\n|<br ?\/?>/gim,' <\/tt><\/li><li><tt>')+'<\/tt><\/li><\/ol>');}function tok(e,ln){hl=/^<\/?[^>]+>$/i;cl=/^\/\/.*\r?\n$/;cb=/^\/\*(?:.|[\n\r])*?\*\/$/;cd=/^\/\*\*(?:.|[\n\r])*?\*\/$/;cs=/^["'](?:.|\r?\n)*["']/;nl=/^\d+\.?\d*\w?$/i;w=/^\w+$/;an=/^@\w+$/;pa=/<\/?[^>]+>|\/\*(?:.|[\n\r])*?\*\/|["](?:\\["]|\\\r?\n|[^"\n])*["]|'(?:\\'|\\\r?\n|[^'\n])*'|\/\/.*\r?\n|\d+\.?\d*\w?|@\w+|\s+|\w+|\W/gim;var arr,ret="";if(ln)arr=e.replace(/<br ?\/?>/gim,'\r\n').match(pa);else arr=e.match(pa);for(var i=0;i<arr.length;i++){tk=arr[i];if(hl.test(tk))ret+=tk;else if(an.test(tk))ret+='<font color="gray"><b>'+tk+'<\/b><\/font>';else if(cs.test(tk)){pre='<font color="gray">';suf='<\/font>';if(/^'/.test(tk)){pre='<font color="gray"><b>';suf='<\/b><\/font>';}if(ln)tk=tk.replace(/\r?\n/g,suf+'\r\n'+pre);ret+=pre+tk+suf;}else if(nl.test(tk))ret+='<font color="orange"><b>'+tk+'<\/b><\/font>';else if(cb.test(tk)){co='"green" style="font-style:italic;"';if(cd.test(tk))co='"teal"';if(ln)tk=tk.replace(/\r?\n/g,'<\/font>\r\n<font color='+co+'>');ret+='<font color='+co+'>'+tk+'<\/font>';}else if(cl.test(tk))ret+='<font color="green">'+tk.replace(/\r?\n$/,'<\/font>\r\n');else if(w.test(tk))ret+=pk(tk);else ret+=tk;}return ret;}function pk(tk){x=eval("/^"+tk+"$/");var i;for(i=0;i<TW.length;++i)if(x.test(TW[i]))return'<font color="purple">'+tk+'<\/font>';for(i=0;i<IW.length;++i)if(x.test(IW[i]))return'<font color="blue"><b>'+tk+'<\/b><\/font>';for(i=0;i<CW.length;++i)if(x.test(CW[i]))return'<font color="purple">'+tk+'<\/font>';return tk;}pct({t:"pre",a:"dir",v:"ltr"},true,true);
Attached is the script you can use with Opera or Greesemonkey.
-- Fancy Code Tag For Java
attachment moved to userscripts.org
Enjoy.
Let me know if you find any errors...Last edited by angryboy; 09-02-2009 at 07:33 PM. Reason: updated, code tags
USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
Similar Threads
-
Rectangle and Colors
By urbim in forum Java AppletsReplies: 0Last Post: 07-11-2009, 03:03 PM -
Textpad colors, lost?
By Torgero in forum New To JavaReplies: 0Last Post: 01-15-2009, 08:12 PM -
Colors and shapes.
By Torgero in forum New To JavaReplies: 14Last Post: 10-13-2008, 05:25 PM -
change colors
By calblue in forum New To JavaReplies: 1Last Post: 12-02-2007, 11:52 PM -
how to set multiple colors in a JtextArea
By valery in forum AWT / SwingReplies: 2Last Post: 08-01-2007, 05:12 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks