CKEditor allow <span> inside <a> tag

元气小坏坏 提交于 2020-01-02 10:32:47

问题


I want to add <span> tag inside of an <a> tag in the CKEditor source:

<a href="http://google.com"><span>Link here</span></a>

But when I add the HTML in CKEditor in source mode, it converts it to:

<a href="http://google.com">Link Here</a>

How can I allow HTML tags inside a href?


回答1:


Do u really need to put the <span> tags in there? Isn't it better to add a class to your link and edit it(the css I guess u want) from there.

What u can do:

  1. Try doing it the other way: <span><a href="http://google.com">Link here</a></span>

  2. Open your html file in Notepad/PSpad or anything that always shows you the rare source code and try to write it there - shouldn't be a problem.

  3. As I already wrote up - if u want that span there for editing css of the link text - use class in your link and edit css values. Example: <a href="http://google.com" class="myLink">Link Here</a> and in css: .myLink { ...your custom setting... }

If you could tell us for what you need the span tags there it would help us answering you :)

P.S.: I'm sorry that I'm not answering about the editor you are using. I just think you might want to try other editors that don't disable stuff u usually can do when writing the code.




回答2:


This <span> is removed by Advanced Content Filter. Apparently (and this is not surprising) none of features enabled in your editor allows bare spans (which are crappy non-semantic HTML), so they are simply removed.

I advice you not to use such messy HTML, because CKEditor will at some point break your <a>+<span> doublets because it does not know that they should be edited together.

However, if you need to use them, then check these options: config.allowedContent or config.extraAllowedContent. First one allows to completely disable Advanced Content Filter.




回答3:


Use extraAllowedContent filter:

CKEDITOR.replace('ckeditor', {
    extraAllowedContent: 'a span',
});


来源:https://stackoverflow.com/questions/16300990/ckeditor-allow-span-inside-a-tag

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