Typel
Typel

Reputation: 1139

How can I prevent CKEditor from enclosing URLs in quotes?

Due to a very specific requirement, I need to prevent CKEditor from rewriting links with quotation marks around the URL. For example, if I input:

<a href=TEST123>TEST123</a>

CKEditor rewrites it to:

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

I currently have the following plugins in my distribution, although adding or removing different plugins to meet this requirement would not be a problem:

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

Before I get lectured about how bad of an idea this is (you're preaching to the choir here), know that this is a REQUIREMENT for a very specific implementation of the Keyora web platform. There's nothing I can do to get around the requirement, since it is already compiled into someone else's code. I just need to make it work, somehow. Is there any way to do this with CKEditor?

Thanks!

Upvotes: 0

Views: 130

Answers (1)

Typel
Typel

Reputation: 1139

I figured out how to do this. The trick is to copy the basicWriter function (located in /ckeditor/core/htmlparser/basicwriter.js) into your /config.js file and apply a small customization to it, like so:

Original

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

...

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

...

} );

Customized

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

...

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

...

} );

This prevents quotation marks from auto-surrounding URLs. Again, this breaks CKEditor for almost every application it is useful for, so I highly recommend NOT doing this under almost any circumstance.

Even though it is bad practice, adding it to the config.js rather than customizing core CKEditor code itself at least allows you to easily roll back the customization.

Upvotes: 2

Related Questions