From b99ae1000c31cabc8621b24ebedd64ed4ad67267 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Mon, 25 Feb 2013 19:27:23 +0100 Subject: automatically wrap lines Signed-off-by: Florian Pritz --- application/controllers/file.php | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'application/controllers/file.php') diff --git a/application/controllers/file.php b/application/controllers/file.php index 333602fbf..5bd829713 100644 --- a/application/controllers/file.php +++ b/application/controllers/file.php @@ -203,19 +203,43 @@ class File extends CI_Controller { private function _pygmentize($file, $lexer) { $return_value = 0; + $output = ""; - ob_start(); + $output .= '
'."\n"; + $output .= '
'."\n";
 
-		echo '';
-		echo '
';
-		// generate line numbers (links)
-		passthru('perl -ne \'print " $.\n"\' '.escapeshellarg($file), $return_value);
-		echo '
'."\n"; + ob_start(); passthru('pygmentize -F codetagify -O encoding=guess,outencoding=utf8 -l '.escapeshellarg($lexer).' -f html '.escapeshellarg($file), $return_value); - - $output = ob_get_contents(); + $buf = ob_get_contents(); ob_end_clean(); + + $buf = explode("\n", $buf); + $line_count = count($buf); + + // Last 2 items are just "" and "" + // We don't need those + unset($buf[$line_count - 2]); + unset($buf[$line_count - 1]); + + foreach ($buf as $key => $line) { + $line_number = $key + 1; + if ($key == 0) { + $line = str_replace("
", "", $line);
+			}
+
+			// Be careful not to add superflous whitespace here (we are in a 
)
+			$output .= "
" + ."" + ." " + ."" + ."".$line."\n"; + $output .= "
"; + } + + $output .= "
"; + $output .= ""; + return array( "return_value" => $return_value, "output" => $output -- cgit v1.2.3-24-g4f1b