fix: filter and parse the extra line breaks of the text
This commit is contained in:
parent
f865c2d9a9
commit
cc935e2645
|
@ -1065,15 +1065,17 @@ class Inline implements InlineModelInterface {
|
||||||
else {
|
else {
|
||||||
let parentMark: NodeInterface | undefined =
|
let parentMark: NodeInterface | undefined =
|
||||||
markApi.closest(node);
|
markApi.closest(node);
|
||||||
|
|
||||||
|
const element = node as NodeInterface;
|
||||||
while (
|
while (
|
||||||
parentMark &&
|
parentMark &&
|
||||||
!parentMark.equal(node) &&
|
!parentMark.equal(node) &&
|
||||||
nodeApi.isMark(parentMark, schema)
|
nodeApi.isMark(parentMark, schema)
|
||||||
) {
|
) {
|
||||||
const cloneMark = parentMark.clone();
|
const cloneMark = parentMark.clone();
|
||||||
const inlineMark = node.clone();
|
const cloneInline = node.clone();
|
||||||
const children = parentMark.children();
|
const children = parentMark.children();
|
||||||
children.each((markChild) => {
|
children.each((markChild, index) => {
|
||||||
// 零宽字符的文本跳过
|
// 零宽字符的文本跳过
|
||||||
if (
|
if (
|
||||||
markChild.nodeType === 3 &&
|
markChild.nodeType === 3 &&
|
||||||
|
@ -1081,13 +1083,13 @@ class Inline implements InlineModelInterface {
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((node as NodeInterface).equal(markChild)) {
|
if (
|
||||||
|
element.equal(markChild) ||
|
||||||
|
children.eq(index)?.contains(element)
|
||||||
|
) {
|
||||||
node = nodeApi.wrap(
|
node = nodeApi.wrap(
|
||||||
nodeApi.replace(
|
nodeApi.replace(element, cloneMark),
|
||||||
node as NodeInterface,
|
cloneInline,
|
||||||
cloneMark,
|
|
||||||
),
|
|
||||||
inlineMark,
|
|
||||||
);
|
);
|
||||||
this.repairBoth(node);
|
this.repairBoth(node);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -607,6 +607,18 @@ class Parser implements ParserInterface {
|
||||||
schema || this.editor.schema,
|
schema || this.editor.schema,
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
|
const children = node.children().toArray();
|
||||||
|
// 子节点还有block节点,则不换行
|
||||||
|
if (
|
||||||
|
children.some((child) => child.name === 'br') ||
|
||||||
|
children.some((child) =>
|
||||||
|
this.editor.node.isBlock(
|
||||||
|
child,
|
||||||
|
schema || this.editor.schema,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return;
|
||||||
result.push('\n');
|
result.push('\n');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -209,7 +209,11 @@ export default class<T extends CodeBlockOptions> extends Plugin<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let code = new Parser(node, this.editor).toText();
|
let code = new Parser(node, this.editor).toText(
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
false,
|
||||||
|
);
|
||||||
code = unescape(code.replace(/\u200b/g, ''));
|
code = unescape(code.replace(/\u200b/g, ''));
|
||||||
this.editor.card.replaceNode<CodeBlockValue>(node, 'codeblock', {
|
this.editor.card.replaceNode<CodeBlockValue>(node, 'codeblock', {
|
||||||
mode: syntax || 'plain',
|
mode: syntax || 'plain',
|
||||||
|
|
Loading…
Reference in New Issue