how to disable tag validation in ckeditor?

我的未来我决定 提交于 2019-12-25 04:13:18

问题


CKeditor apparently automatically creates matching end tags when you enter a start tag. Is there a way to turn this behavior off?

I have a situation where I am creating two blocks of text in an admin program using CKeditor, then I'm using these to paint a page with the first block, some static content, and then the second block. Now I've got a case where I want to wrap the static content in a table. I was thinking, No problem, I'll just put the <table> tag in the first block and the </table> tag in the second block, and the static content will be inside the table. But no, CKeditor insists on closing the table tag in the first block.

In general, I can go to source mode and enter HTML directly, but CKeditor then decides to reformat my tagging. This seems to rather defeat the purpose of having a source mode. (I hate it when I tell the computer what I want and it tells me, No, you're wrong, I know better than you what you want!)


回答1:


CKEditor produces valid HTML. Valid HTML has to include both - start and end tags. There's no way to change this behaviour without hacking editor. Note that even if you'll force editor to produce content without one of these tags it will then try to fix this and won't do this as you expect. E.g. load:

<p>foo</p></td></tr></table>

And you'll completely loose this table so only regexp based fix on data loading could help. In the opposite case:

<table><tr><td><p>foo</p>

You'll end up with paragraph wrapped with table, so it's better. But what if someone would remove this table from editor contents?

Therefore you should do this integration outside editor - prepend table to contents of one editor and append to contents of second one. You simply cannot force editor to work on partial HTML.



来源:https://stackoverflow.com/questions/15769409/how-to-disable-tag-validation-in-ckeditor

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