- Enables dynamic line-height based on font-size

This commit is contained in:
Vlad
2016-04-08 15:16:11 -04:00
parent 813db1ae33
commit ba40437eb9
5 changed files with 26 additions and 11 deletions

View File

@@ -7,6 +7,9 @@ class Footer {
static function render($element) {
$element['text'] = preg_replace('/\n/', '<br /><br />', $element['text']);
$element['text'] = preg_replace('/(<\/?p.*?>)/i', '', $element['text']);
$line_height = sprintf(
'%spx', StylesHelper::$line_height_multiplier * (int) $element['styles']['text']['fontSize']
);
$DOM_parser = new \pQuery();
$DOM = $DOM_parser->parseStr($element['text']);
if(isset($element['styles']['link'])) {
@@ -25,7 +28,7 @@ class Footer {
$template = '
<tr>
<td class="mailpoet_header_footer_padded mailpoet_footer" ' . $background_color . '
style="line-height: ' . StylesHelper::$line_height . ';' . StylesHelper::getBlockStyles($element) . StylesHelper::getStyles($element['styles'], 'text') . '">
style="line-height: ' . $line_height . ';' . StylesHelper::getBlockStyles($element) . StylesHelper::getStyles($element['styles'], 'text') . '">
' . $DOM->html() . '
</td>
</tr>';

View File

@@ -6,7 +6,10 @@ use MailPoet\Newsletter\Renderer\StylesHelper;
class Header {
static function render($element) {
$element['text'] = preg_replace('/\n/', '<br /><br />', $element['text']);
$element['text'] = preg_replace('/(<\/?p.*?>)/', '', $element['text']);
$element['text'] = preg_replace('/(<\/?p.*?>)/i', '', $element['text']);
$line_height = sprintf(
'%spx', StylesHelper::$line_height_multiplier * (int) $element['styles']['text']['fontSize']
);
$DOM_parser = new \pQuery();
$DOM = $DOM_parser->parseStr($element['text']);
if(isset($element['styles']['link'])) {
@@ -25,8 +28,8 @@ class Header {
$template = '
<tr>
<td class="mailpoet_header_footer_padded mailpoet_header" ' . $background_color . '
style="' . StylesHelper::getBlockStyles($element) . StylesHelper::getStyles($element['styles'], 'text') . '">
' . $DOM->html() . '
style="line-height: ' . $line_height . ';' . StylesHelper::getBlockStyles($element) . StylesHelper::getStyles($element['styles'], 'text') . '">
' . $DOM->html() . '
</td>
</tr>';
return $template;

View File

@@ -95,7 +95,7 @@ class Text {
$line_breaks = ($next_element && preg_match('/<li>/i', $next_element->getInnerText())) ? '<br />' : $line_breaks;
$paragraph->html('
<tr>
<td class="mailpoet_paragraph" style="line-height:' . StylesHelper::$line_height . ';word-break:break-word;word-wrap:break-word;' . $style . '">
<td class="mailpoet_paragraph" style="word-break:break-word;word-wrap:break-word;' . $style . '">
' . $contents . $line_breaks . '
</td>
</tr>'
@@ -117,7 +117,7 @@ class Text {
$list->class = 'mailpoet_paragraph';
$list->style .= 'padding-top:0;padding-bottom:0;margin-top:10px;';
}
$list->style .= 'margin-bottom:10px;line-height:' . StylesHelper::$line_height . ';';
$list->style .= 'margin-bottom:10px;';
}
return $DOM->__toString();
}
@@ -128,7 +128,7 @@ class Text {
$headings = $DOM->query('h1, h2, h3, h4');
if(!$headings->count()) return $html;
foreach($headings as $heading) {
$heading->style .= 'line-height:' . StylesHelper::$line_height . ';padding:0;font-style:normal;font-weight:normal;';
$heading->style .= 'padding:0;font-style:normal;font-weight:normal;';
}
return $DOM->__toString();
}