summaryrefslogtreecommitdiffstats
path: root/application/controllers/file.php
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2013-02-25 19:27:23 +0100
committerFlorian Pritz <bluewind@xinu.at>2013-02-25 20:49:49 +0100
commitb99ae1000c31cabc8621b24ebedd64ed4ad67267 (patch)
tree97e40f1631ba608446e09f9cc61a05142ca60a38 /application/controllers/file.php
parent3b5a740ef9a6c905be8be30ad1674c8825dd0f71 (diff)
automatically wrap lines
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/controllers/file.php')
-rw-r--r--application/controllers/file.php40
1 files changed, 32 insertions, 8 deletions
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 .= '<div class="code content table">'."\n";
+ $output .= '<div class="highlight"><pre>'."\n";
- echo '<table class="content"><tr>';
- echo '<td class="numbers"><pre>';
- // generate line numbers (links)
- passthru('perl -ne \'print "<a href=\"#n$.\" ><span class=\"anchor\" id=\"n$.\"> </span>$.</a>\n"\' '.escapeshellarg($file), $return_value);
- echo '</pre></td><td class="code">'."\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 "</pre></div>" 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("<div class=\"highlight\"><pre>", "", $line);
+ }
+
+ // Be careful not to add superflous whitespace here (we are in a <pre>)
+ $output .= "<div class=\"table-row\">"
+ ."<a href=\"#n$line_number\" class=\"linenumber table-cell\">"
+ ."<span class=\"anchor\" id=\"n$line_number\"> </span>"
+ ."</a>"
+ ."<span class=\"line table-cell\">".$line."</span>\n";
+ $output .= "</div>";
+ }
+
+ $output .= "</pre></div>";
+ $output .= "</div>";
+
return array(
"return_value" => $return_value,
"output" => $output