diff --git a/src/image/converters.js b/src/image/converters.js
index 7d20c298..f54e3dab 100644
--- a/src/image/converters.js
+++ b/src/image/converters.js
@@ -8,6 +8,7 @@
*/
import first from '@ckeditor/ckeditor5-utils/src/first';
+import { getViewImgFromWidget } from './utils';
/**
* Returns a function that converts the image view representation:
@@ -35,7 +36,7 @@ export function viewFigureToModel() {
}
// Find an image element inside the figure element.
- const viewImage = Array.from( data.viewItem.getChildren() ).find( viewChild => viewChild.is( 'img' ) );
+ const viewImage = getViewImgFromWidget( data.viewItem );
// Do not convert if image element is absent, is missing src attribute or was already converted.
if ( !viewImage || !viewImage.hasAttribute( 'src' ) || !conversionApi.consumable.test( viewImage, { name: true } ) ) {
@@ -81,7 +82,7 @@ export function srcsetAttributeConverter() {
const writer = conversionApi.writer;
const figure = conversionApi.mapper.toViewElement( data.item );
- const img = figure.getChild( 0 );
+ const img = getViewImgFromWidget( figure );
if ( data.attributeNewValue === null ) {
const srcset = data.attributeOldValue;
@@ -122,7 +123,7 @@ export function modelToViewAttributeConverter( attributeKey ) {
const viewWriter = conversionApi.writer;
const figure = conversionApi.mapper.toViewElement( data.item );
- const img = figure.getChild( 0 );
+ const img = getViewImgFromWidget( figure );
if ( data.attributeNewValue !== null ) {
viewWriter.setAttribute( data.attributeKey, data.attributeNewValue, img );
diff --git a/src/image/utils.js b/src/image/utils.js
index 76aa6580..ad0c3b72 100644
--- a/src/image/utils.js
+++ b/src/image/utils.js
@@ -25,7 +25,7 @@ export function toImageWidget( viewElement, writer, label ) {
return toWidget( viewElement, writer, { label: labelCreator } );
function labelCreator() {
- const imgElement = viewElement.getChild( 0 );
+ const imgElement = getViewImgFromWidget( viewElement );
const altText = imgElement.getAttribute( 'alt' );
return altText ? `${ altText } ${ label }` : label;
@@ -107,6 +107,19 @@ export function isImageAllowed( model ) {
isInOtherImage( selection );
}
+/**
+ * Get view `` element from the view widget (`