[Pieforms-commit] SF.net SVN: pieforms: [198] pieforms-php5/branches/0.2.0/doc/highlighter. php
Status: Alpha
Brought to you by:
oracleshinoda
From: <ora...@us...> - 2007-03-18 13:32:50
|
Revision: 198 http://svn.sourceforge.net/pieforms/?rev=198&view=rev Author: oracleshinoda Date: 2007-03-18 02:04:23 -0700 (Sun, 18 Mar 2007) Log Message: ----------- Added PHP bridge script that highlights code snippets Added Paths: ----------- pieforms-php5/branches/0.2.0/doc/highlighter.php Added: pieforms-php5/branches/0.2.0/doc/highlighter.php =================================================================== --- pieforms-php5/branches/0.2.0/doc/highlighter.php (rev 0) +++ pieforms-php5/branches/0.2.0/doc/highlighter.php 2007-03-18 09:04:23 UTC (rev 198) @@ -0,0 +1,38 @@ +<?php +/** + * Highlights the given source using GeSHi + */ + +if (!isset($argv[1])) { + die('oops: no source passed!'); +} +$source = $argv[1]; +if (!isset($argv[2])) { + die('oops: no language passed!'); +} +$language = $argv[2]; + +// Remove the two leading lines +$source = substr($source, strpos($source, "\n") + 1); +$source = trim($source); + +$phphack = false; +if (substr($language, 0, 3) == 'php' && substr($source, 0, 5) != '<?php') { + $phphack = true; + $source = '<?php' . $source . '?>'; +} + +$source = preg_replace('/^ /m', '', $source); + +require_once('geshi/class.geshi.php'); +$geshi = new GeSHi($source, $language); +$result = $geshi->parseCode(); + +if ($phphack) { + $result = preg_replace('/<span[^>]*><\?php<\/span>/', '', $result); + $result = preg_replace('/<span[^>]*>\?><\/span>/', '', $result); +} + +echo $result; + +?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |