From: x2003bruneau Date: Fri, 14 Jul 2006 21:46:19 +0000 (+0000) Subject: Fix wrapping issues with very long lines (need more tests) X-Git-Tag: 1.8~198 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=fc71753bf973130959081d1f8801c3401e44f4a7;p=banana.git Fix wrapping issues with very long lines (need more tests) Reduce vertical margin in post body git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@99 9869982d-c50d-0410-be91-f2a2ec7c7c7b --- diff --git a/Changelog b/Changelog index 07f3746..66cc201 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +Fri, 14 Jul 2006 Florent Bruneau + * Bugfix: wrapping issues with very long lines + Thu, 13 Jul 2006 Florent Bruneau * Bugfix: xfaces handling diff --git a/banana/misc.inc.php b/banana/misc.inc.php index c855da5..c379ba0 100644 --- a/banana/misc.inc.php +++ b/banana/misc.inc.php @@ -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 = '
'.html_entity_decode(to_entities(richtextToHtml($_text))).'
'; } else { - $res = "\n\n" . to_entities(wrap($_text, "", $flowed))."\n\n"; + $res = "\n" . to_entities(wrap($_text, "", $flowed))."\n"; $res = formatPlainText($res); }