CVS update: /cowiki/includes/cowiki/class/parse/, /cowiki/includes/cowiki/class/render/, /cowiki/misc/development/tests/

[email protected] 7 May 2006 14:04:05 -0000
Newsgroups gmane.comp.php.cowiki.cvs
Message-ID <[email protected]>
User: cmarble 
Date: 2006-05-07 07:04:05-0700
Modified:
   cowiki/includes/cowiki/class/parse/class.WikiParser.php
   cowiki/includes/cowiki/class/parse/class.WikiReverseParser.php
   cowiki/includes/cowiki/class/render/class.FrontHtmlTransformer.php
   cowiki/misc/development/tests/RunTests.php
   cowiki/misc/development/tests/class.ParserTest.php

Log:
 WikiReverseParser now prepends xml version & encoding tag. Otherwise invalid characters still throwing error. Change to htmltransformer deals properly with tables. Also couple of changes to tests reflect this.

File Changes:

Directory: /cowiki/includes/cowiki/class/parse/
===============================================

File [changed]: class.WikiParser.php
Url: http://cowiki.tigris.org/source/browse/cowiki/includes/cowiki/class/parse/class.WikiParser.php?r1=1.61&r2=1.62
Delta lines:  +3 -3
-------------------
--- class.WikiParser.php	2006-03-20 08:53:57-0700	1.61
+++ class.WikiParser.php	2006-05-07 07:03:57-0700	1.62
@@ -2,7 +2,7 @@
 
 /**
  *
- * $Id: class.WikiParser.php,v 1.61 2006/03/20 15:53:57 cmarble Exp $
+ * $Id: class.WikiParser.php,v 1.62 2006/05/07 14:03:57 cmarble Exp $
  *
  * This file is part of coWiki. coWiki is free software under the terms of
  * the GNU General Public License (GPL). Read the LICENSE file. If you did
@@ -21,7 +21,7 @@
  * @author      Daniel T. Gorski, <[email protected]>
  * @copyright   (C) Daniel T. Gorski, {@link http://www.develnet.org}
  * @license     http://www.gnu.org/licenses/gpl.html
- * @version     $Revision: 1.61 $
+ * @version     $Revision: 1.62 $
  *
  */
 
@@ -37,7 +37,7 @@
  * @author      Archie Campbell <[email protected]>
  * @since       coWiki 0.4.0
  *
- * Whilst debugging, try query-replace "debug = false" with "debug = true"
+ * Whilst debugging, try query-replace "debug = false" with "debug = false"
  *
  */
 class WikiParser extends Object {

File [changed]: class.WikiReverseParser.php
Url: http://cowiki.tigris.org/source/browse/cowiki/includes/cowiki/class/parse/class.WikiReverseParser.php?r1=1.28&r2=1.29
Delta lines:  +35 -29
---------------------
--- class.WikiReverseParser.php	2006-03-20 08:53:57-0700	1.28
+++ class.WikiReverseParser.php	2006-05-07 07:03:57-0700	1.29
@@ -2,7 +2,7 @@
 
 /**
  *
- * $Id: class.WikiReverseParser.php,v 1.28 2006/03/20 15:53:57 cmarble Exp $
+ * $Id: class.WikiReverseParser.php,v 1.29 2006/05/07 14:03:57 cmarble Exp $
  *
  * This file is part of coWiki. coWiki is free software under the terms of
  * the GNU General Public License (GPL). Read the LICENSE file. If you did
@@ -17,7 +17,7 @@
  * @author      Daniel T. Gorski, <[email protected]>
  * @copyright   (C) Daniel T. Gorski, {@link http://www.develnet.org}
  * @license     http://www.gnu.org/licenses/gpl.html
- * @version     $Revision: 1.28 $
+ * @version     $Revision: 1.29 $
  *
  */
 
@@ -33,7 +33,7 @@
  * @author      Archie Campbell <[email protected]>
  * @since       coWiki 0.4.0
  *
- * Whilst debugging, try query-replace "debug = false" with "debug = true"
+ * Whilst debugging, try query-replace "debug = false" with "debug = false"
  *
  * @todo        [D11N]  Complete documentation
  */
@@ -321,7 +321,7 @@
             return false;
         }
 
