提交 9daafbc4 编写于 作者: C campaign

添加retainOnlyLabelPasted配置,指定粘贴时是否是只保留标签模式

上级 014aa5c2
......@@ -54,8 +54,40 @@ UE.plugins['paste'] = function () {
var me = this;
me.setOpt({
retainOnlyLabelPasted : false
});
var txtContent, htmlContent, address;
function getPureHtml(html){
return html.replace(/<(\/?)([\w\-]+)([^>]*)>/gi, function (a, b, tagName, attrs) {
tagName = tagName.toLowerCase();
if ({img: 1}[tagName]) {
return a;
}
attrs = attrs.replace(/([\w\-]*?)\s*=\s*(("([^"]*)")|('([^']*)')|([^\s>]+))/gi, function (str, atr, val) {
if ({
'src': 1,
'href': 1,
'name': 1
}[atr.toLowerCase()]) {
return atr + '=' + val + ' '
}
return ''
});
if ({
'span': 1,
'div': 1
}[tagName]) {
return ''
} else {
return '<' + b + tagName + ' ' + utils.trim(attrs) + '>'
}
});
}
function filter(div) {
var html;
if (div.firstChild) {
......@@ -155,7 +187,7 @@ UE.plugins['paste'] = function () {
htmlContent = html.html;
address = me.selection.getRange().createAddress(true);
me.execCommand('insertHtml', htmlContent, true);
me.execCommand('insertHtml', me.getOpt('retainOnlyLabelPasted') === true ? getPureHtml(htmlContent) : htmlContent, true);
}
me.fireEvent("afterpaste", html);
}
......@@ -219,33 +251,8 @@ UE.plugins['paste'] = function () {
range.select(true);
me.__hasEnterExecCommand = true;
var html = htmlContent;
if (plainType === 2) {
html = html.replace(/<(\/?)([\w\-]+)([^>]*)>/gi, function (a, b, tagName, attrs) {
tagName = tagName.toLowerCase();
if ({img: 1}[tagName]) {
return a;
}
attrs = attrs.replace(/([\w\-]*?)\s*=\s*(("([^"]*)")|('([^']*)')|([^\s>]+))/gi, function (str, atr, val) {
if ({
'src': 1,
'href': 1,
'name': 1
}[atr.toLowerCase()]) {
return atr + '=' + val + ' '
}
return ''
});
if ({
'span': 1,
'div': 1
}[tagName]) {
return ''
} else {
return '<' + b + tagName + ' ' + utils.trim(attrs) + '>'
}
});
if (plainType === 2 ) {
html = getPureHtml(html);
} else if (plainType) {
html = txtContent;
}
......
......@@ -16,6 +16,7 @@
###新功能添加
1. 添加了enableContextMenu配置开关,开关右键菜单,默认为true
2. 添加disablePInList配置,指定产出的列表中是否嵌套P标签,默认是false
3. 添加retainOnlyLabelPasted配置,指定粘贴时是否是只保留标签模式,默认是false
##1.3.6
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册