From 923e38b9fd6b04b871125b3feecbc62a4204a464 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Thu, 22 Aug 2013 19:40:38 +0200 Subject: Remove empty line after ansi2html Signed-off-by: Florian Pritz --- application/controllers/file.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'application/controllers') diff --git a/application/controllers/file.php b/application/controllers/file.php index 25e283e4b..ef2e87084 100644 --- a/application/controllers/file.php +++ b/application/controllers/file.php @@ -173,6 +173,7 @@ class File extends MY_Controller { { $return_value = 0; $output = ""; + $lines_to_remove = 0; $output .= '
'."\n"; $output .= '
'."\n";
@@ -180,8 +181,12 @@ class File extends MY_Controller {
 		ob_start();
 		if ($lexer == "ascii") {
 			passthru('ansi2html -p < '.escapeshellarg($file), $return_value);
+			// Last line is empty
+			$lines_to_remove = 1;
 		} else {
 			passthru('pygmentize -F codetagify -O encoding=guess,outencoding=utf8,stripnl=False -l '.escapeshellarg($lexer).' -f html '.escapeshellarg($file), $return_value);
+			// Last 2 items are "
" and "" + $lines_to_remove = 2; } $buf = ob_get_contents(); ob_end_clean(); @@ -190,10 +195,9 @@ class File extends MY_Controller { $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]); + for ($i = 1; $i <= $lines_to_remove; $i++) { + unset($buf[$line_count - $i]); + } foreach ($buf as $key => $line) { $line_number = $key + 1; -- cgit v1.2.3-24-g4f1b