解决编辑器中 从word粘贴内容 功能失效的方法
某些站点的编辑器中可能会出现word粘贴功能不能正常使用的问题,特给出以下解决方法:该方法可能不一定完全解决你的问题,如果不能解决,请跟帖询问
打开文件:\static\js\edit.js
查找以下代码:function pasteWord(str) {
var mstest = /<\w[^>]* class="?"?/gi;
if(mstest.test(str)){
str = str.replace(/<!--\+?<!\-->/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 + ';';
}
re = new RegExp('(^|[;\\s])text-indent:\\s*([^;]+);?', 'ig');
match = re.exec($3);
if(match != null) {
style += 'text-indent:' + parseInt(parseInt(match) / 10) + 'em;';
}
re = new RegExp('(^|[;\\s])font-size:\\s*([^;]+);?', 'ig');
match = re.exec($3);
if(match != null) {
style += 'font-size:' + match + ';';
}
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(/ /, " ");
var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)", 'ig');
str = str.replace(re, "<div$2</div>");
if(!wysiwyg) {
str = html2bbcode(str);
}
insertText(str, str.length, 0);
}
}替换为:function pasteWord(str) {
var mstest = /<\w[^>]* class="?"?/gi;
//if(mstest.test(str)){
str = str.replace(/<!--\+?<!\-->/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 + ';';
}
re = new RegExp('(^|[;\\s])text-indent:\\s*([^;]+);?', 'ig');
match = re.exec($3);
if(match != null) {
style += 'text-indent:' + parseInt(parseInt(match) / 10) + 'em;';
}
re = new RegExp('(^|[;\\s])font-size:\\s*([^;]+);?', 'ig');
match = re.exec($3);
if(match != null) {
style += 'font-size:' + parseInt(match) + '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(/ /, " ");
var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)", 'ig');
str = str.replace(re, "<div$2</div>");
if(!wysiwyg) {
str = html2bbcode(str);
}
insertText(str, str.length, 0);
//}
}替换之后更新一下缓存,然后就OK了~
红色标记是修改的地方:
function pasteWord(str) {
var mstest = /<\w[^>]* class="?"?/gi;
//if(mstest.test(str)){
str = str.replace(/<!--\+?<!\-->/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 + ';';
}
re = new RegExp('(^|[;\\s])text-indent:\\s*([^;]+);?', 'ig');
match = re.exec($3);
if(match != null) {
style += 'text-indent:' + parseInt(parseInt(match) / 10) + 'em;';
}
re = new RegExp('(^|[;\\s])font-size:\\s*([^;]+);?', 'ig');
match = re.exec($3);
if(match != null) {
style += 'font-size:' + parseInt(match) + '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(/ /, " ");
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]