Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
authorDan
Sun, 09 Aug 2009 01:27:45 -0400
changeset 1078 67a4c839c7e1
parent 1077 7f621a3a9cbf
child 1079 fcc42560afe6
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
includes/wikiengine/parse_mediawiki.php
includes/wikiengine/render_xhtml.php
includes/wikiformat.php
--- a/includes/wikiengine/parse_mediawiki.php	Sun Aug 09 01:26:57 2009 -0400
+++ b/includes/wikiengine/parse_mediawiki.php	Sun Aug 09 01:27:45 2009 -0400
@@ -22,6 +22,8 @@
     'externalnotext' => '#\[((?:https?|irc|ftp)://.+?)\]#'
   );
   
+  private $blockquote_rand_id;
+  
   public function lang(&$text)
   {
     global $lang;
@@ -152,15 +154,24 @@
   
   public function blockquote(&$text)
   {
-    if ( !preg_match_all('/^(?:(>+) *.+(?:\r?\n|$))+/m', $text, $quotes) )
-      return array();
-   
-    $pieces = array();
-    foreach ( $quotes[0] as $quote )
-      $pieces[] = "\t" . trim(preg_replace('/^>+ */m', "\t", $quote));
+    $rand_id = hexencode(AESCrypt::randkey(16), '', '');
     
-    $text = Carpenter::tokenize($text, $quotes[0]);
-    return $pieces;
+    while ( preg_match_all('/^(?:(>+) *.+(?:\r?\n|$))+/m', $text, $quotes) )
+    {
+      foreach ( $quotes[0] as $quote )
+      {
+        $piece = trim(preg_replace('/^> */m', '', $quote));
+        $text = str_replace_once($quote, "{blockquote:$rand_id}\n$piece\n{/blockquote:$rand_id}\n", $text);
+      }
+    }
+    //die('<pre>' . htmlspecialchars($text) . '</pre>');
+    
+    $this->blockquote_rand_id = $rand_id;
+  }
+  
+  public function blockquotepost(&$text)
+  {
+    return $this->blockquote_rand_id;
   }
   
   public function paragraph(&$text)
--- a/includes/wikiengine/render_xhtml.php	Sun Aug 09 01:26:57 2009 -0400
+++ b/includes/wikiengine/render_xhtml.php	Sun Aug 09 01:27:45 2009 -0400
@@ -114,12 +114,23 @@
     return $text;
   }
   
-  public function blockquote($text, $pieces)
+  public function blockquote($text)
+  {
+    return $text;
+  }
+  
+  public function blockquotepost($text, $rand_id)
   {
-    foreach ( $pieces as $i => $piece )
-    {
-      $text = str_replace(Carpenter::generate_token($i), "<blockquote>\n" . nl2br($piece) . "\n</blockquote>\n", $text);
-    }
+    $text = strtr($text, array(
+        "<p>{blockquote:$rand_id}<br />"  => '<blockquote>',
+        "<br />\n{/blockquote:$rand_id}</p>" => '</blockquote>',
+        "{blockquote:$rand_id}"  => '<blockquote>',
+        "{/blockquote:$rand_id}" => '</blockquote>'
+      ));
+    $text = strtr($text, array(
+        "<blockquote><br />" => '<blockquote>',
+        "</blockquote><br />" => '</blockquote>'
+      ));
     return $text;
   }
   
--- a/includes/wikiformat.php	Sun Aug 09 01:26:57 2009 -0400
+++ b/includes/wikiformat.php	Sun Aug 09 01:27:45 2009 -0400
@@ -60,11 +60,11 @@
   private $rules = array(
       'lang',
       'templates',
+      'blockquote',
       'tables',
       'heading',
       // note: can't be named list ("list" is a PHP language construct)
       'multilist',
-      'blockquote',
       'bold',
       'italic',
       'underline',
@@ -72,7 +72,8 @@
       'externalnotext',
       'image',
       'internallink',
-      'paragraph'
+      'paragraph',
+      'blockquotepost'
     );
   
   /**