Word-wrap for txt files
authorChristian Weiske <cweiske@cweiske.de>
Sat, 28 Oct 2017 13:47:06 +0000 (15:47 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Sat, 28 Oct 2017 13:47:06 +0000 (15:47 +0200)
This means there are no line numbers for .txt anymore,
but I find it more important to have word wrap.

Resolves: https://github.com/cweiske/phorkie/issues/31

data/config.default.php
src/phorkie/Renderer/Plaintext.php [new file with mode: 0644]
www/css/phorkie.css

index 06b53edaaa3c5c1a5783d56ce7197e5a8d997b2d..fce74c1a88572ae2a52f5ac52d07027b632bf380 100644 (file)
@@ -161,7 +161,8 @@ $GLOBALS['phorkie']['languages'] = array(
     'txt' => array(
         'title' => 'Text (plain)',
         'mime'  => 'text/plain',
-        'geshi' => 'txt'
+        'geshi' => 'txt',
+        'renderer' => '\\phorkie\\Renderer_Plaintext'
     ),
     'ts' => array(
         'title' => 'TypoScript',
diff --git a/src/phorkie/Renderer/Plaintext.php b/src/phorkie/Renderer/Plaintext.php
new file mode 100644 (file)
index 0000000..ef448f9
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+namespace phorkie;
+
+/**
+ * Render plain .txt files
+ */
+class Renderer_Plaintext
+{
+    /**
+     * Simply displays the file
+     *
+     * @param File $file File to render
+     *
+     * @return string HTML
+     */
+    public function toHtml(File $file)
+    {
+        $html = '<div class="code"><pre class="txt">'
+            . htmlspecialchars($file->getContent())
+            . '</pre></div>' . "\n";
+        return $html;
+    }
+}
+
+?>
index e9bce5d2e49a6ed4628033b87f8af93519f1ee49..3619d54044d715df4950ad24a74828ed96cbcabe 100644 (file)
@@ -110,6 +110,9 @@ h1 {
     margin: 0px;
     margin-bottom: 2ex;
 }
+.code pre.txt {
+    white-space: pre-wrap;
+}
 .code {
     overflow-x: auto;
 }