Fix wrapping issues with very long lines (need more tests)
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Fri, 14 Jul 2006 21:46:19 +0000 (21:46 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:34:57 +0000 (00:34 +0100)
Reduce vertical margin in post body

git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@99 9869982d-c50d-0410-be91-f2a2ec7c7c7b

Changelog
banana/misc.inc.php

index 07f3746..66cc201 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -1,3 +1,6 @@
+Fri, 14 Jul 2006                    Florent Bruneau <florent.bruneau@m4x.org>
+       * Bugfix: wrapping issues with very long lines
+
 Thu, 13 Jul 2006                    Florent Bruneau <florent.bruneau@m4x.org>
        * Bugfix: xfaces handling
        
index c855da5..c379ba0 100644 (file)
@@ -431,8 +431,8 @@ function autoformat($text)
 {
     global $banana;
     $length = $banana->wrap;
-        
-    $cmd = "echo ".escapeshellarg($text)." | perl -MText::Autoformat -e 'autoformat {left=>1, right=>$length, all=>1 };'";
+    
+    $cmd = "echo ".escapeshellarg($text)." | perl -MText::Autoformat -e 'autoformat {left=>1, right=>$length };'";
     exec($cmd, $result, $ret);
     if ($ret != 0) {
         $result = split("\n", $text);
@@ -460,7 +460,8 @@ function wrap($text, $_prefix="", $_force=false)
     $format = false;
     foreach ($splits as $line) {
         if ($_force || strlen($line) > $max) {
-            if (preg_match("!^(.*)($url)(.*)!i", $line, $matches) && strlen($matches[2]) > $length && strlen($matches) < 900) {
+            if (preg_match("!^(.*)($url)(.*)!i", $line, $matches)
+                    && strlen($matches[2]) > $length && strlen($matches) < 900) {
                 if (strlen($matches[1]) != 0) {
                     array_push($next, rtrim($matches[1]));
                     if (strlen($matches[1]) > $max) {
@@ -484,8 +485,12 @@ function wrap($text, $_prefix="", $_force=false)
                     }
                 }
             } else {
-                $format = true;
-                array_push($next, $line);
+                if (strlen($line) > 2 * $max) {
+                    $next = array_merge($next, autoformat($line));
+                } else {
+                    $format = true;
+                    array_push($next, $line);
+                }
             }
         } else {
             array_push($next, $line);
@@ -523,7 +528,7 @@ function formatbody($_text, $format='plain', $flowed=false)
     } else if ($format == 'richtext') {
         $res = '<br/>'.html_entity_decode(to_entities(richtextToHtml($_text))).'<br/>';
     } else {
-        $res  = "\n\n" . to_entities(wrap($_text, "", $flowed))."\n\n";
+        $res  = "\n" . to_entities(wrap($_text, "", $flowed))."\n";
         $res  = formatPlainText($res);
     }