Commit c8f8f654 by Carsten Brandt

fixed paragraph formatting

parent d8219570
...@@ -31,7 +31,7 @@ use yii\helpers\Html; ...@@ -31,7 +31,7 @@ use yii\helpers\Html;
* The Formatter class is designed to format values according to a [[locale]]. For this feature to work * The Formatter class is designed to format values according to a [[locale]]. For this feature to work
* the [PHP intl extension](http://php.net/manual/en/book.intl.php) has to be installed. * the [PHP intl extension](http://php.net/manual/en/book.intl.php) has to be installed.
* Most of the methods however work also if the PHP intl extension is not installed by providing * Most of the methods however work also if the PHP intl extension is not installed by providing
* a fallback implementation. Without intl month and day names are in english only. * a fallback implementation. Without intl month and day names are in English only.
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @author Enrica Ruedin <e.ruedin@guggach.com> * @author Enrica Ruedin <e.ruedin@guggach.com>
...@@ -278,7 +278,7 @@ class Formatter extends Component ...@@ -278,7 +278,7 @@ class Formatter extends Component
if ($value === null) { if ($value === null) {
return $this->nullDisplay; return $this->nullDisplay;
} }
return str_replace('<p></p>', '', '<p>' . preg_replace('/[\r\n]{2,}/', "</p>\n<p>", Html::encode($value)) . '</p>'); return str_replace('<p></p>', '', '<p>' . preg_replace('/\R{2,}/', "</p>\n<p>", Html::encode($value)) . '</p>');
} }
/** /**
......
...@@ -145,6 +145,18 @@ class FormatterTest extends TestCase ...@@ -145,6 +145,18 @@ class FormatterTest extends TestCase
$this->assertSame("<p>123</p>\n<p>456</p>", $this->formatter->asParagraphs($value)); $this->assertSame("<p>123</p>\n<p>456</p>", $this->formatter->asParagraphs($value));
$value = "123\n\n\n456"; $value = "123\n\n\n456";
$this->assertSame("<p>123</p>\n<p>456</p>", $this->formatter->asParagraphs($value)); $this->assertSame("<p>123</p>\n<p>456</p>", $this->formatter->asParagraphs($value));
$value = "123\r\n456";
$this->assertSame("<p>123\r\n456</p>", $this->formatter->asParagraphs($value));
$value = "123\r\n\r\n456";
$this->assertSame("<p>123</p>\n<p>456</p>", $this->formatter->asParagraphs($value));
$value = "123\r\n\r\n\r\n456";
$this->assertSame("<p>123</p>\n<p>456</p>", $this->formatter->asParagraphs($value));
$value = "123\r456";
$this->assertSame("<p>123\r456</p>", $this->formatter->asParagraphs($value));
$value = "123\r\r456";
$this->assertSame("<p>123</p>\n<p>456</p>", $this->formatter->asParagraphs($value));
$value = "123\r\r\r456";
$this->assertSame("<p>123</p>\n<p>456</p>", $this->formatter->asParagraphs($value));
// null display // null display
$this->assertSame($this->formatter->nullDisplay, $this->formatter->asParagraphs(null)); $this->assertSame($this->formatter->nullDisplay, $this->formatter->asParagraphs(null));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment