From: Martin G. <gim...@gi...> - 2002-11-03 23:32:38
|
Hi everybody! I have a tutorial on PHP at my WikiWikiWeb, so I wrote a WikiPlugin, that will highlight some PHP code using highlight_string(). It can be seen in action here: http://www.gimpster.com/phpwiki/index.php/PhpTutorial/PrinterFriendly (This page demonstrates a problem with the IncludePage plugin and subpages: a relative link like /Intro on PhpTutorial is interpreted as a relative link from PhpTutorial/PrinterFriendly when PhpTutorial is seen through IncludePage on PhpTutorial/PrinterFriendly.) The code for the plugin is very simple: /** * A plugin that runs the highlight_string() function in PHP on it's * arguments to pretty-print PHP code. * * Usage: * <?plugin PhpHighlight * code that should be highlighted * ?> * * You should not add '<?php' and '?>' to the code - the plugin does * this automatically. * * Author: Martin Geisler <gim...@gi...>. */ class WikiPlugin_PhpHighlight extends WikiPlugin { // Four required functions in a WikiPlugin. function getName () { return _("PhpHighlight"); } function getDescription () { return _("PHP syntax highlighting"); } // Establish default values for each of this plugin's arguments. function getDefaultArguments() { return array(); } function run($dbi, $argstr, $request) { $str = highlight_string("<?php\n" . $argstr . "\n?>", true); /* Remove "<?php\n" and "\n?>": */ $str = str_replace(array('<?php<br />', '?>'), '', $str); /* We might have made some empty font tags: */ $search = '<font color="' . ini_get('highlight.default') . '"></font>'; $str = str_replace($search, '', $str); return new RawXml($str); } }; -- Martin Geisler My GnuPG Key: 0xF7F6B57B See http://gimpster.com/ and http://phpweather.net/ for: PHP Weather => Shows the current weather on your webpage and PHP Shell => A telnet-connection (almost :-) in a PHP page. |