Issue
I'm using ckeditor5 and I'm trying to set the editor by default to be bold and center. So that the user starts writing, the text will be bold and center.
I saw similar questions asked, but none of the answers worked as expected,
I tried to use text-align: center
on the editor element, and also on the parent element, but it didn't work (I also used !important
)
ClassicEditor
.create(document.querySelector( '#editor' ), {
// Editor configuration.
})
.catch( error => {
console.error( error );
});
<script src="https://cdn.ckeditor.com/ckeditor5/40.2.0/classic/ckeditor.js"></script>
<div style="text-align: center !important; font-weight: bold !important">
<textarea id="editor" style="text-align: center !important; font-weight: bold !important"></textarea>
</div>
What can I do?
Solution
I found the method to do it.
You need to use the function execute()
Ckeditor5 documentation: here.
Demo code:
ClassicEditor
.create(document.querySelector( '#editor' ), {
// Editor configuration.
}).then(editor => {
editor.execute('bold');
editor.execute('heading', { value: 'heading2' });
// Code for text alignment (not included in classic editor)
// editor.execute('alignment', { value: 'center'});
})
.catch( error => {
console.error( error );
});
<script src="https://cdn.ckeditor.com/ckeditor5/40.2.0/classic/ckeditor.js"></script>
<textarea id="editor"></textarea>
Answered By - Nissim Elbaz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.