feat: mark节点粘贴过滤不完全
This commit is contained in:
parent
dddc6f28a1
commit
cbe5e37b21
|
@ -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, '');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in New Issue