@concordnow/ckeditor5-image-rendering
Version:
Image rendering feature for CK Editor 5
40 lines (36 loc) • 814 B
JavaScript
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import { getRoundedValue } from './utils';
export default class ImageDimensions extends Plugin {
static get pluginName() {
return 'ImageDimensions';
}
init() {
const editor = this.editor;
const conversion = editor.conversion;
conversion.for( 'upcast' )
.attributeToAttribute( {
view: {
name: 'img',
key: 'width'
},
model: {
key: 'customImageWidth',
value: viewImage => {
return getRoundedValue( viewImage.getAttribute( 'width' ) );
}
}
} )
.attributeToAttribute( {
view: {
name: 'img',
key: 'height'
},
model: {
key: 'customImageHeight',
value: viewImage => {
return getRoundedValue( viewImage.getAttribute( 'height' ) );
}
}
} );
}
}