经过更多的谷歌搜索具有讽刺意味的是,我在这里找到了答案:
CKEditor 对齐图像而不是浮动
为什么它没有出现在搜索中我不知道。这确实起到了作用,尽管我删除了与宽度和高度相关的线条并删除了“float”css 属性的替换,因为这导致所见即所得无法拾取样式。除此之外一切都很好!
更新:我发现在某些情况下这与 CKeditor 4 不太兼容,并发现这个小版本的代码修复了它。
element.forEach = function(){};
element.writeChildrenHtml = function(){};
请参阅:http: //vibhajadwani.wordpress.com/2011/07/18/how-to-remove-image-style-property-from-ckeditor/
所以完整的代码块如下:
CKEDITOR.on('instanceReady', function( ev )
{
// Ends self closing tags the HTML4 way, like <br>.
// See: https://stackoverflow.com/questions/4466185/ckeditor-align-images-instead-of-float
// Mod added for CKE 4
// See: http://vibhajadwani.wordpress.com/2011/07/18/how-to-remove-image-style-property-from-ckeditor/
ev.editor.dataProcessor.htmlFilter.addRules(
{
elements:
{
$: function( element )
{
// Output dimensions of images as width and height
if( element.name == 'img' )
{
var style = element.attributes.style;
if( style )
{
// Get the width from the style.
var match = /(?:^|\s)width\s*:\s*(\d+)px/i.exec( style ),
width = match && match[ 1 ];
// Get the height from the style.
match = /(?:^|\s)height\s*:\s*(\d+)px/i.exec( style );
var height = match && match[ 1 ];
// Get the float from the style.
match = /(?:^|\s)float\s*:\s*(\w+)/i.exec( style );
var align = match && match[ 1 ];
if( align )
{
element.attributes.align = align;
}
}
element.forEach = function(){};
element.writeChildrenHtml = function(){};
}
return element;
}
}
});
});