diff --git a/lib/Newsletter/Renderer/Blocks/Text.php b/lib/Newsletter/Renderer/Blocks/Text.php index 38e9b4fef9..6d69ea9999 100644 --- a/lib/Newsletter/Renderer/Blocks/Text.php +++ b/lib/Newsletter/Renderer/Blocks/Text.php @@ -166,7 +166,7 @@ class Text { } static function removeLastLineBreak($html) { - return preg_replace('/(^)?()+$/i', '', $html); + return preg_replace('/(^)?(]*?\/?>)+$/i', '', $html); } static function insertLineBreak($element) { diff --git a/tests/unit/Newsletter/RendererTest.php b/tests/unit/Newsletter/RendererTest.php index a9c9e9fd15..9692c12d15 100644 --- a/tests/unit/Newsletter/RendererTest.php +++ b/tests/unit/Newsletter/RendererTest.php @@ -235,6 +235,14 @@ class NewsletterRendererTest extends MailPoetTest { // headings should be styled expect($DOM('tr > td.mailpoet_text > h1', 0)->attr('style')) ->contains('padding:0;font-style:normal;font-weight:normal;'); + + // trailing line breaks should be cut off, but not inside an element + $template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][8]; + $DOM = $this->DOM_parser->parseStr(Text::render($template)); + expect(count($DOM('tr > td > br', 0))) + ->equals(0); + expect($DOM('tr > td > h3', 0)->html()) + ->contains('Test trailing line breaks removal

\n

Test line breaks
in headings haha




" } ] }