PluGeSHin

PluGeSHin is a WordPress plugin by Peter Ajtai that lets you use the syntax highlighting of GeSHi through WordPress shortcodes.

Author:Peter Ajtai (profile at wordpress.org)
WordPress version required:2.5
WordPress version tested:3.2.1
Plugin version:2.5
Added to WordPress repository:15-08-2011
Last updated:18-09-2011
Warning! This plugin has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.
Rating, %:0
Rated by:0
Plugin URI:http://netlumination.com/blog/plugeshin
Total downloads:1 068
Active installs:10+
plugin download
Click to start download

PluGeSHin is a WordPress plugin by Peter Ajtai that lets you use the syntax highlighting of GeSHi through WordPress shortcodes.

The format for using PluGeSHin is:

[geshi] CODE TO BE HIGHLIGHTED [/geshi]

Features

  • Use shortcodes in WP-Admin to mark text for syntax higlighting on the front end
  • Use optional attributes in the short codes to control:
    • Language used for highlighting
    • Whether to show line numbers
    • Start line number to use
    • Line marked with an attention grabbing color
    • Target of links to documentation
  • TinyMCE split button:
    • You can wrap your code with the touch of a button in simple [geshi] shortcode without any attributes
    • You can use the PluGeSHin helper to select shortcode attributes and wrap the code with the created shortcode
  • WP-Admin settings page that lets you
    • Set the default language
    • Set whether to show line numbers by default
    • Set the default target for links to documentation
    • Draft a sample test page with the push of a button

Quick Start

  1. Paste code into Visual editor in WP-Admin
  2. Select code with mouse
  3. Hit the G PluGeSHin button
    1. You can also hit the dropdown arrow next to the button
    2. Use the helper to choose your attributes

To see working examples of GeSHi with PluGeSHin visit this page.

PluGeSHin comes with a helpful WP-Admin Settings Page. You can draft a sample Post from that page with the push of a button. The sample page has multiple examples of PluGeSHin shortcodes, so you can both make sure the plugin is working, and so you can look at how the examples were written.

A list of supported languages is shown on the PluGeSHin Settings Page in a dropdown.

PluGeSHin Attributes

PluGeSHin can take one or more attributes, like this:

[geshi attribute="ATTRIBUTE VALUE"] CODE TO BE HIGHLIGHTED [/geshi]

All attributes are optional. Leaving them out will trigger default attributes. The default values for the highlighted language and whether line numbers are shown can be set on the PluGeSHin Settings Page in WP-Admin.

The attributes you can use with PluGeSHin are:

  • lang - is the language used for highlighting. The codes available can be looked up on PluGeSHin's Settings Page from the dropdown.
  • nums - controls whether line numbers are shonw. nums="1" shows line number nums="0" does not.
  • start - controls what the first line number is. You should always have line numbers showing if you set start.
  • highlight - let's you pick the line numbers to draw attention to. It is a comma separated list. The numbers are lines relative to the first one.
  • target - pick the target for anchor element links to documentation

Note that the highlighted code will be wrapped in <pre> tags and the class attribute of the <pre> tags will be PluGeSHin and the name of the highlighted language. This way you can easily use CSS to tweak the styling of your code blocks. You should also wrap the unhighlighted code in <pre> tags. The short tags themselves should not be within <pre> tags.

Here is an example using all four possible attributes

[geshi lang="cpp" start="37" nums="1" highlight="4,13"] 
    CODE TO BE HIGHLIGHTED
[/geshi]

Finally, remember to use Shift+Enter if you're typing code and not pasting it in. You don't have to - PluGeSHin will still work if you don't - but it'll look nicer for you in the Visual edit screen.

Detailed use instructions

Above, in the "Quick Start" section you can read about how to use PluGeSHin with the TinyMCE button. Below are more detailed instructions, in case you want to do things by hand or need to trouble shoot malformed HTML.

The following instructions are for using the Visual editor mode. You can also use the HTML editor mode with PluGeSHin. The important thing to remember is that PluGeSHin can only be responsible for what's between the short codes, so don't wrap the entire short code block in a PRE on the outside!

Steps for using PluGeSHin manually:

  1. Pick Paragraph format from the dropdown.
  2. Hit Alt-Shift-Z if you don't see the Format drop down in the TinyMCE toolbar
  3. Type [geshi]
  4. Hit enter twice
  5. Type [/geshi]
  6. Hit the up arrow once
  7. Pick the Preformatted format.
  8. Type or paste in your code. The Preformat will preserve your indentation.
  9. Save your post and View or Preview it from the front end. The code will now be highlighted.

The code you type or paste in should be preformatted - in <pre> tags. The [geshi] short code tags should not be preformatted.

Stay tuned for

Support of more GeSHi methods. Next ones will probably be the option to show code in a <div> or a <pre> as well as the ability to set header and footer information.

Contact

If you have questions, problems, or general ramblings, correspond with me at spam dot database at gmail dot com.