Beautifier
Questions answered by this recipe
Can I use PmWiki to perform syntax highlighting for source code displayed on wiki pages?
Answer
Yes, the beautifier.tgzΔ script integrates Mike Jewell's Beautifier (http://www.beautifier.org -- site now defunct) into PmWiki and adds custom markup for source code blocks.
- (Beautifer website gone as of 2007-08-20)FWIW, it's still available at Sourceforge
Notes
This version of Beautifier requires PmWiki 2 or later. It's based on the beautifier recipe that was developed for PmWiki 0.6 by Jason Perkins. Once installed, it adds markup of the form
=lang [=
lang source code
=]
where lang is any of the supported beautifiers.
Installation
Start by downloading and unpacking beautifier.tgzΔ to the cookbook/beautifier/ directory. This default package provides support for C++, C#, JavaScript, Lua, Perl, PHP, Python, VB.NET, and XML (sort of). If you want support for other languages, you can grab more HFiles for the Beautifier from Koders or download all the available HFiles from SourceForge (the original site is dead). While you're there, give some props to Mike for making this excellent tool available.
In your local/config.php file, you must include the beautifier.php script and register any languages you want to use. The following would register all of the language beautifiers distributed with the script:
include_once('cookbook/beautifier/beautifier.php'); register_beautifier('cpp'); register_beautifier('csharp'); register_beautifier('javascript'); register_beautifier('lua'); register_beautifier('php3'); register_beautifier('python'); register_beautifier('vbdotnet'); register_beautifier('xml');
For more control over the appearance of the formatted code, you may wish to set $BeautifierOutputType='css', which will use Beautifier's CSS writer instead of the default HTML. You'll want to create your own CSS entries to support the highlighting.
Markup
To enter source code into PmWiki, use the following markup:
=csharp [=
// C# source code goes here
=]
Replace "csharp" with the appropriate language identifier (php3, vbdotnet, etc.) This page has the beautifier enabled for php3, csharp, and css, so you can play with it in the sandbox below.
The formatted output of Beautifier is placed into a <pre class="sourcecode"></pre> tag, so you can tweak the appearance of the block in a stylesheet. Here's a nice one:
.sourcecode { background-color: #eef; border: #666 1px solid; padding: 1em; }
See Also
- Cookbook /
- Ape Embed videos, maps, documents, and more in wiki pages (Stable)
- CodeMirror An enhanced page editor for PmWiki (Stable)
- Gists Markup to allow easy embedding of syntax-highlighted github gists (active)
- PITS The PmWiki Issue Tracking System (Beta)
- PmPygment Display code highlighting using Python pygment (Stable)
- Precode General utility block markup for displaying codes with syntax highlighting (Active/Stable)
- SourceBlock Source code syntax highlighter for PmWiki 2.x using GeSHi (Stable)
- Syntaxlove Syntax highlighting with good look and cool JavaScript-effects
- ZCode Extract and highlight source code files from 7z, TAR, ZIP, or RAR archives (Experimental)
- Beautifier - the main Beautifier web site
- Sourceforge
Contributors
- Jason Perkins
- PedroRabinovitch (not much really, just corrected a typo at the replacement pattern. I'll add more soon)
- Pm - revised for PmWiki 2.0, 2004-12-02
Comments
See discussion at Beautifier-Talk