Plugin Directory

WP-Syntax

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

<pre lang="php">
<div id="foo">
<?php
  function foo() {
    echo "Hello World!\\n";
  }
?>
</div>
</pre>

Example 2: Java, with line numbers

<pre lang="java" line="1">
public class Hello {
  public static void main(String[] args) {
    System.out.println("Hello World!");
  }
}
</pre>

Example 3: Ruby, with line numbers starting at 18

<pre lang="ruby" line="18">
class Example
  def example(arg1)
    return "Hello: " + arg1.to_s
  end
end
</pre>

Supported Languages

The following languages are supported in the lang attribute:

abap, actionscript, actionscript3, ada, apache, applescript, aptsources, asm, asp, autoit, bash, blitzbasic, bnf, boo, c, cmac, caddcl, cadlisp, cil, cfdg, cfm, cobol, cpp-qt, cpp, csharp, css, d, delphi, diff, div, dos, dot, eiffel, fortran, freebasic, genero, gettext, glsl, gml, bnuplot, groovy, haskell, html4strict, idl, ini, inno, io, java, java5, javascript, kixtart, klonec, klonecpp, latex, lisp, lotusformulas, lotusscript, lua, m68k, matlab, mirc, mpasm, mxml, mysql, nsis, objc, ocaml-brief, ocaml, oobas, oracle8, pascal, per, pic16, perl, php-brief, php, plsql, povray, powershell, progress, python, qbasic, rails, reg, robots, ruby, sas, scala, scheme, sdlbasic, smalltalk, smarty, sql, tcl, text, thinbasic, tsql, typoscript, vb, vbnet, verilog, vhdl, visualfoxpro, winbatch, xml, xorg_conf, xpp, z80

(Bold languages just highlight the more popular ones.)

Styling Guidelines

WP-Syntax colors code using the default GeSHi colors. It also uses inline styling to make sure that code highlights still work in RSS feeds. It uses a default wp-syntax.css stylesheet for basic layout. To customize your styling, copy the default wp-content/plugins/wp-syntax/wp-syntax.css to your theme's template directory and modify it. If a file named wp-syntax.css exists in your theme's template directory, this stylesheet is used instead of the default. This allows theme authors to add their own customizations as they see fit.

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:

<?php
add_action('wp_syntax_init_geshi', 'my_custom_geshi_styles');

function my_custom_geshi_styles(&$geshi)
{
    $geshi->set_brackets_style('color: #000;');
    $geshi->set_keyword_group_style(1, 'color: #22f;');
}
?>

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

Release Notes

0.9.1 : Updated to use GeSHi v1.0.8; Improved the FAQ;

0.9 : Added support for anonymous subscribers to use pre tags in their comments allowing for their own colored code snippets [Fernando Briano];

0.8 : Updated to use GeSHi v1.0.7.22 (this normally would be a revision release, but colors changed and there are 9 new languages supported); Added a font-size setting in the default css to thwart complaints about small sizes caused by other default WP themes;

0.7 : Automaticaly included common styles without requiring manual theme customization [Christian Heim]; Added support for adding a custom wp-syntax.css stylesheet to a theme;

0.6.1 : Updated to use GeSHi v1.0.7.21; Updated the WP compatibility version;

0.6 : Support init hook for geshi settings (wp_syntax_init_geshi); (#667) [reedom]

0.5.4 : Updated to use GeSHi v1.0.7.20;

0.5.3 : Fixed styling guideline issue that affected IE 6 [kimuraco];

0.5.2 : Updated to use GeSHi v1.0.7.19;

0.5.1 : Switched geshi directory export to utilize piston instead of svn:externals properties;

0.5 : Added support for single quoted attributes; (#624)

0.4 : Cleanup and documentation for WordPress.org plugin listings;

0.3 : First official public release; Added line number support; Uses GeSHi v1.0.7.18; (#532)

0.2 : Internal release; Adds "before and after" filter support to avoid conflicts with other plugins; (#531)

0.1 : First internal release; Uses GeSHi v1.0.7.16;

Download

FYI

Average Rating

5 stars
4 stars
3 stars
2 stars
1 star
(41 ratings)