tidying html with ckeditor

笑着哭i 提交于 2019-12-06 00:34:58

Please, try to do the following before you save(just to process data with CKEditor native data processor):

    var yourEditor = CKEDITOR.instances.yourEditor;
    // retrieve current data from editor and process it with its dataprocessor
    var formattedDataForWysiWyg = yourEditor.dataProcessor.toHtml(yourEditor.getData());
    // "decode" content processed by ckeditor
    var sourceData = yourEditor.dataProcessor.toDataFormat(formattedDataForWysiWyg);
    // set formatted data back
    yourEditor.setData(sourceData);

Sure, it'll be perfomance hit if you do it frequently.

UPDATE: Sorry, I misled you a bit, but after you mentioned "{cke_protected}" I remembered. So, "toHtml" method of dataProcessor does the following: fixes broken html and wraps protected elements(scripts, flash) into special code constructions to prohibit editing through wysiwyg mode, but when the same html should be displayed in source mode, editor uses "toDataFormat" method of dataProcessor to remove all ckeditor-related code constructions. So, see my update above.

UPDATE 2: New solution works for both 3.6.2 and 3.5.3 versions of CKEditor.

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