Discuz教程网

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

[复制链接]
authicon dly 发表于 2012-9-14 19:53:09 | 显示全部楼层 |阅读模式
某些站点的编辑器中可能会出现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(/ /, " ");
  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(/ /, " ");
  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. }
复制代码

修改的地方:

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);
    //}
}


相关阅读:
1、财付通支付提示:Subject长度不能大于32的解决方法(X2.5 0901版)
2、升级X2.5到20120901版本后,回帖提示“内部错误,无法显示此内容”的解决办法
3、X2.5论坛开启内存优化出现提醒负数的解决方法
4、Discuz!X帖子底部添加“联系我时,请一定说明是在某网站看到的”
5、Discuz!X精品小款新版化龙巷二级导航



上一篇:等了这么久,大家的内心都聚集了很多的运营点子,一起交流分享吧。
下一篇:Discuz X2.5 0901版本新功能是否允許UID登入及其跟其他功能的相互性
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2024-5-17 06:05

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

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