# HG changeset patch
# User Dan
# Date 1249412574 14400
# Node ID b19a9bcb6a450f91fef445c6653155520ea119be
# Parent 604213a07ce0e69801d7dd75b3187ba93b007d19
More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
diff -r 604213a07ce0 -r b19a9bcb6a45 includes/render.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);
}
diff -r 604213a07ce0 -r b19a9bcb6a45 includes/wikiengine/Tables.php
--- 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( '
- ', $indent_level ) .
- '<_paragraph_bypass>
' ;
+ '' ;
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 = "
" . substr ( $x , 2);
+ $z = "
" . substr ( $x , 2);
$l = array_pop ( $ltd ) ;
if ( !array_pop ( $has_opened_tr ) ) $z = " |
" . $z ;
if ( array_pop ( $tr ) ) $z = '' . $z ;
diff -r 604213a07ce0 -r b19a9bcb6a45 includes/wikiengine/parse_mediawiki.php
--- 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', $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.
diff -r 604213a07ce0 -r b19a9bcb6a45 includes/wikiengine/render_xhtml.php
--- 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' => '\\1',
'underline' => '\\1',
'externalwithtext' => '\\2',
- 'externalnotext' => '\\1',
+ 'externalnotext' => '\\1'
);
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>\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), "\n" . nl2br($piece) . "\n
\n", $text);
+ }
+ return $text;
+ }
+
public function paragraph($text, $pieces)
{
foreach ( $pieces as $i => $piece )
diff -r 604213a07ce0 -r b19a9bcb6a45 includes/wikiformat.php
--- 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',