如何重命名 CKEditor 中的现有样式?

伊戈桑托斯07

在我的网页中,我们将只允许用户使用H3H4,但将它们视为“标题 3”和“标题 4”会令人困惑。我想将它们重命名为“标题”和“副标题”,但设置format_h3.name似乎并不影响它。

我无法编写自定义 JS 来配置编辑器,因为我使用的是 Django 插件,它实际上将 python 字典转换为最终使用的 JSON 配置。

我尝试的相关部分如下:

CKEDITOR_CONFIGS = {
    'default': {
        'allowedContent': 'h3 h4 p b i u a[*]',
        'format_p': {'name': 'Standard text', 'element': 'p'},
        'format_h3': {'name': 'Title', 'element': 'h3'},
        'format_h4': {'name': 'Subtitle', 'element': 'h4'},
        'toolbar': [
            {'name': 'styles', 'items': ['Format']},
            {'name': 'basicstyles', 'items': ['Bold', 'Italic', 'Underline', '-', 'RemoveFormat']},
            {'name': 'links', 'items': ['Link', 'Unlink']},
        ]
    }
}
指挥官

不幸的是,无法通过配置更改 CKEditor 中的格式名称。我已经填写了一个功能请求

但是,如果您能够修改编辑器的文件,则始终可以直接更改位于plugins/format/lang/<language>.js.

第二种解决方法是修改format插件源,尤其是init函数

init: function() {
    this.startGroup( lang.panelTitle );

    for ( var tag in styles ) {
        var label = config[ 'format_' + tag ] && config[ 'format_' + tag ].name || lang[ 'tag_' + tag ];

        // Add the tag entry to the panel list.
        this.add( tag, styles[ tag ].buildPreview( label ), label );
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章