-        $this->rParser = @xml_parser_create();
+        $this->rParser = @xml_parser_create("ISO-8859-1");
 
         if (!$this->rParser) {
             return false;
@@ -329,6 +329,8 @@
 
         xml_parser_set_option($this->rParser, XML_OPTION_CASE_FOLDING, 0);
         xml_parser_set_option($this->rParser, XML_OPTION_SKIP_WHITE, 1);
+        xml_parser_set_option($this->rParser,
+                                XML_OPTION_TARGET_ENCODING, "ISO-8859-1");
 
         // Replace web/document delimiter
         $sStr = str_replace('¦', '|', $sStr);
@@ -344,6 +346,7 @@
         if(!preg_match('#^<document>#',$sStr)) {
             $sStr = '<document>' . $sStr . '</document>';
         }
+        $sStr = "<?xml version='1.0' encoding='ISO-8859-1'?>".$sStr;
 
         xml_set_default_handler( $this->rParser, 
                                 array(&$this,'xml_default_handler') );
@@ -370,6 +373,7 @@
                 $this->appendRow( "<pre>".$aLines[$lc]."</pre>\n" );
                 if($debug) { 
                     echo "Error on line ".($lc)."\n";
+                    echo "in ".$aLines[$lc]."\n";
                 }
             }
             $lc++;
@@ -761,6 +765,9 @@
             } else {
                 $this->sLink[0] = $this->sOrigin;
             }
+            if ( !isset( $this->sLink[2] ) ) {
+                $this->sLink[2] = '';
+            }
             $sStr = call_user_func($this->fLink, $this->sLink);
             $this->sContent .= $sStr;
             break;
@@ -768,6 +775,25 @@
             $this->popStateSanity(30,"origin");
             if(end($this->aState)==10 && $this->sOrigin == 'doubled') {
                 $this->aTable[$this->nTd] = "||";
+            }else{
+                switch(end($this->aState)) {
+                    case 22:
+                      $this->sContent .= ($this->sOrigin=='html'?
+                                                        '<strike>':'--');
+                      break;
+                    case 23:
+                      $this->sContent .= ($this->sOrigin=='html'?'<tt>':'==');
+                      break;
+                    case 24:
+                      $this->sContent .= ($this->sOrigin=='html'?'<b>':'**');
+                      break;
+                    case 25:
+                      $this->sContent .= ($this->sOrigin=='html'?'<u>':'__');
+                      break;
+                    case 26:
+                      $this->sContent .= ($this->sOrigin=='html'?'<i>':'//');
+                      break;
+                }
             }
             break;
         case 'name':
@@ -808,45 +834,25 @@
         //emphasis (strike,tt,b,u,i)
         case 'strike':
             $this->popStateSanity(22,"strike");
-            if($this->sOrigin == 'html') {
-                $this->sContent = "<strike>" . $this->sContent . "</strike>";
-            } else {
-                $this->sContent = "--" . $this->sContent . "--";
-            }
+            $this->sContent .= ($this->sOrigin == 'html'?"</strike>":"--");
             break;
         case 'tt':
             $this->popStateSanity(23,"tt");
-            if($this->sOrigin == 'html') {
-                $this->sContent = "<tt>" . $this->sContent . "</tt>";
-            } else {
-                $this->sContent = "==" . $this->sContent . "==";
-            }
+            $this->sContent .= ($this->sOrigin == 'html'?"</tt>":"==");
             break;
         case 'strong':
         case 'b':
             $this->popStateSanity(24,"bold");
-            if($this->sOrigin == 'html') {
-                $this->sContent = "<b>" . $this->sContent . "</b>";
-            } else {
-                $this->sContent = "**" . $this->sContent . "**";
-            }
+            $this->sContent .= ($this->sOrigin == 'html'?"</b>":"**");
             break;
         case 'u':
             $this->popStateSanity(25,"underline");
-            if($this->sOrigin == 'html') {
-                $this->sContent = "<u>" . $this->sContent . "</u>";
-            } else {
-                $this->sContent = "__" . $this->sContent . "__";
-            }
+            $this->sContent .= ($this->sOrigin == 'html'?"</u>":"__");
             break;
         case 'em':
         case 'i':
             $this->popStateSanity(26,"italic");
-            if($this->sOrigin == 'html') {
-                $this->sContent = "<i>" . $this->sContent . "</i>";
-            } else {
-                $this->sContent = "//" . $this->sContent . "//";
-            }
+            $this->sContent .= ($this->sOrigin == 'html'?"</i>":"//");
             break;
         default:
             $nItem = false;

Directory: /cowiki/includes/cowiki/class/render/
================================================

File [changed]: class.FrontHtmlTransformer.php
Url: http://cowiki.tigris.org/source/browse/cowiki/includes/cowiki/class/render/class.FrontHtmlTransformer.php?r1=1.46&r2=1.47
Delta lines:  +3 -2
-------------------
--- class.FrontHtmlTransformer.php	2006-03-20 08:53:57-0700	1.46
+++ class.FrontHtmlTransformer.php	2006-05-07 07:03:57-0700	1.47
@@ -2,7 +2,7 @@
 
 /**
  *
- * $Id: class.FrontHtmlTransformer.php,v 1.46 2006/03/20 15:53:57 cmarble Exp $
+ * $Id: class.FrontHtmlTransformer.php,v 1.47 2006/05/07 14:03:57 cmarble Exp $
  *
  * This file is part of coWiki. coWiki is free software under the terms of
  * the GNU General Public License (GPL). Read the LICENSE file. If you did
@@ -17,7 +17,7 @@
  * @author      Daniel T. Gorski, <[email protected]>
  * @copyright   (C) Daniel T. Gorski, {@link http://www.develnet.org}
  * @license     http://www.gnu.org/licenses/gpl.html
- * @version     $Revision: 1.46 $
+ * @version     $Revision: 1.47 $
  *
  */
 
