WordPress代码高亮插件WP-Syntax

下载地址: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.

发表评论

电子邮件地址不会被公开。 必填项已用*标注