我最近在我的应用中添加了CKEditor,我想在编辑器内包含自己的CSS样式表,以便我可以在编辑器内选择它们。
我该如何实现这一点?我目前的代码看起来像这样:
<script type="text/javascript">
CKEDITOR.replace( 'editor1',{
uiColor : '#9AB8F3',
});
</script>
我最近在我的应用中添加了CKEditor,我想在编辑器内包含自己的CSS样式表,以便我可以在编辑器内选择它们。
我该如何实现这一点?我目前的代码看起来像这样:
<script type="text/javascript">
CKEDITOR.replace( 'editor1',{
uiColor : '#9AB8F3',
});
</script>
<script type="text/javascript">
// This code could (may be should) go in your config.js file
CKEDITOR.stylesSet.add('my_custom_style', [
{ name: 'My Custom Block', element: 'h3', styles: { color: 'blue'} },
{ name: 'My Custom Inline', element: 'span', attributes: {'class': 'mine'} }
]);
// This code is for when you start up a CKEditor instance
CKEDITOR.replace( 'editor1',{
uiColor: '#9AB8F3',
stylesSet: 'my_custom_style'
});
</script>
您还可以阅读完整的stylesSet.add
语法文档:
这对我有效
CKEDITOR.addCss('body{background:blue;}');
如前所述,有一篇页面说明如何设置一组自定义样式。这个页面上隐藏的小宝石(并不是很清楚)是,您可以在配置中内联定义样式,而无需创建命名的样式集,像这样:
stylesSet : [
{
name : 'Green Title',
element : 'h3',
styles :
{
'color' : 'Green'
}
} ],
config.extraPlugins = 'stylesheetparser';
config.contentsCss = '/css/inline-text-styles.css';
config.stylesSet = [];
'/css/inline-text-styles.css' 是你网站根目录外的自己的 css 文件夹的路径,这样就不用将 css 和 javascript 混合在一起了。
虽然来晚了一些,但是默认样式位于 _source/plugins/styles/styles/default.js
。你可以将其作为样式配置并添加样式,这样就相当于在追加。
<script type="text/javascript">
CKEDITOR.replace( 'editor1',{
uiColor : '#9AB8F3',
stylesSet.add('default', [
{ name: 'My Custom Block', element: 'h3', styles: { color: 'Blue'} },
{ name: 'My Custom inline style', element: 'q'}
]);
});
</script>
虽然如果您在多个地方使用它,最好将其放入stylescombo\styles\default.js文件中,并根据api更新您的config.js文件。
CKEDITOR.stylesSet.add
和stylesSet
选项分成了两个调用。我在自己的网站上使用了我的答案中的代码变体。 - metavida