Syntax Highlighter
This is a syntax highlighter that I wrote in JavaScript a while back.

Click on the following code to highlight it.
		
function generate() {
	var form = document.forms[0];
	var ta = form.output;
	var url = form.url.value;
	var func = form.func.value;
	var output = '(function() {\n'
		+'\tvar s=document.createElement("script");\n'
		+'\ts.setAttribute("src", "' + url +'");\n'

	+'\tdocument.body.appendChild(s); \n'
	+'\tfunction load() {\n'
	+'\t	try {\n'
	+'\t		'+ func + '\n'
	+'\t	} catch(e){ \n'
	//+'\t		alert(e); \n'
	+'\t		setTimeout(load, 500);\n'
	+'\t	}\n'
	+'\t}\n'
	+'\tload();\n'
	+'})();';

	document.getElementById("output").innerHTML = (new Highlighter()).highlight(output);	
	document.getElementById("outputurl").innerHTML = "javascript:"+(new Highlighter()).highlight(output.replace(/[\n\t]/g,""));	
}

Also, you can turn this into a bookmarklet: Click Here then click on the following code. You can right click on the previous link and bookmark it to have the ability to highlight code on any page.
		
function generate() {
	var form = document.forms[0];
	var ta = form.output;
	var url = form.url.value;
	var func = form.func.value;
	var output = '(function() {\n'
		+'\tvar s=document.createElement("script");\n'
		+'\ts.setAttribute("src", "' + url +'");\n'

	+'\tdocument.body.appendChild(s); \n'
	+'\tfunction load() {\n'
	+'\t	try {\n'
	+'\t		'+ func + '\n'
	+'\t	} catch(e){ \n'
	//+'\t		alert(e); \n'
	+'\t		setTimeout(load, 500);\n'
	+'\t	}\n'
	+'\t}\n'
	+'\tload();\n'
	+'})();';

	document.getElementById("output").innerHTML = (new Highlighter()).highlight(output);	
	document.getElementById("outputurl").innerHTML = "javascript:"+(new Highlighter()).highlight(output.replace(/[\n\t]/g,""));	
}

This doesn't work so well with highlighting .js files or .cpp files. So, to deal with that, save this bookmarklet instead. Bookmark this link. Then click here to view the source code for the highlighter. Then, click the bookmark you just added.

Download


Tags

javascriptccpp
[ Back to projects ]
Add Comment box