我想配置CKEditor (版本4.3.2),以便在内容中的每个Image2小部件图标记中添加一个类属性。我使用以下代码(基于如何向CKEditor中的段落添加CSS类和ID?):
CKEDITOR.on("instanceReady", function(e)
{
var editor = e.editor;
pClass = 'additional_class',
pClassRegexp = new RegExp(pClass, 'g');
editor.dataProcessor.htmlFilter.addRules(
{
elements:
{
figure: function(element)
{
// If there's no class, assign the custom one:
if (!element.attributes['class'])
element.attributes['class'] = pClass;
// It there's some other class, append the custom one:
else if (!element.attributes['class'].match(pClassRegexp))
element.attributes['class'] += ' ' + pClass;
}
}
});
});不幸的是,我只能为没有类“标题”的图形元素添加类,但它不再是一个小部件。
发布于 2014-12-03 20:32:15
您可以使用CKEditor 4.4及更高版本,使用一些配置选项来完成此操作。以下是来自CKEditor的image2文档的相关说明
由于在CSS 4.4中引入了CKEDITOR.config.image2_alignClasses选项,您可以使用CSS类来设置图像对齐。此外,CKEDITOR.config.image2_captionedClass选项允许您将自定义类分配给标题图像的元素.
config.image2_alignClasses = [ 'image-left', 'image-center', 'image-right' ];
config.image2_captionedClass = 'image-captioned';将产生类驱动的、可手写的标记,使您能够避免僵化和非语义的内联CSS代码:
<figure class="image-captioned image-right">
<img alt="MyImage" src="myimage.png" />
<figcaption>MyCaption</figcaption>
</figure>https://stackoverflow.com/questions/21952845
复制相似问题