Fix last <br/> removal cutting off text when rendering a text block [MAILPOET-856]

This commit is contained in:
Alexey Stoletniy
2017-04-06 10:07:11 +03:00
parent 66d969cc2f
commit 37fcd5699b
3 changed files with 13 additions and 1 deletions

View File

@@ -166,7 +166,7 @@ class Text {
}
static function removeLastLineBreak($html) {
return preg_replace('/(^)?(<br.*?\/?>)+$/i', '', $html);
return preg_replace('/(^)?(<br[^>]*?\/?>)+$/i', '', $html);
}
static function insertLineBreak($element) {

View File

@@ -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('<a');
}
function testItRendersDivider() {

View File

@@ -207,6 +207,10 @@
"textAlign": "center"
}
}
},
{
"type": "text",
"text": "<p>Test trailing line breaks removal</p>\n<h3>Test line breaks <br/> in headings <a href=\"http://www.example.org\">haha</a></h3><br /><br><br/>"
}
]
}