CKEditor disable auto-editing HTML code

落爺英雄遲暮 提交于 2020-08-26 02:12:39

问题


I need in one of my CKEditors to disable autoediting code. If I put this code as HTML:

<div class="kontaktJeden">
                <div class="obr">
                    <img src="images/insol.png" alt="">
                </div>
                <div class="text">
                    <table>
                        <tr><td><span class="meno"><strong>Text.</strong></span></td></tr>
                        <tr><td><span class="text">Text</span></td></tr>
                        <tr><td><span class="ico"><img src="images/ico.png" alt="">Text</span></td></tr>
                        <tr><td><span class="dic"><img src="images/dic.png" alt="">Text</span></td></tr>
                <!--         <tr><td><span class="mob"><img src="images/phone.png" alt="">Text</span></td></tr> -->
                        <tr><td><span class="mail"><img src="images/mail.png" alt="">Text</span></td></tr>
                        <!-- <tr><td><a href=""><img src="images/fb.png" alt=""></a><a href=""><img src="images/yt.png" alt=""></a></td></tr> -->
                    </table>
                </div>

CKEditor will change it to:

<table>
    <tbody>
        <tr>
            <td><strong>Text.</strong></td>
        </tr>
        <tr>
            <td>Text</td>
        </tr>
        <tr>
            <td><img alt="" src="images/ico.png" />Text</td>
        </tr>
        <tr>
            <td><img alt="" src="images/dic.png" />Text</td>
        </tr>
        <!--         <tr><td><span class="mob"><img src="images/phone.png" alt="">Text</span></td></tr> -->
        <tr>
            <td><img alt="" src="images/mail.png" />Text</td>
        </tr>
        <!-- <tr><td><a href=""><img src="images/fb.png" alt=""></a><a href=""><img src="images/yt.png" alt=""></a></td></tr> -->
    </tbody>
</table>

automatically. How can I disable it?

Thanks for any answer.


回答1:


You cannot switch this off. There are reasons why CKEditor reformats your data:

  1. It needs to parse it to fix issues, because it needs to have valid source while editing.
  2. It needs to process your data, because your data needs to be adapted for editing in contenteditable.
  3. It passes your data through browser's DOM, so formatting is lost, because DOM does not keep it.

From the source you posted, you only can keep your classes and divs (if that was your problem). They are stripped by CKEditor because they are not allowed. Read about the Advanced Content Filter which settings you can extend using config.extraAllowedContent.




回答2:


Solved this issue by disabling "clean up". Other options (allowedContent, extraAllowedContent) working only for tags (attributes removing anyway). Version 4.4.5.

allowedContent: true


来源:https://stackoverflow.com/questions/18363850/ckeditor-disable-auto-editing-html-code

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