protected function formatNewLines(string
$str): string
{ if ($str === ''
|| (strpos($str, "\n"
) === false && !
in_array($this->lastBlockElement,
$this->innerBlockRequired, true
))) { return $str;
} // Convert two consecutive newlines to paragraphs
$str =
str_replace("\n\n", "</p>\n\n<p>",
$str);
// Convert single spaces to <br> tags
$br = '<br' .
_solidus() . '>';
$str =
preg_replace("/([^\n])(\n)([^\n])/", '\\1' .
$br . '\\2\\3',
$str);
// Wrap the whole enchilada in enclosing paragraphs
if ($str !== "\n"
) { // We trim off the right-side new line so that the closing </p> tag
// will be positioned immediately following the string, matching
// the behavior of the opening <p> tag
$str = '<p>' .
rtrim($str) . '</p>';
} // Remove empty paragraphs if they are on the first line, as this