Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upcasts img with display:block as block image #12876

Merged
merged 2 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/ckeditor5-image/src/image/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export function getImgViewElementMatcher( editor, matchImageType ) {

// The <img> can be standalone, wrapped in <figure>...</figure> (ImageBlock plugin) or
// wrapped in <figure><a>...</a></figure> (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;
Expand Down
7 changes: 7 additions & 0 deletions packages/ckeditor5-image/tests/image/imageediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,13 @@ describe( 'ImageEditing', () => {
.to.equal( '<paragraph><imageInline alt="alt text" src="/assets/sample.png"></imageInline></paragraph>' );
} );

it( 'should convert image with `display:block` style', () => {
editor.setData( '<p><img src="/asserts/sample.png" alt="alt text" style="display:block" /></p>' );

expect( getModelData( model, { withoutSelection: true } ) )
.to.equal( '<imageBlock alt="alt text" src="/asserts/sample.png"></imageBlock>' );
} );

it( 'should not convert if there is no image class in figure', () => {
editor.setData( '<figure class="quote">My quote</figure>' );

Expand Down
9 changes: 9 additions & 0 deletions packages/ckeditor5-image/tests/image/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' } ) );
Expand Down