自动语法高亮 google-code-prettify

转自:http://www.21andy.com/blog/20100920/1955.html

地址:http://code.google.com/p/google-code-prettify/

特点是无须指定语言!

安装使用

1、在你的文件中包含这儿的脚本和样式表(你要保证这儿的 css 和 js 文件按在你的服务器上, 并且调整在 scriptlink标签中的路径)

2、添加onload="prettyPrint()" 到你的文件的 body 标签中.

3、修改样式表,使用你自己喜欢的颜色. Continue reading “自动语法高亮 google-code-prettify”

WordPress代码高亮插件WP-Syntax[转]

给自己的BLOG加上了代码的语法高亮这插件,对比了好几个类似的插件,觉得这个还是不错的,并且还加上了CSS显示更好看些了,现在转载记录下,以备切换之用。另外注意的事不要设置line为1 即为显示行号,因为我的首页的摘要会出现问题。

下载地址:http://wordpress.org/extend/plugins/wp-syntax/

安装

  1. Upload wp-syntax.zip to your WordPress plugins directory, usually wp-content/plugins/ and unzip the file. It will create a wp-content/plugins/wp-syntax/ directory.
  2. Activate the plugin through the ‘Plugins’ menu in WordPress.
  3. Create a post/page that contains a code snippet following the proper usage syntax.

写文章时,用 <pre> 和 </pre> 将代码包住即可。同时在<pre> 中指定参数 lang=”代码类型” ling=”起始行数”。
最后在使用的过程中注意 lang=”” 一定要使用双引号,而不能用单引号。

Usage(使用方法)

Wrap code blocks with <pre lang=”LANGUAGE” line=”1″> and </pre> where LANGUAGE is a GeSHi supported language syntax. See below for a full list of supported languages. The line attribute is optional.

Example 1: PHP, no line numbers

Example 2: Java, with line numbers

Example 3: Ruby, with line numbers starting at 18

Supported Languages(支持的语言)

The following languages are supported in the lang attribute:

abap, actionscript, ada, apache, applescript, asm, asp, autoit, bash, blitzbasic, bnf, c, c_mac, caddcl, cadlisp, cfdg, cfm, cpp-qt, cpp, csharp, css, d, delphi, diff, div, dos, dot, eiffel, fortran, freebasic, genero, gml, groovy, haskell, html4strict, idl, ini, inno, io, java, java5, javascript, latex, lisp, lua, m68k, matlab, mirc, mpasm, mysql, nsis, objc, ocaml-brief, ocaml, oobas, oracle8, pascal, per, perl, php-brief, php, plsql, python, qbasic, rails, reg, robots, ruby, sas, scheme, sdlbasic, smalltalk, smarty, sql, tcl, text, thinbasic, tsql, vb, vbnet, vhdl, visualfoxpro, winbatch, xml, xpp, z80

(Bold languages just highlight the more popular ones.)

Styling Guidelines

WP-Syntax uses default GeSHi colors by default. It also uses inline styling to make sure that code highlights still work in RSS feeds. To spruce up your code snippets to look more like the screenshots, try adding this CSS to your stylesheet template:
WP-Syntax 能够保留代码中的缩进(空格),让代码更加美观。不过,WP-Syntax高亮的代码默认不会进行拆行,如果代码过长的话,将会导致页面被撑大,影响美观。将如下 CSS 样式写入到所选择的主题样式中,能够解决这个问题:

 

Advanced Customization

WP-Syntax supports a wp_syntax_init_geshi action hook to customize GeSHi initialization settings. Blog owners can handle the hook in a hand-made plugin or somewhere else like this:

This allows for a great possibility of different customizations. Be sure to review the GeSHi Documentation.

转自:http://www.ohlinux.com/?p=188