Code Hightlights at Smarty Site

From: Date: Wed, 09 Apr 2003 23:10:34 +0000
Subject: Code Hightlights at Smarty Site
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-9201@lists.php.net to get a copy of this message
Not so long ago I was wondering if anyone knew how all the code published in the smarty wiki was processed to show up with line numbers and nicely formatted. Well, as noone replied, I swept my tears away and wrote the modifier myself, was worth onle 30 minutes of work and produces amazing results. Feel free to use the code below. /** * parseCode() - Smarty Modifier - will create a nice table of * all the <code> data in the passed string. * * @param $string (string) * @return */ function parseCode($string){ return preg_replace_callback("/<code>(.*?)<\/code>/si",_makeCode,$string); } /** * _makeCode() - callback from parseCode(); * * @param $matches * @return */ function _makeCode($matches){ $lines = explode("\n",trim($matches[1])); if(count($lines) < 2){ $lines = explode("<br>",trim($matches[1])); } $toReturn = "<table cellspacing=1 align=center>"; $counter = 1; foreach($lines as $line){ $line = ereg_replace("[\t]","&nbsp;&nbsp;",$line); $toReturn .= "<tr bgcolor=#eeeeee><td align=right><code><font color=#009900>$counter.</font></code></td><td><code>&nbsp;$line&nbsp;</code></td></tr>"; $counter++; } $toReturn .= "</table><br>"; return $toReturn; } -- .::....::.:...::...:..:.:::..:..::..::.::..:.:.

« previous php.smarty.general (#9201) next »