最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Remove styles when pasting from Word or other source - Stack Overflow

programmeradmin1浏览0评论

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 mand+V.

Any help?

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 mand+V.

Any help?

Share Improve this question asked Jun 29, 2009 at 0:40 dougoftheabacidougoftheabaci
Add a ment  | 

2 Answers 2

Reset to default 6

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;

Try not loading the paste extension.

发布评论

评论列表(0)

  1. 暂无评论