From 22691a7343bed82b874875c259b124841dee3743 Mon Sep 17 00:00:00 2001 From: Arkadiusz Filipczak Date: Fri, 18 Nov 2022 09:50:18 +0100 Subject: [PATCH 1/2] Upcasts img with display:block as block image --- packages/ckeditor5-image/src/image/utils.js | 4 +++- packages/ckeditor5-image/tests/image/utils.js | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/ckeditor5-image/src/image/utils.js b/packages/ckeditor5-image/src/image/utils.js index 8b019900eb2..b7b77e7b127 100644 --- a/packages/ckeditor5-image/src/image/utils.js +++ b/packages/ckeditor5-image/src/image/utils.js @@ -69,7 +69,9 @@ export function getImgViewElementMatcher( editor, matchImageType ) { // The can be standalone, wrapped in
...
(ImageBlock plugin) or // wrapped in
...
(LinkImage plugin). - const imageType = element.findAncestor( imageUtils.isBlockImageView ) ? 'imageBlock' : 'imageInline'; + const imageType = element.getStyle( 'display' ) == 'block' || element.findAncestor( imageUtils.isBlockImageView ) ? + 'imageBlock' : + 'imageInline'; if ( imageType !== matchImageType ) { return null; diff --git a/packages/ckeditor5-image/tests/image/utils.js b/packages/ckeditor5-image/tests/image/utils.js index fac5c51285f..9f89ad02fc4 100644 --- a/packages/ckeditor5-image/tests/image/utils.js +++ b/packages/ckeditor5-image/tests/image/utils.js @@ -264,6 +264,15 @@ describe( 'image utils', () => { } ); } ); + it( 'should return a matcherPattern object if the element has `display:block` style', () => { + element = writer.createElement( 'img', { src: 'sample.jpg', style: 'display:block' } ); + + expect( matcherPattern( element ) ).to.deep.equal( { + name: true, + attributes: [ 'src' ] + } ); + } ); + it( 'should not include "src" in the matcher pattern if the image has no "src"', () => { element = writer.createElement( 'img' ); writer.appendChild( element, writer.createElement( 'figure', { class: 'image' } ) ); From a96333f7073affad985b67ec5247e8b283a8c19c Mon Sep 17 00:00:00 2001 From: Arkadiusz Filipczak Date: Mon, 21 Nov 2022 11:24:39 +0100 Subject: [PATCH 2/2] Added test for block image (display:block) --- packages/ckeditor5-image/tests/image/imageediting.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/ckeditor5-image/tests/image/imageediting.js b/packages/ckeditor5-image/tests/image/imageediting.js index 6dc02cb79e5..2c081216d6e 100644 --- a/packages/ckeditor5-image/tests/image/imageediting.js +++ b/packages/ckeditor5-image/tests/image/imageediting.js @@ -312,6 +312,13 @@ describe( 'ImageEditing', () => { .to.equal( '' ); } ); + it( 'should convert image with `display:block` style', () => { + editor.setData( '

alt text

' ); + + expect( getModelData( model, { withoutSelection: true } ) ) + .to.equal( '' ); + } ); + it( 'should not convert if there is no image class in figure', () => { editor.setData( '
My quote
' );