如何防止CKEditor将URL括在引号中?

时间:2015-07-19 23:22:24

标签: php html ckeditor

由于非常具体的要求,我需要阻止CKEditor使用URL周围的引号重写链接。例如,如果我输入:

<a href=TEST123>TEST123</a>

CKEditor将其重写为:

<a href="TEST123">TEST123</a>

我目前在我的发行版中有以下插件,虽然添加或删除不同的插件以满足此要求不会是一个问题:

basicstyles, button, clipboard, dialog, dialogui, enterkey, 
entities, fakeobjects, floatingspace, indent, indentlist, 
link, list, resize, sourcearea, toolbar, undo, wysiwygarea

在我讲这个想法有多糟糕之前(你在这里向合唱团讲道),要知道这是对Keyora网络平台的一个非常具体的实现的要求。我无法绕过这个要求,因为它已被编译成别人的代码。我只是需要以某种方式使它工作。有没有办法用CKEditor做到这一点?

谢谢!

1 个答案:

答案 0 :(得分:2)

我想出了如何做到这一点。诀窍是将basicWriter函数(位于/ckeditor/core/htmlparser/basicwriter.js中)复制到/config.js文件中并对其应用一个小的自定义,如下所示:

<强>原始

CKEDITOR.htmlParser.basicWriter = CKEDITOR.tools.createClass( {

...

this._.output.push( ' ', attName, '="', attValue, '"' );

...

} );

<强>定制

CKEDITOR.htmlParser.basicWriter = CKEDITOR.tools.createClass( {

...

if ( attName == 'href' ) {
    this._.output.push( ' ', attName, '=', attValue, '' );
    } else {
    this._.output.push( ' ', attName, '="', attValue, '"' );
    }

...

} );

这可以防止自动包围的网址引号。同样,这会破坏CKEditor几乎所有适用的应用程序,因此我强烈建议不要在几乎任何情况下执行此操作。

即使这是不好的做法,将它添加到config.js而不是自定义核心CKEditor代码本身至少可以让您轻松回滚自定义。

相关问题