Re: CVS update: /cowiki/includes/cowiki/class/render/, /cowiki/includes/cowiki/class/parse/

PAUL HANCHETT <[email protected]> Tue, 15 Mar 2005 10:01:50 -0800
Newsgroups gmane.comp.php.cowiki.cvs
Message-ID <[email protected]>
Encouraging sounds from this direction-- Remember that some of us use 
"--" in place of an "em-dash"!

[email protected] wrote:

>User: cmarble 
>Date: 05/03/15 09:16:27
>
>Modified:
> /cowiki/includes/cowiki/class/render/
>  class.FrontHtmlTransformer.php
> /cowiki/includes/cowiki/class/parse/
>  class.WikiParser.php, class.WikiReverseParser.php
>
>Log:
> Issue number:  152, 174, 195, 196, 208
> Obtained from: 
> Submitted by:  cmarble
> Reviewed by:   
> 
> This test file, below...
> 
> *Emphasis* /Italics/ _Underlined_ --Struckout--
> 
> */EmIt/* /*ItEm*/
> 
> *_EmUn_* _*UnEm*_
> <right>/_ItUn_/ _/UnIt/_/*_ItEmUn_*/ /_*ItUnEm*_/</right>
> *--_EmUnSt_--* --/_ItUn_/--
> 
> --/*StItEm*/-- --*/StEmIt/*--
> 
> blah blah blah set-piece blah blah malt-whiskey blah blah
> 
> --struck out doesn't show *bold* here--
> 
> * <b>H</b>yper<i>T</i>ext <u>T</u>ransfer *P*rotocol
> 
> * List
>  * Sub-item
>  * ...
> # numbered list
>  # sub-item
>  # ...
>  # ...
>  * ...
> * Text on one line<br>text on another line
> 
> ...is what I'm using to check my progress. The WikiParser rejects brokenly balanced emphasis.
> 
> Strikethrough is now --struckthrough-- rather than a single hyphen, so that set-pieces of malt-whiskey aren't even looked into.
> 
> The line Hyper Text Transfer etc doesn't work and that's where I'm working at present.
> 
> If all goes to plan, I may even be able to squeeze nested performance out of the emphasis code.
> 
> i.e. --struck through *bold* would still-- appear bold
> 
> It doesn't at present, just the striking shows up.
> 
> Work in progress...
>
>File Changes:
>
>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.40&r2=1.41
>Delta lines:  +8 -3
>-------------------
>--- class.FrontHtmlTransformer.php	14 Mar 2005 17:14:59 -0000	1.40
>+++ class.FrontHtmlTransformer.php	15 Mar 2005 17:16:27 -0000	1.41
>@@ -2,7 +2,7 @@
> 
> /**
>  *
>- * $Id: class.FrontHtmlTransformer.php,v 1.40 2005/03/14 17:14:59 cmarble Exp $
>+ * $Id: class.FrontHtmlTransformer.php,v 1.41 2005/03/15 17:16:27 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.40 $
>+ * @version     $Revision: 1.41 $
>  *
>  */
> 
>@@ -732,9 +732,14 @@
>     // --------------------------------------------------------------------
> 
>     protected function &_transformJustification(&$aMatches) {
>+      /*
>         $sStr =  '<div width="100%" style="text-align:'.$aMatches[1].'">';
>         $sStr .=     $aMatches[2];
>-        $sStr .= '</div>';
>+        $sStr .= '</p>';
>+      */
>+        $sStr =  '<p width="100%" style="text-align:'.$aMatches[1].'">';
>+        $sStr .= $aMatches[2];
>+        $sStr .= '</p>';
> 
>         return $sStr;
>     }
>
>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.39&r2=1.40
>Delta lines:  +74 -65
>---------------------
>--- class.WikiParser.php	14 Mar 2005 17:14:59 -0000	1.39
>+++ class.WikiParser.php	15 Mar 2005 17:16:27 -0000	1.40
>@@ -2,7 +2,7 @@
> 
> /**
>  *
>- * $Id: class.WikiParser.php,v 1.39 2005/03/14 17:14:59 cmarble Exp $
>+ * $Id: class.WikiParser.php,v 1.40 2005/03/15 17:16:27 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.39 $
>+ * @version     $Revision: 1.40 $
>  *
>  */
> 
>@@ -53,6 +53,7 @@
>     define('WIKI_TOKEN_SUB',           19);
>     define('WIKI_TOKEN_SUP',           20);
>     define('WIKI_TOKEN_JUSTIFICATION', 21);
>+    define('WIKI_TOKEN_EMPHASIS',      22);
> /**
>  * coWiki - Wiki parser class
>  *
>@@ -359,6 +360,10 @@
>             case WIKI_TOKEN_JUSTIFICATION:
>                 $sStr = $this->createJustificationElement($sStr, $mMeta);
>                 break;
>+
>+	    case WIKI_TOKEN_EMPHASIS:
>+		$sStr = $this->createEmphasisElement($sStr, $mMeta);
>+		break;
>         }
> 
>         return $sStr;
>@@ -670,6 +675,39 @@
> 	return '<'.$mMeta.'>'.$sStr.'</'.$mMeta.'>';
>     }
> 
>+    protected function createEmphasisElement(&$sStr, &$mMeta) {
>+
>+	$sOpen = $sClose = '';
>+	for ($i=0 ; $i < strlen($mMeta) ; $i++ ){
>+	    switch(substr($mMeta,$i,1)){
>+		case '_':
>+		    $sOpen .= "<u>";
>+		    $sClose = "</u>".$sClose;
>+		    break;
>+		case '-':
>+		    if(!strcmp(substr($mMeta,$i+1,1),'-')){
>+			$sOpen .= "<strike>";
>+			$sClose = "</strike>".$sClose;
>+			$i++;
>+		    }
>+		    break;
>+		case '=':
>+		    $sOpen .= "<tt>";
>+		    $sClose = "</tt>".$sClose;
>+		    break;
>+		case '*':
>+		    $sOpen .= "<b>";
>+		    $sClose = "</b>".$sClose;
>+		    break;
>+		case '/':
>+		    $sOpen .= "<i>";
>+		    $sClose = "</i>".$sClose;
>+		    break;
>+            }
>+	}
>+	return $sOpen . $sStr . $sClose;
>+    }
>+
>     // --- Element creator helpers ----------------------------------------
> 
>     /**
>@@ -861,10 +899,6 @@
>         // processing.
>         $sStr = $this->processToc($sStr);
> 
>-        // After this step all emphasis markups (bold, italic, ...) are
>-        // converted. These markups are not tokenized.
>-        $sStr = $this->processEmphasis($sStr);
>-
>         // After this step all headings (+, ++, +++ -> H1, H2, H3 etc.) are
>         // tokenized for further processing.
>         $sStr = $this->processHeading($sStr);
>@@ -877,6 +911,13 @@
>         // 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);
>@@ -889,9 +930,6 @@
> 	// for further processing.
> 	$sStr = $this->processJustification($sStr);
> 
>-        // After this step lists are tokenized for further processing.
>-        $sStr = $this->processList($sStr);
>-
>         // After this step all parameterized <table></table> are tokenized
>         // for further processing.
>         $sStr = $this->processParamTable($sStr);
>@@ -1362,72 +1400,43 @@
>     protected function processEmphasis(&$sStr) {
> 
>       /*
>-        // These are the possible start delimiters for bold, italic
>-        // and monospace emphasis markups
>-        $sStart = '(\[\'';
>-
>-        // These are the possible end delimiters for bold, italic
>-        // and monospace emphasis markups
>-        $sEnd = '\s,.;:!?()\[\]_-';
>-      */
>+	emphasis markup may be as widely spaced as an entire paragraph
> 
>+	/x/ - italics
>+	*x* - bold
>+	--x-- - strikethrough
>+	_x_ - underlined
>+	=x= - monospaced
>+      */
> 
>-      $sEmph= '([_-=\*]*)';
>-
>-        // Italic first, because we do not want to match "</foo>/bar"
>-        $sStr = preg_replace(
>-            '~  ([^<])?
>-	        (/|&lt;(i|em)&gt;)
>-                ([^ \n/](\S?|.*(\S|\t)))
>-                (/|&lt;/\3&gt;)
>-            ~Umix',
>-            '\1<em>\4</em>',
>-            $sStr
>-        );
> 
>-        // Bold
>-        $sStr = preg_replace(
>-            '~  (\*|&lt;(b|strong)&gt;)
>-                ([^ \n\*](\S?|.*(\S|\t)))
>-                (\*|&lt;/\2&gt;)
>-            ~Umix',
>-            '<strong>\3</strong>',
>-            $sStr
>-        );
>+      $sEmph= '(-{2}|[_=\*/]+)';
>+      $sCont= '([^\n_=*/]*)';
>+      $sWord= '([^ \n/](\S?|.*(\S|\t)))';
> 
>-        // Mono
>-        $sStr = preg_replace(
>-            '~  (=|&lt;(tt)&gt;)
>-                ([^ \n=](\S?|.*(\S|\t)))
>-                (=|&lt;/\2&gt;)
>-            ~Umix',
>-            '<tt>\3</tt>',
>-            $sStr
>-        );
>-
>-        // Strikethrough
>-        $sStr = preg_replace(
>-            '~  (-|&lt;(strike)&gt;)
>-                ([^ \n=](\S?|.*(\S|\t)))
>-                (-|&lt;/\2&gt;)
>-            ~Umix',
>-            '<strike>\3</strike>',
>+        $sStr = preg_replace_callback(
>+            '~  ((-{2}|[_=*/])+)
>+		([^\n_=*/]+)
>+                ((-{2}|[_=*/])+)
>+            ~mix',
>+	    array(&$this,'tokenizeEmphasis'),
>             $sStr
>         );
> 
>-
>-        // Underlined
>-        $sStr = preg_replace(
>-            '~  (_|&lt;(u)&gt;)
>-                ([^ \n=](\S?|.*(\S|\t)))
>-                (_|&lt;/\2&gt;)
>-            ~Umix',
>-            '<u>\3</u>',
>-            $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 {
>+	    return $aMatches[0];
>+	}
>+    }
>+
>     // --------------------------------------------------------------------
> 
>     /**
>@@ -1655,7 +1664,7 @@
> 
>     protected function processJustification(&$sStr) {
>         $sStr = preg_replace_callback(
>-            '=&lt;(left|center|right)&gt;(.*)&lt;/\1&gt;=Ui',
>+            '=&lt;(left|center|right)&gt;(.*)&lt;/\1&gt;=Usi',
> 	    array(&$this, 'tokenizeJustification'),
>             $sStr );
> 
>@@ -1682,7 +1691,7 @@
> 
>         // Treat lists
>         $sStr = preg_replace_callback(
>-            '=\n((\*|#) .*\n)(?! {0,}(\*|#))=Us',
>+            '=\n((\*|#) (.*)\n)(?! {0,}(\*|#))=Us',
>             array(&$this, 'tokenizeList'),
>             $sStr
>         );
>
>File [changed]: class.WikiReverseParser.php
>Url: http://cowiki.tigris.org/source/browse/cowiki/includes/cowiki/class/parse/class.WikiReverseParser.php?r1=1.14&r2=1.15
>Delta lines:  +7 -17
>--------------------
>--- class.WikiReverseParser.php	14 Mar 2005 17:14:59 -0000	1.14
>+++ class.WikiReverseParser.php	15 Mar 2005 17:16:27 -0000	1.15
>@@ -2,7 +2,7 @@
> 
> /**
>  *
>- * $Id: class.WikiReverseParser.php,v 1.14 2005/03/14 17:14:59 cmarble Exp $
>+ * $Id: class.WikiReverseParser.php,v 1.15 2005/03/15 17:16:27 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.14 $
>+ * @version     $Revision: 1.15 $
>  *
>  */
> 
>@@ -135,7 +135,6 @@
>         $sStr = $this->processPosting($sStr);
>         $sStr = $this->processParagraph($sStr);
>         $sStr = $this->processHeading($sStr);
>-        $sStr = $this->processEmphasis($sStr);
>         $sStr = $this->processHorizontalRule($sStr);
>         $sStr = $this->processVariable($sStr);
>         $sStr = $this->processPlugin($sStr);
>@@ -145,6 +144,7 @@
>         $sStr = $this->processSup($sStr);
>         $sStr = $this->processSub($sStr);
> 	$sStr = $this->processJustification($sStr);
>+        $sStr = $this->processEmphasis($sStr);
>         $sStr = $this->processList($sStr);
>         $sStr = $this->processTable($sStr);
>         $sStr = $this->processQuote($sStr);    // last one!
>@@ -437,24 +437,14 @@
> 
> 	//italic
>         $sStr = preg_replace(
>-            '=<em>(.*)</em>=Ums',
>-            '/\1/',
>-            $sStr
>-        );
>-	$sStr = preg_replace(
>-            '=<i>(.*)</i>=Ums',
>-            '/\1/',
>+            '=<(em|i)>(.*)</\1>=Ums',
>+            '/\2/',
>             $sStr
> 	);
> 	//bold
>         $sStr = preg_replace(
>-            '=<strong>(.*)</strong>=Ums',
>-            '*\1*',
>-            $sStr
>-        );
>-        $sStr = preg_replace(
>-            '=<b>(.*)</b>=Ums',
>-            '*\1*',
>+            '=<(strong|b)>(.*)</\1>=Ums',
>+            '*\2*',
>             $sStr
>         );
> 	//monospaced
>@@ -466,7 +456,7 @@
> 	//strikethrough
>         $sStr = preg_replace(
>             '=<strike>(.*)</strike>=Ums',
>-            '-\1-',
>+            '--\1--',
>             $sStr
>         );
> 	//underlined
>@@ -883,7 +873,7 @@
> 
>     protected function processJustification(&$sStr) {
>         $sStr = preg_replace(
>-            '=<(left|center|right)>(.*)</\\1>=Ums',
>+            '=<(left|center|right)>(.*)</\\1>=Usi',
>             "&lt;\\1&gt;\\2&lt;/\\1&gt;",
>             $sStr
>         );
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [email protected]
>For additional commands, e-mail: [email protected]
>
>  
>