How to configure CKEditor to allow html block-level tags to be wrapped in an anchor tag

允我心安 提交于 2019-12-30 07:08:04

问题


I would like to wrap a few block tags in a link (valid in HTML5):

<a href="http://example.com">
  <div>foo</div>
  <p>bar</p>
  <span>baz</span>
  <strong>zoom</strong>
</a>

But CKEditor rewrites the code such that the links are placed inside block tags and allowed to wrap inline tags as the above code is replaced with the following:

<div><a href="http://example.com">foo</a></div>
<p><a href="http://example.com">bar</a></p>
<a href="http://example.com"><span>baz</span> <strong>zoom</strong> </a>

How can I disable this behavior?

In the CKEditor config, I'm using config.allowedContent = true; which disables the filtering of allowed tags.

We're also using config.autoParagraph = false; to not require root-level tags to be wrapped in a paragraph.

I've tried using config.extraAllowedContent = "a p; a div";, but this doesn't seem to have any effect.


回答1:


At the moment CKEditor (4.2) is xHTML/HTML4 editor only. There's no support support for HTML5 DTD (which is dynamic, BTW) and this is the root of your problem. I'm also afraid there's no workaround/config since different DTD means different parser, so CKEditor is not the right tool for you. Sorry.

You can find more information in this ticket.




回答2:


You can try doing something similar to this:

CKEDITOR.dtd.a.div = 1;
CKEDITOR.dtd.a.p = 1;

src: http://ckeditor.com/forums/Support/CKEditor-wont-allow-inside



来源:https://stackoverflow.com/questions/19825802/how-to-configure-ckeditor-to-allow-html-block-level-tags-to-be-wrapped-in-an-anc

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