From 06ce8d971b1dfd7a520c1c2e4933d84f3e4c80d0 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Wed, 22 Mar 2017 16:34:15 +0100 Subject: Pass file content to lexer via stdin This allows to easily modify the content before rendering it. Signed-off-by: Florian Pritz --- application/controllers/file/file_default.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/application/controllers/file/file_default.php b/application/controllers/file/file_default.php index 086d3ebfe..28d83282e 100644 --- a/application/controllers/file/file_default.php +++ b/application/controllers/file/file_default.php @@ -250,17 +250,20 @@ class File_default extends MY_Controller { $output .= '
'."\n"; $output .= '
'."\n"; + $content = file_get_contents($file); + if ($lexer == "ascii") { // TODO: use exec safe and catch exception $ret = (new \libraries\ProcRunner(array('ansi2html', '-p'))) - ->input(file_get_contents($file)) + ->input($content) ->forbid_stderr() ->exec(); // Last line is empty $lines_to_remove = 1; } else { // TODO: use exec safe and catch exception - $ret = (new \libraries\ProcRunner(array('pygmentize', '-F', 'codetagify', '-O', 'encoding=guess,outencoding=utf8,stripnl=False', '-l', $lexer, '-f', 'html', $file))) + $ret = (new \libraries\ProcRunner(array('pygmentize', '-F', 'codetagify', '-O', 'encoding=guess,outencoding=utf8,stripnl=False', '-l', $lexer, '-f', 'html'))) + ->input($content) ->exec(); // Last 2 items are "
" and "" $lines_to_remove = 2; -- cgit v1.2.3-24-g4f1b