From b4e0acc50ce686cc57ca854dd319bb722d1d7f7d Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Fri, 1 Jul 2011 22:10:59 +0200 Subject: add ascii highlighting with escape color support Signed-off-by: Florian Pritz --- application/models/file_mod.php | 14 ++++++++++---- scripts/ansi2html | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100755 scripts/ansi2html diff --git a/application/models/file_mod.php b/application/models/file_mod.php index 2ba44f551..a1ad73b92 100644 --- a/application/models/file_mod.php +++ b/application/models/file_mod.php @@ -247,12 +247,14 @@ class File_mod extends CI_Model { exit(); } + + $special_modes = array("ascii"); // directly download the file - if (!$mode // user didn't specify a mode/didn't enable autodetection + if (!in_array($mode, $special_modes) && (!$mode // user didn't specify a mode/didn't enable autodetection || !$this->mime2extension($type) // file can't be highlighted || $mode == "plain" // user wants to the the plain file || filesize($file) > $this->config->item('upload_max_text_size') - ) { + )) { if ($mode == 'plain') { $type = "text/plain"; } @@ -283,8 +285,12 @@ class File_mod extends CI_Model { if (! $cached = $this->memcachelibrary->get($filedata['hash'].'_'.$mode)) { ob_start(); if ($mode == "rmd") { - echo ''."\n"; - passthru('/usr/bin/perl /usr/bin/perlbin/vendor/Markdown.pl '.escapeshellarg($file)); + echo ''."\n"; + passthru('/usr/bin/perl /usr/bin/vendor_perl/vendor/Markdown.pl '.escapeshellarg($file)); + } elseif ($mode == "ascii") { + echo '
'."\n";
+				passthru('/usr/bin/perl '.FCPATH.'scripts/ansi2html '.escapeshellarg($file));
+				echo "
\n"; } else { echo '
';
 				// generate line numbers (links)
diff --git a/scripts/ansi2html b/scripts/ansi2html
new file mode 100755
index 000000000..e33e24630
--- /dev/null
+++ b/scripts/ansi2html
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+use strict;
+use HTML::FromANSI ();
+
+my $h = HTML::FromANSI->new(
+		fill_cols => 0,
+		font_face => "",
+		style => "",
+		tt => 0
+);
+
+open IN,  "<", $ARGV[0]  or die "cannot read $ARGV[0]: $!";
+
+$h->add_text();
+my $html = $h->html;
+$html =~ s/background: black; //g;
+$html =~ s/color: white; /color: black /g;
+$html =~ s/
/\n/g; + +print $html; -- cgit v1.2.3-24-g4f1b