如何配置CKEditor以允许将html块级标签包装在锚标签中

Bea*_*ith 4 html5 ckeditor

我想在链接中包装一些块标签(在HTML5中有效):

<a href="http://example.com">
  <div>foo</div>
  <p>bar</p>
  <span>baz</span>
  <strong>zoom</strong>
</a>
Run Code Online (Sandbox Code Playgroud)

但是CKEditor重写了代码,以便将链接放置在块标签内,并允许包装内联标签,因为上述代码被替换为以下代码:

<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>
Run Code Online (Sandbox Code Playgroud)

如何禁用此行为?

在CKEditor配置中,我正在使用config.allowedContent = true;它禁用允许标签的过滤。

我们还习惯于config.autoParagraph = false;不要求将根级标签包装在段落中。

我尝试使用config.extraAllowedContent = "a p; a div";,但这似乎没有任何效果。

Geo*_*rge 5

您可以尝试执行以下操作:

CKEDITOR.dtd.a.div = 1;
CKEDITOR.dtd.a.p = 1;
Run Code Online (Sandbox Code Playgroud)

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


ole*_*leq 3

目前 CKEditor (4.2) 仅是 xHTML/HTML4 编辑器。不支持 HTML5 DTD(顺便说一句,这是动态的),这是问题的根源。我还担心没有解决方法/配置,因为不同的 DTD 意味着不同的解析器,所以 CKEditor 不是适合您的工具。对不起。

您可以在此票证中找到更多信息。