即使 allowedContent 设置为 true,CKEditor 4 也会删除 A 标签中的 xlink:href

CKEditor 4 removes xlink:href in A tags even when allowedContent set to true

我必须使用 CKEditor 来允许用户编辑一些可能包含 SVG 图像的 HTLM 页面。那些 SVG 图像中定义的 links 包含一些属性,如 xlink:href。例如:

    <svg preserveaspectratio="xMinYMin meet" version="1.1" viewbox="0 0 778 873" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> 
    <image height="100%" width="100%" xlink:href="map.png"></image> 
        <g class="hover_group" opacity="1"> 
            <a xlink:href="http://www.google.com">
                <rect fill="red" height="100" opacity="0.0" width="160" x="110" y="240"></rect> 
            </a> 
        </g> 
    </svg>

我已经设置了CKEDITOR.config.allowedContent = true,希望编辑器保留所有标签和属性。

然而,当我在所见即所得和HTML模式之间来回切换时,我注意到A标签变成了这样:

a href="http://www.google.com" xlink:=""

<svg preserveaspectratio="xMinYMin meet" version="1.1" viewbox="0 0 778 873" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> 
    <image height="100%" width="100%" xlink:href="map.png"></image> 
    <g class="hover_group" opacity="1"> 
        <a href="http://www.google.com" xlink:="">
            <rect fill="red" height="100" opacity="0.0" width="160" x="110" y="240"></rect> 
        </a> 
    </g> 
</svg>

此行为只发生在 A 标签上,而不是 IMAGE 标签。

当然,这会使 SVG 文件中的 link 不再起作用。

有人知道如何解决这个问题吗?谢谢。我不想手动允许所有允许的标签或属性,因为这可能需要很多工作。

这是 CKEditor 中的一个错误(也称为 "lack of feature")。它无法正确处理以“:href”结尾的属性。

我报告了 http://dev.ckeditor.com/ticket/13233,其中还包括一个可能的补丁程序。如果正确,则此问题将在下一个次要版本中修复。