Remove styles when pasting from Word or other source

两盒软妹~` 提交于 2019-12-21 05:22:12

问题


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?


回答1:


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;



回答2:


Try not loading the paste extension.



来源:https://stackoverflow.com/questions/1056142/remove-styles-when-pasting-from-word-or-other-source

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