tiptap/packages/core/src/helpers/generateText.ts

30 lines
789 B
TypeScript
Raw Normal View History

import { Node } from 'prosemirror-model'
import { getSchema } from './getSchema'
import { Extensions, JSONContent, TextSerializer } from '../types'
import { getTextSerializersFromSchema } from './getTextSerializersFromSchema'
import { getText } from './getText'
export function generateText(
doc: JSONContent,
extensions: Extensions,
options?: {
blockSeparator?: string,
textSerializers?: Record<string, TextSerializer>,
},
): string {
const {
blockSeparator = '\n\n',
textSerializers = {},
} = options || {}
const schema = getSchema(extensions)
const contentNode = Node.fromJSON(schema, doc)
return getText(contentNode, {
blockSeparator,
textSerializers: {
...textSerializers,
...getTextSerializersFromSchema(schema),
},
})
}