|
Beautifier<< Date Time Stamp | Cookbook-V1 | Group List >> Note: The recipes here are for PmWiki versions 0.6 and 1.0 only. For PmWiki 2.0 recipes, see Cookbook.
GoalProvide syntax highlighting for source code displayed on wiki pages. SolutionIntegrate Mike Jewell's Beautifier into PmWiki, add custom markup for source code blocks. DiscussionThis version of Beautifier requires PmWiki 0.6.1 or later. You can still find the previous versions here, but they are no longer supported (and really, why wouldn't you run 0.6? It rocks!). The markup has changed in this version, but installation has become drastically simpler. Thanks to Pm for the help. --Profiles/JasonPerkins Changes in this version
InstallationStart by downloading and unpacking the add-on file to your In include_once('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');
If you are hosting your wiki with Microsoft IIS, you should also add the line error_reporting(E_ALL ^ E_NOTICE); otherwise the Beautifier code will spit out some warning messages that will mess up your pages. 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. If so, you'll need to specify the code styles in your own stylesheet. The following is an example: .code-comment { color: green; }
.code-quote { color: gray; }
.code-type1 { color: blue; } /* keywords */
.code-type2 { color: blue; } /* data types */
.code-type3 { color: maroon; } /* preprocessor */
MarkupTo 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.) The formatted source code will be 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;
}
You can see this addon in action at http://premake.sourceforge.net/PremakeWiki/Snippets. See Also
Contributors
Are there any plans to port this very useful recipe to PmWiki 2? Thanks Already done -- see Cookbook.Beautifier. --Pm
pmwiki-2.2.36 -- Last modified by {{Pm}}
|