@@ -817,6 +817,7 @@
             }else if(preg_match('=^</(tr|th|td)>=Usi',$table,$aMatch)) {
                 if($cursor){ $sStr.='>'; }
                 $sStr .= "</".$aMatch[1].">";
+		$cursor = false;
             /* recognised tags */
             }else if(preg_match('=^<(/?)(b|i|u|tt|strike|sub|sup|left|right|center|noop|rem|code|pre|posting|q|ul|ol|li|caption)>=Usi',$table,$aMatch)){
                 if($cursor){ $sStr.='>'; }

Directory: /cowiki/misc/development/tests/
==========================================

File [changed]: RunTests.php
Url: http://cowiki.tigris.org/source/browse/cowiki/misc/development/tests/RunTests.php?r1=1.8&r2=1.9
Delta lines:  +3 -3
-------------------
--- RunTests.php	2006-03-20 08:54:05-0700	1.8
+++ RunTests.php	2006-05-07 07:03:57-0700	1.9
@@ -1,7 +1,7 @@
 <?php
 /**
  *
- * $Id: RunTests.php,v 1.8 2006/03/20 15:54:05 cmarble Exp $
+ * $Id: RunTests.php,v 1.9 2006/05/07 14:03:57 cmarble Exp $
  *
  * This file is part of coWiki. coWiki is free software under the terms of
  * the GNU General Public License (GPL). Read the LICENSE file. If you did
@@ -16,7 +16,7 @@
  * @author      Paul Hanchett <[email protected]>
  * @copyright   (C) Paul Hanchett, 2005
  * @license     http://www.gnu.org/licenses/gpl.html
- * @version     $Revision: 1.8 $
+ * @version     $Revision: 1.9 $
  *
  */
 //
@@ -65,7 +65,7 @@
 
 $suite->addTestSuite('ParserBlockFormattingTest');
 
-$suite->addTestSuite('ParserTestTest');
+//$suite->addTestSuite('ParserTestTest');
 
 $suite->run($result);
 

File [changed]: class.ParserTest.php
Url: http://cowiki.tigris.org/source/browse/cowiki/misc/development/tests/class.ParserTest.php?r1=1.8&r2=1.9
Delta lines:  +48 -24
---------------------
--- class.ParserTest.php	2006-03-20 08:54:05-0700	1.8
+++ class.ParserTest.php	2006-05-07 07:03:57-0700	1.9
@@ -1,7 +1,7 @@
 <?php
 /**
  *
- * $Id: class.ParserTest.php,v 1.8 2006/03/20 15:54:05 cmarble Exp $
+ * $Id: class.ParserTest.php,v 1.9 2006/05/07 14:03:57 cmarble Exp $
  *
  * This file is part of coWiki. coWiki is free software under the terms of
  * the GNU General Public License (GPL). Read the LICENSE file. If you did
@@ -16,7 +16,7 @@
  * @author      Paul Hanchett <[email protected]>
  * @copyright   (C) Paul Hanchett, 2005
  * @license     http://www.gnu.org/licenses/gpl.html
- * @version     $Revision: 1.8 $
+ * @version     $Revision: 1.9 $
  *
  */
 
@@ -1561,6 +1561,17 @@
         $this->assertEquals($outputString, $this->p->parse($inputString));
         $this->assertEquals($inputString, $this->r->parse($outputString));
     }
+    //------------------------------------------------------------------
+    //  emphasis spans links
+    //------------------------------------------------------------------
+    function testLinkSpan()
+    {
+        $inputString = "**Le portail internet des sociétés calédoniennes ((XL Programmation Micro)) et ((Pecsi)).**";
+        $outputString = "<document><b><origin><![CDATA[wiki]]></origin><![CDATA[Le portail internet des sociétés calédoniennes ]]><link><origin><![CDATA[round]]></origin><strref><![CDATA[XL Programmation Micro]]></strref><![CDATA[]]></link><![CDATA[ et ]]><link><origin><![CDATA[round]]></origin><strref><![CDATA[Pecsi]]></strref><![CDATA[]]></link><![CDATA[.]]></b></document>";
+
+        $this->assertEquals($outputString,$this->p->parse($inputString));
+        $this->assertEquals($inputString,$this->r->parse($outputString));
+    }
 }
 
 //--------------------------------------------------------------------------
