mirror of
https://github.com/outline/outline.git
synced 2026-11-30 09:00:18 +03:00
fix: textBetween line breaks
This commit is contained in:
1 parent
3437bd3a6c
commit
e7c6d5b7cd
1 file changed
+23
-13
@@ -16,27 +16,37 @@ export default function textBetween(
|
||||
to: number,
|
||||
plainTextSerializers: Record<string, PlainTextSerializer | undefined>
|
||||
): string {
|
||||
const blockSeparator = "\n\n";
|
||||
let text = "";
|
||||
let separated = true;
|
||||
let first = true;
|
||||
const blockSeparator = "\n";
|
||||
|
||||
doc.nodesBetween(from, to, (node, pos) => {
|
||||
const toPlainText = plainTextSerializers[node.type.name];
|
||||
let nodeText = "";
|
||||
|
||||
if (toPlainText) {
|
||||
if (node.isBlock && !separated) {
|
||||
text += blockSeparator;
|
||||
separated = true;
|
||||
}
|
||||
|
||||
text += toPlainText(node);
|
||||
nodeText += toPlainText(node);
|
||||
} else if (node.isText) {
|
||||
text += node.text?.slice(Math.max(from, pos) - pos, to - pos);
|
||||
separated = false;
|
||||
} else if (node.isBlock && !separated) {
|
||||
text += blockSeparator;
|
||||
separated = true;
|
||||
nodeText += node.textBetween(
|
||||
Math.max(from, pos) - pos,
|
||||
to - pos,
|
||||
blockSeparator
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
node.isBlock &&
|
||||
((node.isLeaf && nodeText) || node.isTextblock) &&
|
||||
blockSeparator
|
||||
) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
text += blockSeparator;
|
||||
}
|
||||
}
|
||||
|
||||
text += nodeText;
|
||||
});
|
||||
|
||||
return text;
|
||||
|
||||
Reference in new issue
Block a user