dougoftheabaci
dougoftheabaci

Reputation:

Remove styles when pasting from Word or other source

I'm trying to set it up so that when I paste text, specifically from Word or another source, all the styling will be stripped. I'm happy to let bold and italic styles stay as well as lists and so forth, but the rest should go.

How can I do this?

I know there is a plugin that will allow me to do this if I paste via clicking a button but I'm looking for if someone presses CTRL+V or command+V.

Any help?

Upvotes: 4

Views: 4614

Answers (2)

Ber
Ber

Reputation: 41793

I am using TinyMCE with the paste plugin an the following setup:

paste_create_paragraphs : false,
paste_create_linebreaks : false,
paste_use_dialog : true,
paste_auto_cleanup_on_paste : true,
paste_convert_middot_lists : false,
paste_unindented_list_class : "unindentedList",
paste_convert_headers_to_strong : true,
paste_insert_word_content_callback : "convertWord",

And it does just that: When you hit "Ctrl-V", a dialog pops up letting you paste in your contents, which gets autocleaned from any Word related stuff.

You may also need this no-op callback:

function convertWord(type, content) {
switch (type) {
    // Gets executed before the built in logic performes it's cleanups
    case "before":
        //content = content.toLowerCase(); // Some dummy logic
        break;

    // Gets executed after the built in logic performes it's cleanups
    case "after":
        //content = content.toLowerCase(); // Some dummy logic
        break;
}

return content;

Upvotes: 6

MiffTheFox
MiffTheFox

Reputation: 21555

Try not loading the paste extension.

Upvotes: -1

Related Questions