Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

ckeditor

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.

like image 992
Beau Smith Avatar asked Nov 07 '13 00:11

Beau Smith


1 Answers

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

like image 160
George Avatar answered Oct 13 '22 10:10

George