I using insertText() to create new paragraph, how can i add custom class for new element?
_What steps should be taken to fulfill the task?_
Here is my code:
`js
const docFrag = editor.model.change(writer => {
const p1 = writer.createElement('paragraph', {class: 'flashback'});
const docFrag = writer.createDocumentFragment();
writer.append(p1, docFrag);
writer.insertText('※ ※ ※', p1);
return docFrag;
});
`
Hi, thanks for the report. Did you allow class attribute on the paragraph element in the schema and provide proper conversion for this attribute? The simplified implementation could look like this:
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
export default class AllowClassAttribute extends Plugin {
init() {
const editor = this.editor;
editor.model.schema.extend( 'paragraph', { allowAttributes: [ 'class' ] } );
editor.conversion.attributeToAttribute( { model: 'class', view: 'class' } );
}
}
Hi, thanks for the report. Did you allow
classattribute on theparagraphelement in the schema and provide proper conversion for this attribute? The simplified implementation could look like this:import Plugin from '@ckeditor/ckeditor5-core/src/plugin'; export default class AllowClassAttribute extends Plugin { init() { const editor = this.editor; editor.model.schema.extend( 'paragraph', { allowAttributes: [ 'class' ] } ); editor.conversion.attributeToAttribute( { model: 'class', view: 'class' } ); } }
Thanks @Mgsy, it worked.