protected function wrap($str)
{
$lines = explode("\n", $str);
$text = '';
foreach ($lines as $line) {
if (strlen($line) > 78) {
if ($line[0] === '>') {
$wrapped = wordwrap($line, 76);
$text .= str_replace("\n", "\n> ", $wrapped) . "\n";
} elseif ($line[0] === '+' || $line[0] === '|') {
$text .= $line . "\n";
} else {
$text .= wordwrap($line, 78) . "\n";
}
} else {
$text .= $line . "\n";
}
}
return $text;
}