Use image alignment from <figure> or <img>

[MAILPOET-1684]
This commit is contained in:
Jan Jakeš
2019-01-07 18:07:23 +01:00
parent 4d97a2f6a7
commit 88f14575dc
2 changed files with 17 additions and 4 deletions

View File

@ -49,7 +49,7 @@ class PostContentManager {
'<a>', '<ul>', '<ol>', '<li>', '<br>', '<blockquote>'
);
if($display_type === 'full') {
$tags_not_being_stripped = array_merge($tags_not_being_stripped, array('<img>', '<h1>', '<h2>', '<h3>'));
$tags_not_being_stripped = array_merge($tags_not_being_stripped, array('<figure>', '<img>', '<h1>', '<h2>', '<h3>'));
}
$content = strip_tags($content, implode('', $tags_not_being_stripped));

View File

@ -26,7 +26,7 @@ class StructureTransformer {
$top_ancestor = DOMUtil::findTopAncestor($item);
$offset = $top_ancestor->index();
if($item->hasParent('a')) {
if($item->hasParent('a') || $item->hasParent('figure')) {
$item = $item->parent;
}
@ -40,8 +40,21 @@ class StructureTransformer {
*/
private function transformTagsToBlocks($root, $image_full_width) {
return array_map(function($item) use ($image_full_width) {
if($item->tag === 'img' || $item->tag === 'a' && $item->query('img')) {
if($item->tag === 'img' || in_array($item->tag, ['a', 'figure'], true) && $item->query('img')) {
$image = $item->tag === 'img' ? $item : $item->query('img')[0];
// when <figure> exist, it carries align class, otherwise it's on <img>
$alignItem = $item->tag === 'figure' ? $item : $image;
if($alignItem->hasClass('aligncenter')) {
$align = 'center';
} elseif($alignItem->hasClass('alignleft')) {
$align = 'left';
} elseif($alignItem->hasClass('alignright')) {
$align = 'right';
} else {
$align = 'left';
}
$width = $image->getAttribute('width');
$height = $image->getAttribute('height');
return array(
@ -54,7 +67,7 @@ class StructureTransformer {
'height' => $height === null ? 'auto' : $height,
'styles' => array(
'block' => array(
'textAlign' => 'center',
'textAlign' => $align,
),
),
);