2021-09-10 05:51:05 +08:00
|
|
|
import { Node } from 'prosemirror-model'
|
2021-12-06 19:00:09 +08:00
|
|
|
import { getSchema } from './getSchema'
|
2021-09-10 05:51:05 +08:00
|
|
|
import { Extensions, JSONContent, TextSerializer } from '../types'
|
2022-05-03 04:01:07 +08:00
|
|
|
import { getTextSerializersFromSchema } from './getTextSerializersFromSchema'
|
2021-12-06 19:00:09 +08:00
|
|
|
import { getText } from './getText'
|
2021-09-10 05:51:05 +08:00
|
|
|
|
2021-12-06 19:00:09 +08:00
|
|
|
export function generateText(
|
2021-09-10 05:51:05 +08:00
|
|
|
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,
|
2022-05-03 04:01:07 +08:00
|
|
|
...getTextSerializersFromSchema(schema),
|
2021-09-10 05:51:05 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|