ckeditor5-textindent
Version:
Text indentation feature for CK Editor 5
44 lines (38 loc) • 853 B
JavaScript
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import { getRoundedValues } from './utils';
export default class FullTextIndent extends Plugin {
static get pluginName() {
return 'FullTextIndent';
}
init() {
const conversion = this.editor.conversion;
conversion.for( 'upcast' ).attributeToAttribute( {
view: {
name: 'p',
styles: {
'margin': /[\s\S]+/
}
},
model: {
key: 'customMargin',
value: viewElement => {
return getRoundedValues( viewElement.getStyle( 'margin' ) );
}
}
} );
conversion.for( 'downcast' ).attributeToAttribute( {
model: 'customMargin',
view: modelAttributeValue => {
if ( !modelAttributeValue ) {
return;
}
return {
key: 'style',
value: {
'margin': modelAttributeValue.join( 'px ' ) + 'px'
}
};
}
} );
}
}