Client-side Javascript to split dummy HTML from CKEditor

I believe this may be due to the Need Pure / jQuery Javascript Solution for clearing Word HTML from the text area

But in my case, I use CKEditor; however, before sending data to the server (or after receiving it), I would like to remove the "HTML tags" of HTML tags and comments, such as those that appear when pasted from the latest (2007 or later) versions of Microsoft Office. Since the server side is a third-party application, I would prefer to make this client side if I can. Yes, I know about the security risks associated with this; it is simply intended to disinfect data in general use cases.

Are there any general methods or existing libraries (especially jQuery-friendly) that can do this? Note that I do not want to encode or delete all HTML files, only ores related to Office.

+3
source share
1 answer

Have you tried CKEditor built-in to Word cleanup features? It seems to start automatically when using the "Insert from word" dialog, but can also be used from your code. I'm not a CKEditor API expert, so there may be a more efficient or proper way to do this, but this seems to work with the current version (3.3.1):

function cleanUp() {

    if (!CKEDITOR.cleanWord) {
        // since the filter is lazily loaded by the pastefromword plugin we need to add it ourselves. 
        // We use the same function as the callback for when the cleanup filter is loaded. Change the script path to the correct one
        CKEDITOR.scriptLoader.load("../plugins/pastefromword/filter/default.js", cleanUp, null, false, true );
        alert('loading script for the first usage');
    } else { // The cleanWord is available for use

        // change to the correct editor instance
        var editor = CKEDITOR.instances.editor1;
        // perform the clean up
        var cleanedUpData = CKEDITOR.cleanWord(editor .getData(),  editor );

        // do something with the clean up
        alert(cleanedUpData);
    }
}

cleanUp();

, default.js . , http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html ( "pasteFromWord" ).

- , , WordOff (http://wordoff.org/). , jsonp- , .

+3

Source: https://habr.com/ru/post/1757722/


All Articles