diff --git a/lib/Newsletter/Renderer/Blocks/Text.php b/lib/Newsletter/Renderer/Blocks/Text.php
index 0ef7ba5ff7..d3fa560237 100644
--- a/lib/Newsletter/Renderer/Blocks/Text.php
+++ b/lib/Newsletter/Renderer/Blocks/Text.php
@@ -57,14 +57,7 @@ class Text {
'
);
- $blockquote->parent->insertChild(
- array(
- 'tag_name' => 'br',
- 'self_close' => true,
- 'attributes' => array()
- ),
- $blockquote->index() + 1
- );
+ $blockquote = self::insertLineBreak($blockquote);
}
return $DOM->__toString();
}
@@ -75,8 +68,25 @@ class Text {
$paragraphs = $DOM->query('p');
if(!$paragraphs->count()) return $html;
foreach($paragraphs as $paragraph) {
- // remove empty paragraphs
+ // process empty paragraphs
if(!trim($paragraph->html())) {
+ $next_element = ($paragraph->getNextSibling()) ?
+ trim($paragraph->getNextSibling()->text()) :
+ false;
+ $previous_element = ($paragraph->getPreviousSibling()) ?
+ trim($paragraph->getPreviousSibling()->text()) :
+ false;
+ $previous_element_tag = ($previous_element) ?
+ $paragraph->getPreviousSibling()->tag :
+ false;
+ // if previous or next paragraphs are empty OR previous paragraph
+ // is a heading, insert a break line
+ if (!$next_element ||
+ !$previous_element ||
+ (preg_match('/h\d+/', $previous_element_tag))
+ ) {
+ $paragraph = self::insertLineBreak($paragraph);
+ }
$paragraph->remove();
continue;
}
@@ -91,9 +101,13 @@ class Text {
$paragraph->cellpadding = 0;
$next_element = $paragraph->getNextSibling();
// unless this is the last element in column, add double line breaks
- $line_breaks = ($next_element && !$next_element->getInnerText()) ? '
' : '';
+ $line_breaks = ($next_element && !trim($next_element->text())) ?
+ '
' :
+ '';
// if this element is followed by a list, add single line break
- $line_breaks = ($next_element && preg_match('/