Is there anyway to stop CKEditor 4 from filtering my anchor tag attributes?

╄→尐↘猪︶ㄣ 提交于 2019-12-22 10:27:11

问题


CKEditor 4 attribute filtering is stripping any occurrence "href" from anchor tags put into the editor. I have a plugin which creates links that contain some "custom" attributes. A link looks something like this:

<a href="#" document-href="abc123">Some Link</a>

The CKEditor returns the link in this form when I call getData():

<a href="#" document->Some Link</a>

Is there a way to instruct CKEditor to stop filtering link attributes? Does anyone happen to know where in the source this regex is so I can fix it?

Thanks!


回答1:


I've just checked this link on CKEditor 4.1 - the output is:

<p><a href="#">Some Link</a></p>

Since 4.1 the document-href is stripped because it is now allowed in the editor. You have to add an Advanced Content Filter rule - e.g.:

config.extraAllowedContent = 'a[!href,document-href]';

And then it would work in 4.1. Before 4.1 it should work by default, without setting anything.

However there's a bug in CKEditor's HTML parser. It does not parse correctly sth-href attributes on links so a result is a sth- attribute.

For now I advice you to change the name of this attribute to data-url or whatever else without href ending.

I created a ticket: https://dev.ckeditor.com/ticket/10298




回答2:


try setting this in config file.

    config.allowedContent = true;

also if its getting filtered on insert then you can try this:

//var yourAnchor = '<a href="#" document-href="abc123">Some Link</a>';

editor.insertHtml(yourAnchor, 'unfiltered_html');


来源:https://stackoverflow.com/questions/15795142/is-there-anyway-to-stop-ckeditor-4-from-filtering-my-anchor-tag-attributes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!