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 {
|
||||
let parentMark: NodeInterface | undefined =
|
||||
markApi.closest(node);
|
||||
|
||||
const element = node as NodeInterface;
|
||||
while (
|
||||
parentMark &&
|
||||
!parentMark.equal(node) &&
|
||||
nodeApi.isMark(parentMark, schema)
|
||||
) {
|
||||
const cloneMark = parentMark.clone();
|
||||
const inlineMark = node.clone();
|
||||
const cloneInline = node.clone();
|
||||
const children = parentMark.children();
|
||||
children.each((markChild) => {
|
||||
children.each((markChild, index) => {
|
||||
// 零宽字符的文本跳过
|
||||
if (
|
||||
markChild.nodeType === 3 &&
|
||||
|
@ -1081,13 +1083,13 @@ class Inline implements InlineModelInterface {
|
|||
) {
|
||||
return;
|
||||
}
|
||||
if ((node as NodeInterface).equal(markChild)) {
|
||||
if (
|
||||
element.equal(markChild) ||
|
||||
children.eq(index)?.contains(element)
|
||||
) {
|
||||
node = nodeApi.wrap(
|
||||
nodeApi.replace(
|
||||
node as NodeInterface,
|
||||
cloneMark,
|
||||
),
|
||||
inlineMark,
|
||||
nodeApi.replace(element, cloneMark),
|
||||
cloneInline,
|
||||
);
|
||||
this.repairBoth(node);
|
||||
} else {
|
||||
|
|
|
@ -607,6 +607,18 @@ class Parser implements ParserInterface {
|
|||
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');
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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, ''));
|
||||
this.editor.card.replaceNode<CodeBlockValue>(node, 'codeblock', {
|
||||
mode: syntax || 'plain',
|
||||
|
|
Loading…
Reference in New Issue