1.简介 introductionjavascript
Google Code Pretiffy 是 Google 的一个用来对代码进行语法着色的 JavaScript 库,支持 C/C++, Java, Python, Ruby, PHP, VisualBasic, AWK, Bash, SQL, HTML, XML, CSS, JavaScript, Makefiles和部分Perl。css
code.google.com、stackoverflow.com、api.jquery.com等知名网站都在使用它。html
2.官方示例 DEMOjava
见http://google-code-prettify.googlecode.com/svn/trunk/tests/prettify_test.htmljquery
以下图所示,为在网页上进行c语言代码着色后的效果:web
3.特色 features listapi
工做基于前台页面 即便代码中包含行号、连接等等,也可运行。 简单的API :只需加载一点JS和CSS,以及添加一个onLoad事件。 轻量级:绝对的小体积并不会阻碍加载页面。 可经过CSS定制样式。 经过CSS定制的样式。主题库 支持全部的C类语言,Bash类语言,XML类语言。无需指定语言。 其它可扩展语言,你能够经过指定语言来支持。 良好的跨浏览器支持。
4.安装方法 installation浏览器
一、在你的网页上加载JS和CSS文件bash
<link href="prettify.css" type="text/css" rel="stylesheet" /> <script type="text/javascript" src="prettify.js"></script>
二、而后在html 的body标签中添加一个onload事件 onload=”prettyPrint()”svn
若是你加载了JQuery,则能够添加如下代码
$(document).ready(function(){ prettyPrint(); })
到这里,你的google-code-prettify基本能够工做了。
5.使用方法 usage
你只须要把代码放进
<pre>...</pre> 或者 <code>...</code>
就能够实行代码高亮了。
无需你指定哪一种语言就能够工做了。固然,你也能够指定一种语言,
<pre class=”prettyprint Language”>,
将language 改成如下的一种语言:“bash”, “c”, “cc”, “cpp”, “cs”, “csh”, “cyc”, “cv”, “htm”, “html”, ”java”, “js”, “m”, “mxml”, “perl”, “pl”, “pm”, “py”, “rb”, “sh”, ”xhtml”, “xml”, “xsl”。
6.参考 reference
1.google-code-prettify使用手册:http://google-code-prettify.googlecode.com/svn/trunk/README.html
2.google-code-prettify主页:http://code.google.com/p/google-code-prettify/