diff --git a/mailpoet/lib/EmailEditor/Integrations/Core/Initializer.php b/mailpoet/lib/EmailEditor/Integrations/Core/Initializer.php index f4b594d958..0616398ff2 100644 --- a/mailpoet/lib/EmailEditor/Integrations/Core/Initializer.php +++ b/mailpoet/lib/EmailEditor/Integrations/Core/Initializer.php @@ -16,7 +16,7 @@ class Initializer { * Register core blocks email renderers when the blocks renderer is initialized. */ public function registerCoreBlocksRenderers(BlocksRegistry $blocksRegistry): void { - $blocksRegistry->addBlockRenderer('core/paragraph', new Renderer\Blocks\Paragraph()); + $blocksRegistry->addBlockRenderer('core/paragraph', new Renderer\Blocks\Text()); $blocksRegistry->addBlockRenderer('core/heading', new Renderer\Blocks\Text()); $blocksRegistry->addBlockRenderer('core/column', new Renderer\Blocks\Column()); $blocksRegistry->addBlockRenderer('core/columns', new Renderer\Blocks\Columns()); diff --git a/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Paragraph.php b/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Paragraph.php index 9af5654e8c..dc2eb5dc91 100644 --- a/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Paragraph.php +++ b/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Paragraph.php @@ -18,7 +18,6 @@ class Paragraph extends AbstractBlockRenderer { private function getBlockWrapper(string $blockContent, array $parsedBlock, SettingsController $settingsController): string { $themeData = $settingsController->getTheme()->get_data(); $classes = (new DomDocumentHelper($blockContent))->getAttributeValueByTagName('p', 'class') ?? ''; - $align = $parsedBlock['attrs']['align'] ?? 'left'; $styles = [ 'text-align' => $align, diff --git a/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Text.php b/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Text.php index 2bb5d6c78b..cb03136378 100644 --- a/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Text.php +++ b/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Text.php @@ -3,7 +3,6 @@ namespace MailPoet\EmailEditor\Integrations\Core\Renderer\Blocks; use MailPoet\EmailEditor\Engine\SettingsController; -use MailPoet\EmailEditor\Integrations\Utils\DomDocumentHelper; /** * This renderer covers both core/paragraph and core/heading blocks @@ -11,15 +10,18 @@ use MailPoet\EmailEditor\Integrations\Utils\DomDocumentHelper; class Text extends AbstractBlockRenderer { protected function renderContent(string $blockContent, array $parsedBlock, SettingsController $settingsController): string { $blockContent = $this->adjustStyleAttribute($blockContent); - return str_replace('{heading_content}', $blockContent, $this->getBlockWrapper($blockContent, $parsedBlock, $settingsController)); + return str_replace('{heading_content}', $blockContent, $this->getBlockWrapper($blockContent, $parsedBlock)); } /** * Based on MJML */ - private function getBlockWrapper($blockContent, array $parsedBlock, SettingsController $settingsController): string { - $level = $parsedBlock['attrs']['level'] ?? 2; // default level is 2 - $classes = (new DomDocumentHelper($blockContent))->getAttributeValueByTagName("h$level", 'class') ?? ''; + private function getBlockWrapper($blockContent, array $parsedBlock): string { + $html = new \WP_HTML_Tag_Processor($blockContent); + $classes = ''; + if ($html->next_tag()) { + $classes = $html->get_attribute('class') ?? ''; + } $blockStyles = $this->getStylesFromBlock([ 'color' => $parsedBlock['attrs']['style']['color'] ?? [], @@ -31,11 +33,14 @@ class Text extends AbstractBlockRenderer { 'min-width' => '100%', // prevent Gmail App from shrinking the table on mobile devices ]; + $styles['text-align'] = 'left'; if (isset($parsedBlock['attrs']['textAlign'])) { $styles['text-align'] = $parsedBlock['attrs']['textAlign']; + } elseif (in_array($parsedBlock['attrs']['align'] ?? null, ['left', 'center', 'right'])) { + $styles['text-align'] = $parsedBlock['attrs']['align']; } - $styles = $this->compileCss($blockStyles['declarations'], $styles); + $compiledStyles = $this->compileCss($blockStyles['declarations'], $styles); return ' @@ -48,7 +53,7 @@ class Text extends AbstractBlockRenderer { width="100%" > - + {heading_content} diff --git a/mailpoet/tests/integration/EmailEditor/Integration/Core/Renderer/Blocks/HeadingTest.php b/mailpoet/tests/integration/EmailEditor/Integration/Core/Renderer/Blocks/HeadingTest.php index 0aba817640..f390860ae8 100644 --- a/mailpoet/tests/integration/EmailEditor/Integration/Core/Renderer/Blocks/HeadingTest.php +++ b/mailpoet/tests/integration/EmailEditor/Integration/Core/Renderer/Blocks/HeadingTest.php @@ -26,7 +26,6 @@ class HeadingTest extends \MailPoetTest { ], 'email_attrs' => [ 'width' => '640px', - 'font-size' => '24px', ], 'innerBlocks' => [], 'innerHTML' => '

This is Heading 1

', diff --git a/mailpoet/tests/integration/EmailEditor/Integration/Core/Renderer/Blocks/ParagraphTest.php b/mailpoet/tests/integration/EmailEditor/Integration/Core/Renderer/Blocks/ParagraphTest.php index 2446169f11..45d5a3179c 100644 --- a/mailpoet/tests/integration/EmailEditor/Integration/Core/Renderer/Blocks/ParagraphTest.php +++ b/mailpoet/tests/integration/EmailEditor/Integration/Core/Renderer/Blocks/ParagraphTest.php @@ -6,14 +6,18 @@ use MailPoet\EmailEditor\Engine\EmailEditor; use MailPoet\EmailEditor\Engine\SettingsController; class ParagraphTest extends \MailPoetTest { - /** @var Paragraph */ + /** @var Text */ private $paragraphRenderer; /** @var array */ private $parsedParagraph = [ 'blockName' => 'core/paragraph', - 'email_attrs' => [ - 'font-size' => '16px', + 'attrs' => [ + 'style' => [ + 'typography' => [ + 'fontSize' => '16px', + ], + ], ], 'innerBlocks' => [], 'innerHTML' => '

Lorem Ipsum

', @@ -27,7 +31,7 @@ class ParagraphTest extends \MailPoetTest { public function _before() { $this->diContainer->get(EmailEditor::class)->initialize(); - $this->paragraphRenderer = new Paragraph(); + $this->paragraphRenderer = new Text(); $this->settingsController = $this->diContainer->get(SettingsController::class); }