feat: mark节点粘贴过滤不完全

This commit is contained in:
yanmao 2021-12-07 00:10:42 +08:00
parent dddc6f28a1
commit cbe5e37b21
2 changed files with 26 additions and 3 deletions

View File

@ -28,8 +28,10 @@ export default class Paste {
getDefaultStyle() { getDefaultStyle() {
const defaultStyle = { const defaultStyle = {
color: tinycolor2(this.engine.container.css('color')).toHex(), color: tinycolor2(this.engine.container.css('color')).toHexString(),
'background-color': tinycolor2('white').toHex(), 'background-color': tinycolor2(
this.engine.container.css('background-color'),
).toHexString(),
'font-size': this.engine.container.css('font-size'), 'font-size': this.engine.container.css('font-size'),
}; };
return defaultStyle; return defaultStyle;
@ -77,7 +79,7 @@ export default class Paste {
defautlStyleKeys.forEach((key) => { defautlStyleKeys.forEach((key) => {
const value = styles[key]; const value = styles[key];
if (!value) return; if (!value) return;
if (value === defaultStyle[key]) { if (value.toLowerCase() === defaultStyle[key].toLowerCase()) {
node.css(key, ''); node.css(key, '');
} }
}); });

View File

@ -221,6 +221,26 @@ class Parser implements ParserInterface {
oldRules.push(rule); oldRules.push(rule);
let newNode = filter(node); let newNode = filter(node);
if (!newNode) return; if (!newNode) return;
// 如果这个节点过滤掉所有属性样式后还是一个有效的节点就替换掉当前节点
const newAttributes = newNode.attributes();
const newStyle = getStyleMap(newAttributes.style || '');
delete newAttributes.style;
if (
Object.keys(newAttributes).length === 0 &&
Object.keys(newStyle).length === 0 &&
schema.getType(newNode) === 'mark'
) {
node.before(newNode);
const children = node.children();
newNode.append(
children.length > 0
? children
: $('\u200b', null),
);
node.remove();
node = newNode;
return;
}
//获取这个新的节点所属类型,并且不能是之前节点一样的规则 //获取这个新的节点所属类型,并且不能是之前节点一样的规则
let type = schema.getType( let type = schema.getType(
newNode, newNode,
@ -229,6 +249,7 @@ class Parser implements ParserInterface {
rule.type === 'mark' && rule.type === 'mark' &&
oldRules.indexOf(rule) < 0, oldRules.indexOf(rule) < 0,
); );
//如果是mark节点使用新节点包裹旧节点子节点 //如果是mark节点使用新节点包裹旧节点子节点
while (type === 'mark') { while (type === 'mark') {
const children = node.children(); const children = node.children();