summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2012-10-15 23:38:44 +0200
committerFlorian Pritz <bluewind@xinu.at>2012-10-16 22:12:32 +0200
commit36f0185d8c950933099268c69081cabc084545c9 (patch)
treeddfdc602a15080d2de464aa670a9715f33294da4
parent143d920cb703d47bd8606ba2497241fce7d06a27 (diff)
Fall back to plain text if lexer is unknown/broken
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--application/controllers/file.php59
-rw-r--r--application/views/file/html_header.php2
-rw-r--r--data/paste.css6
3 files changed, 52 insertions, 15 deletions
diff --git a/application/controllers/file.php b/application/controllers/file.php
index 427af33dc..2cf84016b 100644
--- a/application/controllers/file.php
+++ b/application/controllers/file.php
@@ -179,35 +179,68 @@ class File extends CI_Controller {
// highlight the file and chache the result
$this->load->library("MemcacheLibrary");
if (! $cached = $this->memcachelibrary->get($filedata['hash'].'_'.$lexer)) {
- ob_start();
if ($lexer == "rmd") {
+ ob_start();
+
+ echo '<table class="content"><tr>';
echo '<td class="markdownrender">'."\n";
passthru('perl '.FCPATH.'scripts/Markdown.pl '.escapeshellarg($file), $return_value);
+
+ $cached = ob_get_contents();
+ ob_end_clean();
} elseif ($lexer == "ascii") {
+ ob_start();
+
+ echo '<table class="content"><tr>';
echo '<td class="code"><pre class="text">'."\n";
passthru('perl '.FCPATH.'scripts/ansi2html '.escapeshellarg($file), $return_value);
echo "</pre>\n";
+
+ $cached = ob_get_contents();
+ ob_end_clean();
} else {
- echo '<td class="numbers"><pre>';
- // generate line numbers (links)
- passthru('perl -ne \'print "<a href=\"#n$.\" id=\"n$.\">$.</a>\n"\' '.escapeshellarg($file), $return_value);
- echo '</pre></td><td class="code">'."\n";
- passthru('pygmentize -F codetagify -O encoding=guess,outencoding=utf8 -l '.escapeshellarg($lexer).' -f html '.escapeshellarg($file), $return_value);
+ $ret = $this->_pygmentize($file, $lexer);
+ $return_value = $ret["return_value"];
+ $cached = $ret["output"];
+ }
+
+ if ($return_value != 0) {
+ $cached = "<div class=\"error\"><p>Error trying to process the file.
+ Either the lexer is unknown or something is broken.
+ Falling back to plain text.</p></div>\n";
+ $ret = $this->_pygmentize($file, "text");
+ $cached .= $ret["output"];
}
- $cached = ob_get_contents();
- ob_end_clean();
$this->memcachelibrary->set($filedata['hash'].'_'.$lexer, $cached, 100);
}
- if ($return_value != 0) {
- show_error("Error trying to process the file. Either the lexer is unknown or something is broken.\n");
- } else {
- $this->output->append_output($cached);
- }
+ $this->output->append_output($cached);
$this->load->view($this->var->view_dir.'/html_footer', $this->data);
}
+ private function _pygmentize($file, $lexer)
+ {
+ $return_value = 0;
+
+ ob_start();
+
+ echo '<table class="content"><tr>';
+ echo '<td class="numbers"><pre>';
+ // generate line numbers (links)
+ passthru('perl -ne \'print "<a href=\"#n$.\" id=\"n$.\">$.</a>\n"\' '.escapeshellarg($file), $return_value);
+ echo '</pre></td><td class="code">'."\n";
+ passthru('pygmentize -F codetagify -O encoding=guess,outencoding=utf8 -l '.escapeshellarg($lexer).' -f html '.escapeshellarg($file), $return_value);
+
+ $output = ob_get_contents();
+ ob_end_clean();
+
+ return array(
+ "return_value" => $return_value,
+ "output" => $output
+ );
+ }
+
function _display_info($id)
{
$this->data["title"] .= " - Info $id";
diff --git a/application/views/file/html_header.php b/application/views/file/html_header.php
index cd2116ada..60db38238 100644
--- a/application/views/file/html_header.php
+++ b/application/views/file/html_header.php
@@ -50,5 +50,3 @@ if ("onhashchange" in window) {
}
/* ]]> */
</script>
- <table class="content">
- <tr>
diff --git a/data/paste.css b/data/paste.css
index c8f165a75..925f432d4 100644
--- a/data/paste.css
+++ b/data/paste.css
@@ -83,6 +83,12 @@ a.no {
a.raw_link {
color: lightblue;
}
+
+.error {
+ padding: 10px 20px;
+ background: #fcc;
+}
+
.hll { background-color: #ffffcc }
.c { color: #408080; font-style: italic } /* Comment */
.err { border: 1px solid #FF0000 } /* Error */