Fix text align

[MAILPOET-3473]
This commit is contained in:
Pavel Dohnal
2021-03-11 13:34:55 +01:00
committed by Veljko V
parent 13a2dce867
commit deb4d7833d
3 changed files with 25 additions and 3 deletions

View File

@@ -147,10 +147,10 @@ class Text {
$list->class = 'mailpoet_paragraph';
} else {
$list->class = 'mailpoet_paragraph';
$list->style .= 'padding-top:0;padding-bottom:0;margin-top:10px;';
$list->style = StylesHelper::joinStyles($list->style, 'padding-top:0;padding-bottom:0;margin-top:10px;');
}
$list->style = StylesHelper::applyTextAlignment($list->style);
$list->style .= 'margin-bottom:10px;';
$list->style = StylesHelper::joinStyles($list->style, 'margin-bottom:10px;');
$list->style = EHelper::escapeHtmlStyleAttr($list->style);
}
return $DOM->__toString();
@@ -163,7 +163,7 @@ class Text {
if (!$headings->count()) return $html;
foreach ($headings as $heading) {
$heading->style = StylesHelper::applyTextAlignment($heading->style);
$heading->style .= 'padding:0;font-style:normal;font-weight:normal;';
$heading->style = StylesHelper::joinStyles($heading->style, 'padding:0;font-style:normal;font-weight:normal;');
$heading->style = EHelper::escapeHtmlStyleAttr($heading->style);
}
return $DOM->__toString();

View File

@@ -113,6 +113,22 @@ class StylesHelper {
$block . 'text-align:left;';
}
/**
* Join styles and makes sure they are separated by ;
*/
public static function joinStyles(?string $styles1, ?string $styles2): string {
if ($styles1 === null) $styles1 = '';
if ($styles2 === null) $styles2 = '';
$style = trim($styles1);
if (
(strlen($style) > 0)
&& (substr($style, -1) !== ';')
) $style .= ';';
$style .= $styles2;
return $style;
}
public static function applyFontFamily($attribute, $style) {
if ($attribute !== 'fontFamily') return $style;
return (isset(self::$font[$style])) ?

View File

@@ -109,6 +109,12 @@ class TextTest extends \MailPoetUnitTest {
expect($output)->stringContainsString('<h2 style="text-align:left;padding:0;font-style:normal;font-weight:normal;">Heading 2</h2>');
}
public function testItStylesHeadingsCenter() {
$this->block['text'] = '<h1 style="text-align: center"><strong>Let\'s Get Started! </strong></h1>';
$output = (new Text)->render($this->block);
expect($output)->stringContainsString('<h1 style="text-align: center;padding:0;');
}
public function testItRemovesLastLineBreak() {
$this->block['text'] = 'hello<br />';
$output = (new Text)->render($this->block);