简体   繁体   English

CKEditor 4 - 如何设置默认字体?

[英]CKEditor 4 - How to set default font?

I use CKEditor 4 and I want to set default font.我使用 CKEditor 4,我想设置默认字体。 I added "font_defaultLabel" with my font choice but it doesn't work ...我用我的字体选择添加了“font_defaultLabel”,但它不起作用......

I found this solution on the Internet but it's a trick for me and not a true solution :我在互联网上找到了这个解决方案,但这对我来说是一个技巧,而不是一个真正的解决方案:

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

Can someone help me?有人能帮我吗?

EpokK EpokK

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;您可以使用 ckeditor 的数据处理器来修改(例如)您选择的字体大小、字体系列的段落,这将影响输入到 ckeditor 中的任何段落,无论是在源代码中粘贴、写入还是更改; 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 dataProcessor.dataFilter 相同

But if you intend to view html created outside of your environment, these rules might make it a real mess但是如果你打算查看在你的环境之外创建的 html,这些规则可能会让它变得一团糟

CKeditor uses a default css file for it's content: contents.css You can change the used font(s) there. CKeditor 为其内容使用默认 css 文件: contents.css您可以在那里更改使用的字体。 Just make sure you use the same css (or just the font) when displaying the CKeditor content without CKeditor.在没有 CKeditor 的情况下显示 CKeditor 内容时,请确保使用相同的 css(或仅使用字体)。

Simply place this below your original CKEDITOR JS, and change the font-size to whatever you like.只需将它放在原始 CKEDITOR JS 下方,然后将字体大小更改为您喜欢的任何值。 This works for me, hope it does for you!这对我有用,希望对你有用!

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM