Google provides many tools to aid web development. One such tool for code snippet beautification is known as google-code-prettify or prettify. It provides basic syntax highlighting for code in various languages including:
bash, c, cc, c++, c#, c shell, CycL, cv, htm, html, java, javascript, matlab, mxml, perl, pl, pm, python, ruby, shell, xhtml, xml, xslt
Usage
Add the css and javascript to the document, preferably in the footer to help load times:
1 2 |
<link href="prettify.css" type="text/css" rel="stylesheet" /> <script type="text/javascript" src="prettify.js"></script> |
Run the javascript in the HTML. Google suggest doing this with onload in the bodytag:
1 |
<body onload="prettyPrint()"> |
Include a prettyprint class either as a prepending pre tag or within the code tag itself:
1 |
class="prettyprint" |