如何在CKEditor 4中设置默认字体

问题描述

我正在尝试为CKEditor 4设置认字体和字体大小。

在CKEditor 4文档中找到了这一点 https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-font_style

就像我想将认字体更改为“ Comic Sans MS”,将字体大小更改为“ 48”

试图这样,但不起作用

ckeditorConfig.font_style = {
  element:  'span',styles:  { 'font-family': 'Comic Sans MS' },overrides:  [ { element: 'font',attributes: { 'face': null } } ]
};

ckeditorConfig.fontSize_style = {
  element:  'span',styles:  { 'font-size': '48px' },attributes: { 'size': null } } ]
};

是从堆栈溢出中发现的,但没有可用的示例How Can i change default font of Ckeditor?

还在CKEditor的instanceReady上设置跨度并没有帮助 Is there a way to set the default font and font-size in CKEditor?

----更新---

上面的CKEditor配置覆盖了CKEditor的Font下拉选项,并且不影响认字体。似乎它会覆盖从下拉菜单中选择的字体,直到Config中指定的字体。

是否还有其他方法可以设置CKEditor 4的认字体。

预先感谢。

解决方法

我为我的用例找到了解决方案。我有一段代码,其中清理了不需要的 ckeditor 书签。添加了一个带有一些特定于字体设置的内联样式的 div,以在保存线程时保留字体样式。对于实时 UI 更改,向 ckeditor 的父 div 添加样式,以在键入内容时反映字体样式。 ckeditorConfig.font_style 没有用。使用 ckeditorConfig.font_defaultLabel 设置 ckeditor 的字体下拉值。我无法使用 setData 方法设置样式,因为它可能会阻碍某些现有代码流。