有没有办法在CKEditor中设置默认字体和字体大小? [英] Is there a way to set the default font and font-size in CKEditor?

查看:281
本文介绍了有没有办法在CKEditor中设置默认字体和字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一个解决方案,一段时间,现在,唯一的修复,我发现只影响文本在编辑器本身显示的方式,而不是当发送/保存在其他地方时生成的文本的外观。我在说CSS修补程序和这样的东西。

I've been looking for a solution for this for a while now and the only fixes I found only affect the way the text is displayed in the editor itself and not how the generated text will look when sent/saved somewhere else. I'm talking CSS fixes and stuff like that.

我使用CKEditor通过我们的网络应用程序撰写和发送电子邮件,而css修复更改显示的字体编辑器本身,收到的电子邮件仍然显示在TNR或任何继承自电子邮件客户端。除非,当然,我从插件为每个段落更改字体和大小。

I'm using CKEditor to compose and send emails trough our web application and while the css fixes change the font shown in the editor itself, the recieved emails are still displayed in TNR or whatever is inherited from the email client. Unless, of course, I change the font and size from the plugin for each paragraph.

从我注意到的每当你在插件内设置字体和大小,CKEditor创建一个跨度(实际上是两个,一个与字体和一个(例如< span style =font:Arial>< span style =font-size:12>< / span>< / span> ),我想我可以把整个结果包裹在一个span或div,我想要的字体和尺寸样式,但这可能会干扰用户的模板和样式。

From what I've noticed whenever you set the font and size from within the plugin, CKEditor creates a span (well, actually two, one with the font and one with the size) with the newly changed style (for example <span style="font: Arial"><span style="font-size: 12"></span></span>) and I figure I could just wrap the whole result in a span or div with my desired font and size styling, but that might interfere the users' templates and styles.

有没有任何方法来设置从插件本身的默认文本样式(如电子邮件的收件人看到的)或者我必须拿出一个黑客。

Is there any way to set the default text styles (as seen by the recipient of the emails) from the plugin itself or will I have to come up with a hack to it.

推荐答案

这是我发现强制ck编辑器创建默认字体的唯一方法。 IE即使没有选择字体,也将输入的文本包裹在(默认)字体范围中,因此将输出格式化的文本。如果希望更改是通用的,请将以下内容添加到config.js。否则,应该也可以将它添加到一个实例。虽然我没有尝试过。

This is the only way I have found to force ck editor to create a default font. IE it wraps entered text in a (default) font span even if no font has been selected, and therefore will output formatted text. If you want the changes to be universal, add the following to config.js. Otherwise, it should be possible to add it to just one instance as well. Though I haven't tried that.

config.font_defaultLabel = 'Arial';

这将使下拉默认值为Arial。虽然这不工作的方式,我希望。首先,编辑器必须被激活(不只是加载),下拉到默认。然后,与手动选择不同,该值不会在下拉框中突出显示。它只是显示。

This will make the drop down default to 'Arial'. Though even this doesn't work the way I would hope. First, the editor must be activated (not just loaded) for the drop down to default. Then unlike a manual selection the value is not highlighted in the drop down box. It just displays.

然后将其添加到默认配置选项下面:

Then add this below your default configuration options:

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

这将使用您需要的跨度预填充文本区域。但是,您必须在span标签中包含一些字符,以强制此黑客工作。所以你会被困在你的输出中你不想真正想要的东西。我发现在网络上的某个地方使用的原始版本:

This will pre-populate the text area with the span you need. However you must include some character(s) in the span tag to force this 'hack' to work. So you're going to be stuck with something in your output you don't really want.The original version of this I found somewhere on the web used:

&shy;

这似乎比较无害。

已经看起来寻找一个更好的方法(如果有人知道,会喜欢)。大多数人只是说捕获输出并重新格式化它。这真的不是我的选择。也可以通过自定义插件来实现。这对我来说也不可行。

I have looked and looked for a better way (and would love if someone knew one). Most people simply say capture the output and reformat it. That really wasn't an option for me. It may also be possible to accomplish this with a custom plugin. That too wasn't really viable for me.

希望这可以帮助某人至少节省一些时间。

Hope this helps someone save some time at least.

原来来自CK编辑器的支持板。以下是链接:论坛

P.S. The original came from the support board at CK editor. Here is the link: forum

这篇关于有没有办法在CKEditor中设置默认字体和字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