pretty print - How to format code in html / css / js/ php -


i'm looking way automatically format , color code write in html document. know wikipedia it, example on page: http://en.wikipedia.org/wiki/nested_function

i'm sure there libraries out there this, can't life of me, find one. have suggestions?

have @ prettify javascript library. it's 1 used people (it's 1 being used here on so, example.)

you use this:

in <head> element:

<link href="prettify.css" type="text/css" rel="stylesheet" /> <script type="text/javascript" src="prettify.js"></script> 

in <body> element:

<body onload="prettyprint()">   <!-- html here... -->   <pre class="prettyprint"> def say_hi():     print("hello world!")   </pre>   <!-- html here... --> </body> 

that's simple use of library. if you're using other javascript on page recommend other methods enabling prettify library (i.e., don't use onload attribute of <body> element.) example, if you're using jquery, wrote jquery plugin use syntax highlight elements:

// extend jquery functionality support prettify prettify() method. jquery.fn.prettify = function () { this.html(prettyprintone(this.html())); }; 

used this:

$('#my-code-element').prettify();