Skip to content Skip to sidebar Skip to footer

Client-side Javascript Code To Strip Bogus Html From Ckeditor

I believe this may be related to Need Pure/jQuery Javascript Solution For Cleaning Word HTML From Text Area But in my case I am using CKEditor; however, before sending the data to

Solution 1:

Did you try CKEditor built in Word clean up functionality? It seems to be run automatically when using the "Paste From Word" dialog, but can also be used from your code. I'm not an expert on CKEditor API, so there might be a more efficient or correct way of doing this, but this seems to work on the current release (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 instancevar editor = CKEDITOR.instances.editor1;
        // perform the clean upvar cleanedUpData = CKEDITOR.cleanWord(editor .getData(),  editor );

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

cleanUp();

If you're not happy with this clean up you can modify default.js for your clean up needs. There are some configuration options available for the cleanup, check http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html (search for "pasteFromWord" options).

If you need something more advanced, but that will require a server access, I suggest you check WordOff (http://wordoff.org/). You might be able to build a proxy and jsonp wrapper around their service so you can use it from the client without a server installation.

Post a Comment for "Client-side Javascript Code To Strip Bogus Html From Ckeditor"