Google Code Pretiffy 代碼 着色 高亮 開源 javascript(JS)庫

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/

3.http://www.hujuntao.com/web/javascript/google-code-pretiffy-lightweight-code-highlighting-plugin.html

相關文章
相關標籤/搜索