Discuz!官方免费开源建站系统

 找回密码
 立即注册
搜索

[已解决] 解决编辑器中word粘贴内容功能失效的方法

[复制链接]
cr180 发表于 2012-9-14 11:56:54 | 显示全部楼层 |阅读模式
某些站点的编辑器中可能会出现word粘贴功能不能正常使用的问题,特给出以下解决方法:
该方法可能不一定完全解决你的问题,如果不能解决,请跟帖询问



打开文件:\static\js\edit.js
查找:
  1. function pasteWord(str) {
  2.     var mstest = /<\w[^>]* class="?[MsoNormal|xl]"?/gi;
  3.     if(mstest.test(str)){
  4.         str = str.replace(/<!--\[if[\s\S]+?<!\[endif\]-->/gi, "");
  5.         str = str.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3");
  6.         str = str.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, function ($1, $2, $3, $4) {
  7.             var style = '';
  8.             re = new RegExp('(^|[;\\s])color:\\s*([^;]+);?', 'ig');
  9.             match = re.exec($3);
  10.             if(match != null) {
  11.                 style += 'color:' + match[2] + ';';
  12.             }
  13.             re = new RegExp('(^|[;\\s])text-indent:\\s*([^;]+);?', 'ig');
  14.             match = re.exec($3);
  15.             if(match != null) {
  16.                 style += 'text-indent:' + parseInt(parseInt(match[2]) / 10) + 'em;';
  17.             }
  18.             re = new RegExp('(^|[;\\s])font-size:\\s*([^;]+);?', 'ig');
  19.             match = re.exec($3);
  20.             if(match != null) {
  21.                 style += 'font-size:' + match[2] + ';';
  22.             }
  23.             if(style) {
  24.                 style = ' style="' + style + '"';
  25.             }
  26.             return '<' + $2 + style + $4;
  27.         });
  28.         str = str.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3");
  29.         str = str.replace(/<\\?\?xml[^>]*>/gi, "");
  30.         str = str.replace(/<\/?\w+:[^>]*>/gi, "");
  31.         str = str.replace(/&nbsp;/, " ");
  32.         var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)", 'ig');
  33.         str = str.replace(re, "<div$2</div>");
  34.         if(!wysiwyg) {
  35.             str = html2bbcode(str);
  36.         }
  37.         insertText(str, str.length, 0);
  38.     }
  39. }
复制代码
替换为:
  1. function pasteWord(str) {
  2.     var mstest = /<\w[^>]* class="?[MsoNormal|xl]"?/gi;
  3.     //if(mstest.test(str)){
  4.         str = str.replace(/<!--\[if[\s\S]+?<!\[endif\]-->/gi, "");
  5.         str = str.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3");
  6.         str = str.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, function ($1, $2, $3, $4) {
  7.             var style = '';
  8.             re = new RegExp('(^|[;\\s])color:\\s*([^;]+);?', 'ig');
  9.             match = re.exec($3);
  10.             if(match != null) {
  11.                 style += 'color:' + match[2] + ';';
  12.             }
  13.             re = new RegExp('(^|[;\\s])text-indent:\\s*([^;]+);?', 'ig');
  14.             match = re.exec($3);
  15.             if(match != null) {
  16.                 style += 'text-indent:' + parseInt(parseInt(match[2]) / 10) + 'em;';
  17.             }
  18.             re = new RegExp('(^|[;\\s])font-size:\\s*([^;]+);?', 'ig');
  19.             match = re.exec($3);
  20.             if(match != null) {
  21.                 style += 'font-size:' + parseInt(match[2]) + 'pt;';
  22.             }
  23.             if(style) {
  24.                 style = ' style="' + style + '"';
  25.             }
  26.             return '<' + $2 + style + $4;
  27.         });
  28.         str = str.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3");
  29.         str = str.replace(/<\\?\?xml[^>]*>/gi, "");
  30.         str = str.replace(/<\/?\w+:[^>]*>/gi, "");
  31.         str = str.replace(/&nbsp;/, " ");
  32.         var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)", 'ig');
  33.         str = str.replace(re, "<div$2</div>");
  34.         if(!wysiwyg) {
  35.             str = html2bbcode(str);
  36.         }
  37.         insertText(str, str.length, 0);
  38.     //}
  39. }
复制代码
回复

使用道具 举报

 楼主| cr180 发表于 2012-9-14 11:58:14 | 显示全部楼层
修改的地方:

function pasteWord(str) {
    var mstest = /<\w[^>]* class="?[MsoNormal|xl]"?/gi;
    //if(mstest.test(str)){
        str = str.replace(/<!--\[if[\s\S]+?<!\[endif\]-->/gi, "");
        str = str.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3");
        str = str.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, function ($1, $2, $3, $4) {
            var style = '';
            re = new RegExp('(^|[;\\s])color:\\s*([^;]+);?', 'ig');
            match = re.exec($3);
            if(match != null) {
                style += 'color:' + match[2] + ';';
            }
            re = new RegExp('(^|[;\\s])text-indent:\\s*([^;]+);?', 'ig');
            match = re.exec($3);
            if(match != null) {
                style += 'text-indent:' + parseInt(parseInt(match[2]) / 10) + 'em;';
            }
            re = new RegExp('(^|[;\\s])font-size:\\s*([^;]+);?', 'ig');
            match = re.exec($3);
            if(match != null) {
                style += 'font-size:' + parseInt(match[2]) + 'pt;';
            }
            if(style) {
                style = ' style="' + style + '"';
            }
            return '<' + $2 + style + $4;
        });
        str = str.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3");
        str = str.replace(/<\\?\?xml[^>]*>/gi, "");
        str = str.replace(/<\/?\w+:[^>]*>/gi, "");
        str = str.replace(/&nbsp;/, " ");
        var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)", 'ig');
        str = str.replace(re, "<div$2</div>");
        if(!wysiwyg) {
            str = html2bbcode(str);
        }
        insertText(str, str.length, 0);
    //}
}

回复

使用道具 举报

liqu12511 发表于 2012-9-14 15:35:35 | 显示全部楼层
学着修改试试
回复

使用道具 举报

天堂没有雨天 发表于 2012-9-14 19:00:21 | 显示全部楼层
很给力,支持
回复

使用道具 举报

1314学习网 发表于 2012-9-14 19:53:39 | 显示全部楼层
前排支持。。。
回复

使用道具 举报

KiSsゞ 发表于 2012-9-14 19:58:32 | 显示全部楼层
没用过这个功能呢,支持下
回复

使用道具 举报

桃源老赵 发表于 2012-9-14 19:59:29 | 显示全部楼层
怎么去掉这个功能图标呢
回复

使用道具 举报

binxiannet 发表于 2012-9-20 21:51:39 | 显示全部楼层
谢谢楼主,我收藏了,待后边修改到了试试/
回复

使用道具 举报

Jayjr 发表于 2012-10-13 21:44:43 | 显示全部楼层
我想去掉这个功能,楼主能教我吗?
回复

使用道具 举报

单车34 发表于 2012-11-7 20:43:27 | 显示全部楼层
好,已经处理了,谢谢
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2025-9-3 13:57 , Processed in 0.110316 second(s), 15 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表