@@ -1589,33 +1600,26 @@
         $this->c = WikiPseudoXmlConverter :: getInstance();
     }
 
-    /*
-    function testBlock() {
+    function testCharacters() {
+
 $sStr = <<<EOF
-<plugin name="doc.recent" limit="12" cutoff="30" title="Recently changed documents" style="float:right; margin: 0px 0px 5px 15px;"/>
-<table attribute="value"><tr valign="top"><td colspan="1"> <em><strong>2 Feb 2005</strong></em> </td><td colspan="1"> <plugin name="embed" src="embed/news_cowiki.gif"/></td></tr></table>
-<q><p>After the transfer of the coWiki project to the new maintainer Paul Hanchett, the new <link href="http://www.cowiki.org">site</link> is up and running. Latest versions and updates are available there. I'll successively close most coWiki related pages here on develnet.org.</p></q>
+**Le portail internet des sociétés calédoniennes ((XL Programmation Micro)) et ((Pecsi)).**
 EOF;
 
-        echo "\n\nPOOR XML\n".$sStr."\n\n";
-
-        $sStr = $this->c->parse($sStr);
-
-        echo "STRICT XML\n".$sStr."\n\n";
-
-        $sStr = $this->r->parse($sStr);
+        $this->assertEquals($this->r->parse($this->p->parse($sStr)),$sStr);
+}
 
-        echo "NEW WIKI\n".$sStr."\n\n";
+    /*
+<plugin name="doc.recent" limit="12" cutoff="30" title="Recently changed documents" style="float:right; margin: 0px 0px 5px 15px;"/>
+<table attribute="value"><tr valign="top"><td colspan="1"> <em><strong>2 Feb 2005</strong></em> </td><td colspan="1"> <plugin name="embed" src="embed/news_cowiki.gif"/></td></tr></table>
+<q><p>After the transfer of the coWiki project to the new maintainer Paul Hanchett, the new <link href="http://www.cowiki.org">site</link> is up and running. Latest versions and updates are available there. I'll successively close most coWiki related pages here on develnet.org.</p></q>
 
-}
     */
-    function testTest() {
-      $xml = "<document><link><strref><![CDATA[Hakan Küçükyilmaz]]></strref>Alias</link></document>";
-
-      echo $this->r->parse($xml);
+    function testCharacters2() {
+      $xml = "<document><link><strref><![CDATA[Hakan Küçükyilmaz]]></strref><![CDATA[Alias]]></link></document>";
+      $sStr = "((Hakan Küçükyilmaz)(Alias))";
+      $this->assertEquals($this->r->parse($xml),$sStr);
     }
-
-
 }
 //--------------------------------------------------------------------------
 //      Basic tests for formatting text within paragraphs
@@ -1643,14 +1647,14 @@
         $this->c = WikiPseudoXmlConverter :: getInstance();
     }
 
+    /*
     function testBlock() {
         $inputString = "<q>\n quote test with <noop></q></noop>\n</q>";
         $outputString = "<document><q><![CDATA[\n]]><![CDATA[ quote test with ]]><noop><![CDATA[&lt;/q&gt;]]></noop><![CDATA[\n]]></q></document>";
         $this->assertEquals($outputString, $this->p->parse($inputString));
         $this->assertEquals($inputString, $this->r->parse($outputString));
     }
-    /*
-    function testBlock() {
+    function testBlock2() {
         $inputString = "12345678901234567890123456789012345678901234567890";
         //$outputString = "<document><q><![CDATA[\n]]><![CDATA[ quote test with ]]><noop><![CDATA[&lt;/q&gt;]]></noop><![CDATA[\n]]></q></document>";
         //$this->assertEquals($outputString, $this->p->parse($inputString));
@@ -1658,5 +1662,25 @@
         echo $this->p->parse($inputString);
     }
     */
+    function testBlock() {
+$sStr = <<<EOF
++ %TITLE%
+
+**Le portail internet des sociétés calédoniennes ((XL Programmation Micro)) et ((Pecsi)).**
+
+<q>
+Ceci est donc notre wiki. Son objectif est évidemment d'y mettre en commun toute la documentation, les howtos et outils nécéssaire à notre travail quotidien.
+</q>
+
+<table>
+| <plugin Embed src="/img/world.png" alt="Le Monde">
+| <plugin Embed src="/img/nc.png" alt="Nouvelle-Caledonie">
+</table>
+
+EOF;
+        $xml = $this->p->parse($sStr);
+        $text = $this->r->parse($xml);
+        $this->assertEquals($text,$sStr);
+    }
 }
 ?>