paper-ai-release-24-07-21/utils/others/slateutils.ts
Liuweiqing 9429952505 init
2024-01-18 15:46:18 +08:00

22 lines
431 B
TypeScript

import { Node } from "slate";
const extractText = (nodes: Node[]): string => {
return nodes
.map((node: any) => {
// 如果节点是文本节点
if ("text" in node) {
return node.text;
}
// 如果节点是元素且包含子节点
if (Array.isArray(node.children)) {
return extractText(node.children);
}
return "";
})
.join("");
};
export { extractText };