如何在 CKEditor 中重命名现有样式?
How to rename existing styles in CKEditor?
在我的网页中,我们只允许用户使用 H3
和 H4
,但将它们视为 "Title 3" 和 "Title 4" 会让人感到困惑。我想将它们重命名为 "Title" 和 "Subtitle",但设置 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 中的格式名称。我为此填写了 feature request。
但是,如果您能够修改编辑器的文件,您始终可以直接更改位于 plugins/format/lang/<language>.js
.
中的语言条目
第二种解决方法是修改 format
插件源,尤其是 init
function:
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 );
}
}
这在 CKEditor 4 中仍然没有正式解决,但我确实想出了这个大锤方法...
CKEDITOR.lang.load('en', 'en', function(lc, data) {
data.format.tag_p = 'Standard text';
data.format.tag_h3 = 'Title';
data.format.tag_h4 = 'Subtitle';
});
根据手册,第一个'en'是您要加载的语言代码,第二个是后备语言。您需要在回调中覆盖标签,否则您将收到有关标签不存在的错误。
此示例将更改您 运行 页面上每个 CKEditor 实例的文本。它还会为在所述实例中使用这些翻译的每个插件更改它。
我还没有找到执行此操作的每个实例的方法。
在我的网页中,我们只允许用户使用 H3
和 H4
,但将它们视为 "Title 3" 和 "Title 4" 会让人感到困惑。我想将它们重命名为 "Title" 和 "Subtitle",但设置 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 中的格式名称。我为此填写了 feature request。
但是,如果您能够修改编辑器的文件,您始终可以直接更改位于 plugins/format/lang/<language>.js
.
第二种解决方法是修改 format
插件源,尤其是 init
function:
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 );
}
}
这在 CKEditor 4 中仍然没有正式解决,但我确实想出了这个大锤方法...
CKEDITOR.lang.load('en', 'en', function(lc, data) {
data.format.tag_p = 'Standard text';
data.format.tag_h3 = 'Title';
data.format.tag_h4 = 'Subtitle';
});
根据手册,第一个'en'是您要加载的语言代码,第二个是后备语言。您需要在回调中覆盖标签,否则您将收到有关标签不存在的错误。
此示例将更改您 运行 页面上每个 CKEditor 实例的文本。它还会为在所述实例中使用这些翻译的每个插件更改它。
我还没有找到执行此操作的每个实例的方法。