yepeeeee, text engine seems to be OK
authorPierre Habouzit (MadCoder <pierre.habouzit@m4x.org>
Sat, 29 Jan 2005 22:53:16 +0000 (22:53 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:27:56 +0000 (23:27 +0200)
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-411

include/wiki.inc.php

index 1404f22..23a1595 100644 (file)
@@ -306,7 +306,8 @@ class XOrgWikiToText
     // {{{ function render
 
     function render($AST, $idt = '') {
-        return $idt . $this->_render($AST, $idt, false);
+        $res = $this->_render($AST, $idt, false, true);
+        return substr($res, $res{0} == "\n")."\n";
     }
 
     // }}}
@@ -315,18 +316,21 @@ class XOrgWikiToText
 
     // {{{ function _render
     
-    function _render($AST, $idt, $list)
+    function _render($AST, $idt, $list, $first)
     {
         $res = '';
+        if (strpos('|br|div|p|pre|h1|h2|h3|li|', "|{$AST->type}|")!==false && !$first) {
+            $res .= "\n$idt";
+        }
         if ($AST->type == 'ol' || $AST->type == 'ul') {
             if ($list) {
-                $idt .= '    ';
-                $res .= "\n$idt";
+                $res .= "$idt";
             } else {
                 $list = true;
             }
         } elseif ($AST->type == 'li') {
             $res .= '  - ';
+            $idt .= '    ';
         } elseif ($AST->type == 'u') {
             $res .= '_';
         } elseif ($AST->type == 'em') {
@@ -339,14 +343,14 @@ class XOrgWikiToText
             return "[{$AST->attrs['src']}]";
         }
         foreach ($AST->childs as $val) {
+            $first = false;
             if (is_string($val)) {
                 $res .= $val;
             } else {
-                $res .= $this->_render($val, $idt, $list);
+                $res .= $this->_render($val, $idt, $list, $first);
             }
         }
         if (strpos('|br|div|p|pre|h1|h2|h3|li|', "|{$AST->type}|")!==false) {
-            $res .= "\n$idt";
         } elseif ($AST->type == 'u') {
             $res .= '_';
         } elseif ($AST->type == 'em') {