mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
update textformat to not output wrap chars after last para
This commit is contained in:
2
NEWS
2
NEWS
@@ -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
|
||||
|
@@ -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: */
|
||||
|
Reference in New Issue
Block a user