Ugly hack, but really fix issues with some 'long lines'
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Thu, 10 Aug 2006 13:02:26 +0000 (13:02 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:35:08 +0000 (00:35 +0100)
git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@135 9869982d-c50d-0410-be91-f2a2ec7c7c7b

banana/misc.inc.php

index ccc309b..f8bdada 100644 (file)
@@ -479,13 +479,13 @@ function makeTable($text)
  *  FORMATTING STUFF : BODY
  */
 
-function autoformat($text)
+function autoformat($text, $force = 0)
 {
     global $banana;
     $length = $banana->wrap;
-    
+    $force  = $force ? 1 : 0; 
     $cmd = 'echo ' . escapeshellarg($text)
-         . ' | perl -MText::Autoformat -e \'autoformat {left=>1, right=>' . $length . ', all=>1 };\'';
+         . ' | perl -MText::Autoformat -e \'autoformat {left=>1, right=>' . $length . ', all=>' . $force . ' };\'';
 
     exec($cmd, $result, $ret);
     if ($ret != 0) {
@@ -494,7 +494,7 @@ function autoformat($text)
     return $result;
 }                                
 
-function wrap($text, $_prefix="", $_force=false)
+function wrap($text, $_prefix="", $_force=false, $firstpass = true)
 {
     $parts = preg_split("/\n-- ?\n/", $text);
     if (count($parts)  >1) {
@@ -524,7 +524,7 @@ function wrap($text, $_prefix="", $_force=false)
                 }
                     
                 if ($format) {
-                    $result = array_merge($result, autoformat(join("\n", $next)));
+                    $result = array_merge($result, autoformat(join("\n", $next), $firstpass));
                 } else {
                     $result = array_merge($result, $next);
                 }
@@ -547,12 +547,16 @@ function wrap($text, $_prefix="", $_force=false)
         }
     }
     if ($format) {
-        $result = array_merge($result, autoformat(join("\n", $next)));
+        $result = array_merge($result, autoformat(join("\n", $next), $firstpass));
     } else {
         $result = array_merge($result, $next);
     }
 
-    return $_prefix.join("\n$_prefix", $result).($_prefix ? '' : $sign);
+    $result = $_prefix.join("\n$_prefix", $result).($_prefix ? '' : $sign);
+    if ($firstpass) {
+        return wrap($result, $_prefix, $_force, false);
+    }
+    return $result;
 }
 
 function cutlink($link)