diff -r bdbb49cf6f1b -r e6b14d33ac55 includes/render.php --- a/includes/render.php Sat Jul 11 20:25:50 2009 -0400 +++ b/includes/render.php Sat Jul 11 20:28:03 2009 -0400 @@ -717,38 +717,54 @@ $input = trim($input); if ( $newlinemode ) { - $result = preg_match_all('/ - (?:^|[\s]*)\|? # start of parameter - string start or series of spaces - [ ]* - (?: - ([A-z0-9_]+) # variable name - [ ]* = [ ]* # assignment - )? # this is optional - if the parameter name is not given, a numerical index is assigned - (.+) # value - /x', trim($input), $matches); + // we're going by newlines. + // split by parameter, then parse each one individually + $input = explode("\n", str_replace("\r", '', $input)); + $lastparam = ''; + $i = 0; + foreach ( $input as $line ) + { + if ( preg_match('/^ *\|? *([A-z0-9_]+) *= *(.+)$/', $line, $match) ) + { + // new parameter, named + $parms[ $match[1] ] = $match[2]; + $lastparam = $match[1]; + } + else if ( preg_match('/^ *\| *(.+)$/', $line, $match) || $lastparam === '' ) + { + $parms[ $i ] = $match[1]; + $lastparam = $i; + $i++; + } + else + { + $parms[ $lastparam ] .= "\n$line"; + } + } } else { $result = preg_match_all('/ - (?:^|[ ]*)\| # start of parameter - string start or series of spaces - [ ]* - (?: - ([A-z0-9_]+) # variable name - [ ]* = [ ]* # assignment - )? # name section is optional - if the parameter name is not given, a numerical index is assigned - ([^\|]+|.+?\n[ ]*\|) # value - /x', trim($input), $matches); - } - if ( $result ) - { - $pi = 0; - for ( $i = 0; $i < count($matches[0]); $i++ ) + (?:^|[ ]*)\| # start of parameter - string start or series of spaces + [ ]* + (?: + ([A-z0-9_]+) # variable name + [ ]* = [ ]* # assignment + )? # name section is optional - if the parameter name is not given, a numerical index is assigned + ([^\|]+|.+?\n[ ]*\|) # value + /x', trim($input), $matches); + if ( $result ) { - $matches[1][$i] = trim($matches[1][$i]); - $parmname = !empty($matches[1][$i]) ? $matches[1][$i] : strval(++$pi); - $parms[ $parmname ] = $matches[2][$i]; + $pi = 0; + for ( $i = 0; $i < count($matches[0]); $i++ ) + { + $matches[1][$i] = trim($matches[1][$i]); + $parmname = !empty($matches[1][$i]) ? $matches[1][$i] : strval(++$pi); + $parms[ $parmname ] = $matches[2][$i]; + } } } + // die('
' . print_r($parms, true) . ''); return $parms; } @@ -782,7 +798,7 @@ /isxU"; if ( $count = preg_match_all($template_regex, $text, $matches) ) { - //die('
' . print_r($matches, true) . ''); + // die('
' . print_r($matches, true) . ''); for ( $i = 0; $i < $count; $i++ ) { $matches[1][$i] = sanitize_page_id($matches[1][$i]); @@ -801,6 +817,38 @@ } if ( $tpl_code = RenderMan::fetch_template_text($matches[1][$i]) ) { + // Intelligent paragraphs. + // If: + // * A line is fully wrapped in a
tag + // * The line contains a variable + // * The variable contains newlines + // Then: + // * Drop the
tag, replace it fully paragraph-ized by newlines + + if ( preg_match_all('/^( *)
(.*?\{([A-z0-9]+)\}.*?)<\/p> *$/m', $tpl_code, $paramatch) ) + { + $parser = new Carpenter(); + $parser->exclusive_rule('paragraph'); + + foreach ( $paramatch[0] as $j => $match ) + { + // $line is trimmed (the
is gone) + $spacing =& $paramatch[1][$i]; + $para_attrs =& $paramatch[2][$j]; + $para_attrs = str_replace(array('$', '\\'), array('\$', '\\\\'), $para_attrs); + $line =& $paramatch[3][$j]; + $varname =& $paramatch[4][$j]; + if ( isset($parms[$varname]) && strstr($parms[$varname], "\n") ) + { + $newline = str_replace('{' . $varname . '}', $parms[$varname], $line); + $paraized = $parser->render($newline); + $paraized = preg_replace('/^
/m', "$spacing
", $paraized); + $paraized = $spacing . trim($paraized); + $tpl_code = str_replace_once($match, $paraized, $tpl_code); + } + } + } + $parser = $template->makeParserText($tpl_code); $parser->assign_vars($parms); $text = str_replace($matches[0][$i], $parser->run(), $text);