问题
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