javascript CKEditor 4 - 如何设置默认字体?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16339258/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CKEditor 4 - How to set default font?
提问by EpokK
I use CKEditor 4 and I want to set default font. I added "font_defaultLabel" with my font choice but it doesn't work ...
我使用 CKEditor 4,我想设置默认字体。我用我的字体选择添加了“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;">­</span>');
});
Can someone help me?
有人能帮我吗?
EpokK
EpokK
回答by Zee
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 的数据处理器来修改(例如)您选择的字体大小、字体系列的段落,这将影响输入到 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 + ';'; }
}
});
});
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,这些规则可能会让它变得一团糟
回答by Willem
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.
CKeditor 为其内容使用默认 css 文件:contents.css
您可以在那里更改使用的字体。在没有 CKeditor 的情况下显示 CKeditor 内容时,请确保使用相同的 css(或仅使用字体)。
回答by Mark
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 JS 下方,然后将字体大小更改为您喜欢的任何值。这对我有用,希望对你有用!
CKEDITOR.on( 'instanceReady', function( ev ) {
ev.editor.setData('<span style="font-size:48px;">­</span>');
});