差异format_tags和stylesSet

时间:2012-11-02 10:47:58

标签: ckeditor

CKEDITOR配置中的format_tags属性和stylesSet属性有什么区别?

我正在使用API​​进行一些自定义按钮(它们在DOM中,而不是在编辑器本身中),我还有一个样式下拉列表。

我首先使用format_tags属性:

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'} }
]);

这对我来说看起来更好,因为我知道可以为元素使用额外的类和内联样式。

有人可以解释为什么有两种格式化文字的方法吗?当您拥有更好的配置选项format_tags时,为什么会使用stylesSet

4 个答案:

答案 0 :(得分:1)

我调查了一下。您似乎可以使用与format_tag相同的格式stylesSet

我现在在配置中有这个:

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

这最适合在您的ckeditor中添加自定义格式标记。

答案 1 :(得分:0)

如果您使用其他语言,请不要忘记将自定义标记转换添加到“格式”部分。 ../lang/nl.js否则新标签在格式下拉列表中不可见。

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

答案 2 :(得分:0)

如果我想在格式标记中添加自定义部分标记,请为我工作:

1.转到config.js,添加
config.format_tags =' h1; h2; h3; h4; h5; h6; section '
config.format_section = {element:' section',attributes:{' class' :'测试' } ;;

2.然后打开所需的语言文件(例如en.js) - > lang / en.js
搜索" tag_pre":"格式化",然后添加" tag_section":""

答案 3 :(得分:0)

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

标签下拉列表

更改当前块元素标记类型(p,h1,h2,...)。此列表的配置例如是format_tags: 'p;h2;h3;h4;div;pre'Learn more here

样式下拉列表

更改当前所选元素的各种设置(不仅是块元素)。使用此功能,您可以为图像提供某些类。此列表的配置例如是:

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

Learn more here