Google Code Prettify 页面语法高亮JS库

开发 后端
Google Code Pretiffy 是 Google 的一个用来对代码进行语法着色的 JavaScript 库,支持 C/C++, Java, Python, Ruby, PHP, VisualBasic, AWK, Bash, SQL, HTML, XML, CSS, JavaScript, Makefiles和部分Perl。

Google Code Pretiffy 是 Google 的一个用来对代码进行语法着色的 JavaScript 库,支持 C/C++, Java, Python, Ruby, PHP, VisualBasic, AWK, Bash, SQL, HTML, XML, CSS, JavaScript, Makefiles和部分Perl。

  1. package foo;  
  2.  
  3. import java.util.Iterator;  
  4.  
  5. /**  
  6.  * the fibonacci series implemented as an Iterable.  
  7.  */ 
  8. public final class Fibonacci implements Iterable<Integer> {  
  9.   /** the next and previous members of the series. */ 
  10.   private int a = 1, b = 1;  
  11.  
  12.   @Override 
  13.   public Iterator<Integer> iterator() {  
  14.     return new Iterator<Integer>() {  
  15.       /** the series is infinite. */ 
  16.       public boolean hasNext() { return true; }  
  17.       public Integer next() {  
  18.         int tmp = a;  
  19.         a += b;  
  20.         b = tmp;  
  21.         return a;  
  22.       }  
  23.       public void remove() { throw new UnsupportedOperationException(); }  
  24.     };  
  25.   }  
  26.  
  27.   /**  
  28.    * the n<sup>th</sup> element of the given series.  
  29.    * @throws NoSuchElementException if there are less than n elements in the  
  30.    *   given Iterable's {@link Iterable#iterator iterator}.  
  31.    */ 
  32.   public static <T>  
  33.   T nth(int n, Iterable<T> iterable) {  
  34.     Iterator<? extends T> it = iterable.iterator();  
  35.     while (--n > 0) {  
  36.       it.next();  
  37.     }  
  38.     return it.next();  
  39.   }  
  40.  
  41.   public static void main(String[] args) {  
  42.     System.out.print(nth(10new Fibonacci()));  
  43.   }  

更多演示:http://google-code-prettify.googlecode.com/svn/trunk/tests/prettify_test.html

下载地址:http://code.google.com/p/google-code-prettify/downloads/list

责任编辑:林师授 来源: 51CTO
相关推荐

2012-05-22 01:49:22

Highlight.jJavaWEB

2012-05-22 01:45:58

JavaScriptCSSXML

2011-08-05 09:45:30

Google CodeGit

2009-06-09 21:59:13

语法高亮Javascript

2019-11-18 08:41:09

JavaScript编程语言浏览器

2010-02-23 17:42:29

Ubuntu vim

2009-09-03 15:11:18

RHEL5vi高亮

2013-09-09 09:50:27

代码语法工具

2013-05-24 11:14:01

谷歌代码

2014-03-14 10:56:59

语法高亮代码高亮

2023-05-31 11:38:45

GPTIDE代码

2011-10-08 13:45:12

JavaScript

2009-08-18 10:17:44

Google Code

2009-03-24 14:25:14

LinuxGoogleSummer of C

2013-03-19 11:13:14

Google广告SXSW

2023-07-30 22:25:00

JavaScrip服务端Web

2011-10-08 13:22:43

Google数据库云计算

2020-12-15 10:24:05

2020-08-06 10:50:06

开源BAT命令

2012-08-23 10:30:09

JavaScript
点赞
收藏

51CTO技术栈公众号