update textformat to not output wrap chars after last para

This commit is contained in:
mohrt
2004-05-07 22:50:11 +00:00
parent 0262f49c6a
commit bcb1d2a196
2 changed files with 13 additions and 14 deletions

2
NEWS
View File

@@ -1,3 +1,5 @@
- adjusted textformat to not output wrap chars after last para
(Monte)
- use tempnam() instead of unqid() to create better temporary files in
smarty_core_write_file() (xces, messju)
- add 'mail' to escape modifier for safe display of e-mail

View File

@@ -71,33 +71,30 @@ function smarty_block_textformat($params, $content, &$smarty)
}
// split into paragraphs
$paragraphs = preg_split('![\r\n][\r\n]!',$content);
$output = '';
$_paragraphs = preg_split('![\r\n][\r\n]!',$content);
$_output = '';
foreach ($paragraphs as $paragraph) {
if ($paragraph == '') {
for($_x = 0, $_y = count($_paragraphs); $_x < $_y; $_x++) {
if ($_paragraphs[$_x] == '') {
continue;
}
// convert mult. spaces & special chars to single space
$paragraph = preg_replace(array('!\s+!','!(^\s+)|(\s+$)!'),array(' ',''),$paragraph);
$_paragraphs[$_x] = preg_replace(array('!\s+!','!(^\s+)|(\s+$)!'), array(' ',''), $_paragraphs[$_x]);
// indent first line
if($indent_first > 0) {
$paragraph = str_repeat($indent_char,$indent_first) . $paragraph;
$_paragraphs[$_x] = str_repeat($indent_char, $indent_first) . $_paragraphs[$_x];
}
// wordwrap sentences
$paragraph = wordwrap($paragraph, $wrap - $indent, $wrap_char, $wrap_cut);
$_paragraphs[$_x] = wordwrap($_paragraphs[$_x], $wrap - $indent, $wrap_char, $wrap_cut);
// indent lines
if($indent > 0) {
$paragraph = preg_replace('!^!m',str_repeat($indent_char,$indent),$paragraph);
$_paragraphs[$_x] = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraphs[$_x]);
}
$output .= $paragraph . $wrap_char . $wrap_char;
}
$_output = implode($wrap_char . $wrap_char, $_paragraphs);
return $assign ? $smarty->assign($assign, $_output) : $_output;
if ($assign) {
$smarty->assign($assign,$output);
} else {
return $output;
}
}
/* vim: set expandtab: */