Ckeditor 差异格式\u标记和样式集

Ckeditor 差异格式\u标记和样式集,ckeditor,Ckeditor,在CKEDITOR配置中,format\u标记属性和stylesSet属性之间有什么区别 我将API用于一些自定义按钮(在DOM中,而不是在编辑器本身中),并且我还有一个样式下拉列表 我首先使用了format\u标签属性: var tags = config.format_tags.split( ';' ); // Create style objects for all defined styles. var styles = {}; $.each(tags,function(i,tag) {

在CKEDITOR配置中,
format\u标记
属性和
stylesSet
属性之间有什么区别

我将API用于一些自定义按钮(在DOM中,而不是在编辑器本身中),并且我还有一个样式下拉列表

我首先使用了
format\u标签
属性:

var tags = config.format_tags.split( ';' );
// Create style objects for all defined styles.
var styles = {};
$.each(tags,function(i,tag) {
  styles[ tag ] = new CKEDITOR.style( config[ 'format_' + tag ] );
  styles[ tag ]._.enterMode = ckeditor.config.enterMode;
});
在此之后,我可以调用所需的样式函数来应用(或删除)它

今天我偶然发现了
stylesSet
属性,我可以这样使用它:

CKEDITOR.stylesSet.add('my_custom_style', [
  { name: 'My Custom Block', element: 'h3', styles: { color: 'blue'} },
  { name: 'My Custom Inline', element: 'span', attributes: {'class': 'mine'} }
]);
这对我来说更合适,因为我知道可以为元素使用额外的类和内联样式


有人能解释一下为什么有两种文本格式吗?当您有更好的配置选项(如
样式集
)时,为什么要使用
格式标签
。似乎可以对
格式标签使用与
样式集相同的格式

现在,我的配置中有以下内容:

config.format_tags = 'h1;h2;h3;test';
config.format_test = { element : 'span', attributes : { 'class' : 'test' }, styles: { color: 'blue'} };

这最适合将自定义格式标记添加到您的编辑器中。

如果您使用其他语言,请不要忘记将自定义标记翻译添加到“格式”部分/lang/nl.js否则新标记在格式dropdownlist中不可见

"format": {
  .......       
  "tag_test": "tekst met css"
}

如果我想添加一个自定义的标记来格式化标记,这对我来说是可行的:

1.转到config.js,添加
config.format_标记='h1;h2;h3;h4;h5;h6部分
config.format_section={element:'section',attributes:{'class':'test'}

2.然后打开所需的语言文件(例如en.js)->lang/en.js

搜索“tag_pre”:“Formatted”,并添加“tag_section”:“section”

实际上有两个下拉列表。一个用于标记选择,第二个用于样式选择。工具栏中这些字段的可见性可以在配置中更改。

标记下拉列表 更改当前块元素标记类型(p、h1、h2等)。此列表的配置是例如
格式_标签:'p;h2;h3;h4;分区;在“
之前

样式下拉列表 更改当前选定图元(不仅仅是块图元)的各种设置。例如,使用此选项可以为图像指定特定的类。此列表的配置如下所示:

stylesSet: [
            {
                name : 'Image on the left',
                element : 'img',
                attributes : { 'class' : 'myLeftImage' }
            }
        ]