CKEditor 4 -如何设置默认字体

CKEditor 4 - How to set default font?

本文关键字:设置 默认 字体 何设置 CKEditor      更新时间:2023-09-26

我使用CKEditor 4,我想设置默认字体。我添加了"font_defaultLabel"与我的字体选择,但它不工作…

我在网上找到了这个解决方案,但这对我来说是一个技巧,不是一个真正的解决方案:

CKEDITOR.on( 'instanceReady', function( ev ) {
     ev.editor.setData('<span style="font-family:Arial, Verdana, sans-serif;">&shy;</span>');
});

有人能帮帮我吗?

EpokK

您可以使用ckeditor的数据处理器来修改(例如)段落与您选择的字体大小,字体族,这将影响任何段落输入到ckeditor无论是粘贴,写入或更改源;像这样:

CKEDITOR.on('instanceReady', function( ev ) {
  ev.editor.dataProcessor.htmlFilter.addRules({
    elements: {
      p: function (e) { e.attributes.style = 'font-size:' + fontsizevariable + 'px; font-family:' + fontfamilyvariable + ';'; }
    }
  });
});

dataProcessor.dataFilter

但是如果您打算查看在您的环境之外创建的html,这些规则可能会使它变得非常混乱

CKeditor使用默认的css文件作为它的内容:contents.css您可以在那里更改使用的字体。只要确保你使用相同的css(或只是字体)时,显示CKeditor内容没有CKeditor

只需将其放在原始CKEDITOR JS下面,并将字体大小更改为您喜欢的任何大小。这对我有用,希望对你有用!

CKEDITOR.on( 'instanceReady', function( ev ) {
 ev.editor.setData('<span style="font-size:48px;">&shy;</span>');
});