More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
authorDan
Tue, 04 Aug 2009 15:02:54 -0400
changeset 1073 b19a9bcb6a45
parent 1072 604213a07ce0
child 1074 1a4f13626f76
More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
includes/render.php
includes/wikiengine/Tables.php
includes/wikiengine/parse_mediawiki.php
includes/wikiengine/render_xhtml.php
includes/wikiformat.php
--- a/includes/render.php	Tue Aug 04 15:02:00 2009 -0400
+++ b/includes/render.php	Tue Aug 04 15:02:54 2009 -0400
@@ -312,12 +312,13 @@
    * @access private
    */
   
-  public static function tag_unstrip($tag, &$text, &$stripdata)
+  public static function tag_unstrip($tag, &$text, &$stripdata, $keep = false)
   {
     $random_id = $stripdata['random_id'];
     
     foreach ( $stripdata['blocks'] as $i => $block )
     {
+      $block = $keep ? "<$tag>$block</$tag>" : $block;
       $text = str_replace("{{$tag}:{$random_id}:{$i}}", $block, $text);
     }
     
--- a/includes/wikiengine/Tables.php	Tue Aug 04 15:02:00 2009 -0400
+++ b/includes/wikiengine/Tables.php	Tue Aug 04 15:02:54 2009 -0400
@@ -67,7 +67,7 @@
       $attributes = unstripForHTML( $matches[2] );
 
       $t[$k] = str_repeat( '<dl><dd>', $indent_level ) .
-        '<_paragraph_bypass><table' . fixTagAttributes( $attributes, 'table' ) . '>' ;
+        '<table' . fixTagAttributes( $attributes, 'table' ) . '>' ;
       array_push ( $td , false ) ;
       array_push ( $ltd , '' ) ;
       array_push ( $tr , false ) ;
@@ -76,7 +76,7 @@
     }
     else if ( count ( $td ) == 0 ) { } # Don't do any of the following
     else if ( '|}' == substr ( $x , 0 , 2 ) ) {
-      $z = "</table></_paragraph_bypass>" . substr ( $x , 2);
+      $z = "</table>" . substr ( $x , 2);
       $l = array_pop ( $ltd ) ;
       if ( !array_pop ( $has_opened_tr ) ) $z = "<tr><td></td></tr>" . $z ;
       if ( array_pop ( $tr ) ) $z = '</tr>' . $z ;
--- a/includes/wikiengine/parse_mediawiki.php	Tue Aug 04 15:02:00 2009 -0400
+++ b/includes/wikiengine/parse_mediawiki.php	Tue Aug 04 15:02:54 2009 -0400
@@ -133,7 +133,7 @@
       foreach ( $items as $item )
       {
         // get the depth
-        $itemtoken = preg_replace('/[^#:\*].*$/', '', $item);
+        $itemtoken = preg_replace('/^([#:\*]+).*$/s', '$1', $item);
         // get the text
         $itemtext = trim(substr($item, strlen($itemtoken)));
         $piece['items'][] = array(
@@ -142,7 +142,6 @@
             'text' => $itemtext
           );
       }
-      
       $pieces[] = $piece;
     }
     
@@ -151,6 +150,19 @@
     return $pieces;
   }
   
+  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));
+    
+    $text = Carpenter::tokenize($text, $quotes[0]);
+    return $pieces;
+  }
+  
   public function paragraph(&$text)
   {
     // The trick with paragraphs is to not turn things into them when a block level element already wraps the block of text.
@@ -158,7 +170,9 @@
     $blocklevel = 'address|blockquote|center|code|div|dl|fieldset|form|h1|h2|h3|h4|h5|h6|hr|li|ol|p|pre|table|ul|tr|td|th|tbody|thead|tfoot';
     
     // Wrap all block level tags
+    RenderMan::tag_strip('_paragraph_bypass', $text, $_nw);
     $text = preg_replace("/<($blocklevel)(?: .+?>|>)(?:(?R)|.*?)<\/\\1>/s", '<_paragraph_bypass>$0</_paragraph_bypass>', $text);
+    RenderMan::tag_unstrip('_paragraph_bypass', $text, $_nw, true);
     
     // This is potentially a hack. It allows the parser to stick in <_paragraph_bypass> tags
     // to prevent the paragraph parser from interfering with pretty HTML generated elsewhere.
--- a/includes/wikiengine/render_xhtml.php	Tue Aug 04 15:02:00 2009 -0400
+++ b/includes/wikiengine/render_xhtml.php	Tue Aug 04 15:02:54 2009 -0400
@@ -21,7 +21,7 @@
     'italic' => '<em>\\1</em>',
     'underline' => '<span style="text-decoration: underline;">\\1</span>',
     'externalwithtext' => '<a href="\\1" onclick="window.open(this.href); return false;">\\2</a>',
-    'externalnotext' => '<a href="\\1" onclick="window.open(this.href); return false;">\\1</a>',
+    'externalnotext' => '<a href="\\1" onclick="window.open(this.href); return false;">\\1</a>'
   );
   
   public function heading($text, $pieces)
@@ -60,7 +60,7 @@
           $itag = 'dd';
           break;
       }
-      $list = "<$btag>\n";
+      $list = "<_paragraph_bypass><$btag>\n";
       $spacing = '';
       $depth = 1;
       foreach ( $piece['items'] as $j => $item )
@@ -108,12 +108,21 @@
         $spacing = substr($spacing, 4);
         $depth--;
       }
-      $list .= "</$btag>\n";
+      $list .= "</$btag></_paragraph_bypass>\n";
       $text = str_replace(Carpenter::generate_token($i), $list, $text);
     }
     return $text;
   }
   
+  public function blockquote($text, $pieces)
+  {
+    foreach ( $pieces as $i => $piece )
+    {
+      $text = str_replace(Carpenter::generate_token($i), "<blockquote>\n" . nl2br($piece) . "\n</blockquote>\n", $text);
+    }
+    return $text;
+  }
+  
   public function paragraph($text, $pieces)
   {
     foreach ( $pieces as $i => $piece )
--- a/includes/wikiformat.php	Tue Aug 04 15:02:00 2009 -0400
+++ b/includes/wikiformat.php	Tue Aug 04 15:02:54 2009 -0400
@@ -64,6 +64,7 @@
       'heading',
       // note: can't be named list ("list" is a PHP language construct)
       'multilist',
+      'blockquote',
       'bold',
       'italic',
       'underline',