代码加亮–Code highlight[适合Drupal,WordPress等系统]

Categories: Development Notes; Tagged with: ; @ August 27th, 2008 16:32

Drupal演示:点此
下面是Java代码高亮:

public void doFilter(ServletRequest req, ServletResponse resp,
      FilterChain filterChain) throws IOException, ServletException {
   String uri = null;
   try {
      uri = ((HttpServletRequest)req).getRequestURI();
      tracer.startThreadInfoCapture(CPU + BLOCK + WAIT);
      // ===================================
      //   This is the target.
      // ===================================
      filterChain.doFilter(req, resp);
      // ===================================
   } catch (Exception e) {
   } finally {
      tracer.endThreadInfoCapture("Servlets", getClass().getName(), uri);
   }
}

使用方法:

在这里下载最新版
http://code.google.com/p/syntaxhighlighter/downloads/list/
在usage中有介绍使用发放,怕各位英语跟我一样不好,简单说下使用方法:
1.解压缩,上传到你网站某目录中.[注意看目录,实际结构跟usage中介绍的不一样]
2.将js的引用加到到Head中:注意路径要正确!我这里是使用了java,js,xml跟core的.你可以根据你的需要选择使用.最下面的一个js是用来操作代码上发的几个功能的,如新窗口查看,复制到粘贴板,打印等.目录一定要正确.

<link type=”text/css” rel=”stylesheet” href=”/dp.SyntaxHighlighter/Styles/SyntaxHighlighter.css”></link>
<script language=”javascript” src=”/dp.SyntaxHighlighter/Scripts/shCore.js”></script>
<script language=”javascript” src=”/dp.SyntaxHighlighter/Scripts/shBrushJava.js”></script>
<script language=”javascript” src=”/dp.SyntaxHighlighter/Scripts/shBrushJScript.js”></script>
<script language=”javascript” src=”/dp.SyntaxHighlighter/Scripts/shBrushXml.js”></script>
<script language=”javascript”>
window.onload = function () {
dp.SyntaxHighlighter.ClipboardSwf = ‘/dp.SyntaxHighlighter/Scripts/clipboard.swf’;
dp.SyntaxHighlighter.HighlightAll(‘code’);
}
</script>
至此就配置好了.
使用方法:
在写博客时,把代码放到标签中间
<pre name=”code” class=”java/js/xml”>代码….</pre>[class中写入对应语言]

手动加入标签

注意LiveWriter需在Code模式下手写.

Drupal演示:http://riashanghai.com

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.