Is there a way to set the default font and font-size in CKEditor?
This is the only way I have found to force ck editor to create a default font. IE it wraps entered text in a (default) font span even if no font has been selected, and therefore will output formatted text. If you want the changes to be universal, add the following to config.js. Otherwise, it should be possible to add it to just one instance as well. Though I haven't tried that.
config.font_defaultLabel = 'Arial';
This will make the drop down default to 'Arial'. Though even this doesn't work the way I would hope. First, the editor must be activated (not just loaded) for the drop down to default. Then unlike a manual selection the value is not highlighted in the drop down box. It just displays.
Then add this below your default configuration options:
CKEDITOR.on( 'instanceReady', function( ev ) {
ev.editor.setData('<span style="font-family:Arial, Verdana, sans-serif;"></span>');
});
This will pre-populate the text area with the span you need. However you must include some character(s) in the span tag to force this 'hack' to work. So you're going to be stuck with something in your output you don't really want.The original version of this I found somewhere on the web used:
Which seems relatively innocuous.
I have looked and looked for a better way (and would love if someone knew one). Most people simply say capture the output and reformat it. That really wasn't an option for me. It may also be possible to accomplish this with a custom plugin. That too wasn't really viable for me.
Hope this helps someone save some time at least.
P.S. The original came from the support board at CK editor. Here is the link: forum
How Can i change default font of Ckeditor?
Per the docs these all seem to be defined in plugins/font/plugin.js.
{Object} CKEDITOR.config.font_style
The style definition to be used to apply the font in the text.
Defined in: plugins/font/plugin.js.
config.font_style = { element : 'span', styles : { 'font-family' : '#(family)' }, overrides : [ { element : 'font', attributes : { 'face' : null } } ] };
How to set default font in CKEditor 4
I got a solution for my use case. I had a block of code where the unwanted ckeditor bookmarks were cleaned up. Added a div with some inline styles specific to the font setting, to persist the font styles when thread is saved. For live UI changes, added a style to the ckeditor's parent div, to reflect the font styles while typing the content. ckeditorConfig.font_style
was not useful.Used ckeditorConfig.font_defaultLabel
to set the font drop down value of the ckeditor. I can't use the setData
method to set styles, as it may obstruct some of the the existing code flow.
CKEditor 4 - How to set default font?
you can use ckeditor's dataprocessor to modify (for example) paragraphs with your choice for font-size, font-family, this will affect any paragraph entered into ckeditor be it pasted, written or changed in the source; something like this:
CKEDITOR.on('instanceReady', function( ev ) {
ev.editor.dataProcessor.htmlFilter.addRules({
elements: {
p: function (e) { e.attributes.style = 'font-size:' + fontsizevariable + 'px; font-family:' + fontfamilyvariable + ';'; }
}
});
});
same for dataProcessor.dataFilter
But if you intend to view html created outside of your environment, these rules might make it a real mess
Related Topics
How to Detect MAC Os Inverted Color Mode in JavaScript/Css
Vanilla JavaScript: Resize Font-Awesome to Fit Container
Can Bootstrap (4) Be Integrated Along with Angular Material (2)
Force Address Bar to Show in Mobile Chrome App
How to Check What Fonts Are Installed on MAChines via the Web
Adding to Script Bundle from Partial View in .Net MVC 5
A Way to Count Columns in a Responsive Grid
Best Way to Make Bootstrap Responsive Based on Parent Div
Test If a Browser Supports a CSS Selector
Getting the Height of an Option Element with JavaScript
Cross-Browser Way to Flip HTML/Image via JavaScript/Css
I Need List of All Class Name of Font-Awesome
Getting Last-Child of a Div in IE8
Auto Image Resize Based on Browser Window Dimensions
How to Save Data from a Form with HTML5 Local Storage
Check If Window Is Already Open Window.Open
Does the JavaScript Onclick Event Not Work on <Select> <Option>'S