CKEditor 4 - How to set default font?

前端 未结 3 1410
一个人的身影
一个人的身影 2021-01-06 00:05

I use CKEditor 4 and I want to set default font. I added \"font_defaultLabel\" with my font choice but it doesn\'t work ...

I found this solution on the Internet but

相关标签:
3条回答
  • 2021-01-06 00:34

    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

    0 讨论(0)
  • 2021-01-06 00:39

    Simply place this below your original CKEDITOR JS, and change the font-size to whatever you like. This works for me, hope it does for you!

    CKEDITOR.on( 'instanceReady', function( ev ) {
     ev.editor.setData('<span style="font-size:48px;">&shy;</span>');
    });
    
    0 讨论(0)
  • 2021-01-06 00:51

    CKeditor uses a default css file for it's content: contents.css You can change the used font(s) there. Just make sure you use the same css (or just the font) when displaying the CKeditor content without CKeditor.

    0 讨论(0)
提交回复
热议问题