CVS update: /cowiki/includes/cowiki/class/parse/

[email protected] 15 Mar 2005 22:44:50 -0000
Newsgroups gmane.comp.php.cowiki.cvs
Message-ID <[email protected]>
User: cmarble 
Date: 05/03/15 14:44:50

Modified:
 /cowiki/includes/cowiki/class/parse/
  class.WikiParser.php

Log:
 Issue number:  152, 174, 195, 196, 208
 Obtained from: 
 Submitted by:  cmarble
 Reviewed by:   
 
 Think I've got the list sub-issue sorted. I'll be looking for bullets in a table (#198) next, and any table-related issues.
 
 Unless what I've commit-ed is a crock of shite...
 
 ...but that's where peer review comes in :-)

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.41&r2=1.42
Delta lines:  +58 -15
---------------------
--- class.WikiParser.php	15 Mar 2005 19:48:53 -0000	1.41
+++ class.WikiParser.php	15 Mar 2005 22:44:50 -0000	1.42
@@ -2,7 +2,7 @@
 
 /**
  *
- * $Id: class.WikiParser.php,v 1.41 2005/03/15 19:48:53 cmarble Exp $
+ * $Id: class.WikiParser.php,v 1.42 2005/03/15 22:44:50 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.41 $
+ * @version     $Revision: 1.42 $
  *
  */
 
@@ -322,7 +322,7 @@
                 break;
 
             case WIKI_TOKEN_LIST:
-                $sStr = $this->createList($sStr);
+                $sStr = $this->createList($sStr, $mMeta);
                 break;
 
             case WIKI_TOKEN_SIMPLE_TABLE:
@@ -911,13 +911,6 @@
         // processing.
         $sStr = $this->processBreak($sStr);
 
-        // After this step lists are tokenized for further processing.
-        $sStr = $this->processList($sStr);
-
-        // After this step all emphasis markups (bold, italic, ...) are
-        // tokenized for further processing.
-        $sStr = $this->processEmphasis($sStr);
-
         // After this step all subs (<sub>) are tokenized for further
         // processing.
         $sStr = $this->processSub($sStr);
@@ -926,6 +919,13 @@
         // processing.
         $sStr = $this->processSup($sStr);
 
+        // After this step lists are tokenized for further processing.
+        $sStr = $this->processList($sStr);
+
+        // After this step all emphasis markups (bold, italic, ...) are
+        // tokenized for further processing.
+        $sStr = $this->processEmphasis($sStr);
+
 	// After this step all <left>,<right> & <centre> are tokenized
 	// for further processing.
 	$sStr = $this->processJustification($sStr);
@@ -1409,11 +1409,12 @@
 	=x= - monospaced
       */
 
-
       $sEmph= '(-{2}|[_=\*/]+)';
       $sCont= '([^\n_=*/]*)';
       $sWord= '([^ \n/](\S?|.*(\S|\t)))';
 
+        $sStr = $this->collapseEmphasis( $sStr );
+
         $sStr = preg_replace_callback(
             '~  ((-{2}|[_=*/])+)
 		([^\n_=*/]+)
@@ -1426,10 +1427,44 @@
         return $sStr;
     }
 
+    protected function collapseEmphasis(&$sStr) {
+
+	//italic
+        $sStr = preg_replace(
+            '=&lt;(em|i)&gt;(.*)&lt;/\1&gt;=ms',
+            '/\2/',
+            $sStr
+        );
+	//bold
+        $sStr = preg_replace(
+            '=&lt;(strong|b)&gt;(.*)&lt;/\1&gt;=ms',
+            '*\2*',
+            $sStr
+        );
+	//monospaced
+        $sStr = preg_replace(
+            '=&lt;tt&gt;(.*)&lt;/tt&gt;=ms',
+            '=\1=',
+            $sStr
+        );
+	//strikethrough
+        $sStr = preg_replace(
+            '=&lt;strike&gt;(.*)&lt;/strike&gt;=ms',
+            '--\1--',
+            $sStr
+        );
+	//underlined
+        $sStr = preg_replace(
+            '=&lt;u&gt;(.*)&lt;/u&gt;=ms',
+            '_\1_',
+            $sStr
+        );
+
+        return $sStr;
+    }
+
     protected function tokenizeEmphasis(&$aMatches) {
 	//proper emphatic nesting	
-      //echo implode('#',$aMatches);
-      //exit;
         if ($aMatches[1]==strrev($aMatches[4])) {
 	    return $this->tokenize($aMatches[3],WIKI_TOKEN_EMPHASIS, $aMatches[1]);
 	} else {
@@ -1691,6 +1726,7 @@
 
         // Treat lists
         $sStr = preg_replace_callback(
+	    /* '=\n(( {0,})(\*|#)+ (.*))$=Us',*/
             '=\n((\*|#) (.*)\n)(?! {0,}(\*|#))=Us',
             array(&$this, 'tokenizeList'),
             $sStr
@@ -1710,7 +1746,11 @@
      * @since   coWiki 0.3.0
      */
     protected function tokenizeList(&$aMatches) {
-        return "\n".$this->tokenize($aMatches[1], WIKI_TOKEN_LIST)."\n";
+	return "\n".$this->tokenize(
+		    $aMatches[1],
+		    WIKI_TOKEN_LIST,
+		    $this->processEmphasis($aMatches[4])
+		)."\n";
     }
 
     // --------------------------------------------------------------------
@@ -1723,7 +1763,7 @@
      * @author  Daniel T. Gorski, <[email protected]>
      * @since   coWiki 0.3.0
      */
-    protected function createList(&$sStr) {
+    protected function createList(&$sStr, &$mMeta) {
 
         // Fix multiple bullets at the beginning of the line.
         // E.g. fix sick things like this to make it intuitive:
@@ -1756,7 +1796,10 @@
         $this->aList = array();
 
         for ($i=0; $i<sizeof($aList[1]); $i++) {
-            $this->aList[$i]['TEXT']  = $aList[3][$i];
+	  //$this->aList[$i]['TEXT'] = $this->restoreTokens($mMeta);
+	  //$this->aList[$i]['TEXT']  = $aList[3][$i];
+	    $sEmp = $this->restoreTokens($this->processEmphasis($aList[3][$i]));
+	    $this->aList[$i]['TEXT'] = $sEmp;
             $this->aList[$i]['DEPTH'] = strspn($aList[1][$i], ' ');
             $this->aList[$i]['TYPE']  = $aList[2][$i];
         }