January 6, 2009, Tuesday, 5

WordPress:CodeHighlighterPlugin

From IdeA thinKING

Jump to: navigation, search

Contents

Overview

This plugin is a syntax highlighter for source code. It uses GeSHi as fontifier engine.

Requirements

  • Wordpress 2.x.
  • Compatible with all web servers including Apache and IIS.

Download

Installation

To install the plugin:

  1. Unzip the plugin archive.
  2. Upload the directory to the /wp-content/plugins/ directory
  3. Activate the plugin through the 'Plugins' menu in WordPress

Usage

  1. Put the code snippet to pre tag.
  2. Add the lang attribute to the pre tag like the following.
    • <pre lang="cpp">
  3. Add the lineno attribute to the pre tag after the lang tag like the following if you want to display line numbers. The number in the lineno tag becomes a start line number. There is no default value for the start line number. So you must supply the value to the lineno tag.
    • <pre lang="cpp" lineno="1">
  4. If you do not add lang attribute, the pre tag is handled normally.
  5. If you want to have border, add the style like the following to your .css file.
    • pre { border: 1px dotted #ccc; padding: 0.2em 0.5em; }
  6. You can use following languages in lang.
    • abap, actionscript, ada, apache, applescript, asm, asp, autoit, bash, blitzbasic, bnf, c, c_mac, caddcl, cadlisp, cfdg, cfm, cpp-qt, cpp, csharp, css-gen, 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

Screenshots

Known issues

  1. Because this plugin uses regular expression to match string range from '<pre lang="some">' to '</pre>', you can't use '</pre>' in your code snippet. If you must put the '</pre>' tag, you can put a space between '<' and '/pre> like '< /pre>'. The '< /pre>' is converted to '</pre>' automatically by plugin.
  2. If you want to change the style, you should modify the plugin source file. (codehighlighter.php)

Contact

You can leave a comment at CodeHighlighter plugin test page .

License

Copyright (C) 2008 Wongoo Lee

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Version history

  1. 1.8 Mar 9 2008
    • Upgrade GeSHi version to 1.0.7.20.
  2. 1.7 Mar 17 2007
    • Remove two WP filters; wptexturize and convert_chars. This helps making code concise.
  3. 1.6 Mar 7 2007
    • Fix a bug that plus signs are not shown.
  4. 1.5 Mar 5 2007
    • Add an option to display line numbers with 'lineno="startline"'.
    • Handle'</pre>' tag in the code snippet with '< /pre>'.
  5. 1.4 Mar 1 2007
    • Polish the regular expression of plugin to support html better.
  6. 1.3 Feb 8 2007
    • Handle WP's character conversion before highlighting.
    • Upgrade GeSHi to 1.0.7.17.
  7. 1.2 Jan 5 2007
    • Drop the 'em' feature.
    • Upgrade GeSHi to 1.0.7.16.
  8. 1.0 May 24 2006
    • Initial release

Reference

iwongu 15:15, 5 January 2007 (KST)