diff options
author | Florian Pritz <bluewind@xinu.at> | 2017-03-22 16:34:15 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2017-03-22 16:34:15 +0100 |
commit | 06ce8d971b1dfd7a520c1c2e4933d84f3e4c80d0 (patch) | |
tree | 0c812848ebdf37e0842b67215bd5e08775054a9d | |
parent | f3663b034754aa2e3dc0ea2a9485255951008a74 (diff) |
Pass file content to lexer via stdin
This allows to easily modify the content before rendering it.
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r-- | application/controllers/file/file_default.php | 7 |
1 files 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 .= '<div class="code content table">'."\n"; $output .= '<div class="highlight"><code class="code-container">'."\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 "</pre></div>" and "" $lines_to_remove = 2; |