Derek Gathright![]()
A JavaScript module and CSS file that allows syntax highlighting of source code snippets in an html page.
Features
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="http://yui.yahooapis.com/3.4.0/build/yui/yui.js"></script>
<script type="text/javascript">
// Note, because of licensing restrictions, this module is not hosted on YUI's CDN.
// You should host this JS script and the CSS file (below) from your own domain.
YUI({
modules: {
'gallery-prettify': {
fullpath: 'https://raw.github.com/derek/yui3-gallery/master/src/gallery-prettify/js/prettify.js',
requires: ['gallery-prettify-css-sam']
},
'gallery-prettify-css-sam': {
fullpath: 'http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css'
},
'gallery-prettify-css-night': {
fullpath: 'http://google-code-prettify.googlecode.com/svn/trunk/styles/sunburst.css'
}
}
}).use('gallery-prettify', function(Y) {
// It's loaded, now make everything pretty!
Y.prettyPrint();
});​
</script>
</head>
<body>
<h1>Javascript</h1>
<pre class="prettyprint">
/**
* nth element in the fibonacci series.
* @param n >= 0
* @return the nth element, >= 0.
*/
function fib(n) {
var a = 1, b = 1;
var tmp;
while (--n >= 0) {
tmp = a;
a += b;
b = tmp;
}
return a;
}
document.write(fib(10));
</pre>
</body>
</html>
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info