2023-02-03 00:37:33 +08:00
|
|
|
import { Node } from '@tiptap/pm/model'
|
2022-06-08 20:10:25 +08:00
|
|
|
|
2023-07-01 03:03:49 +08:00
|
|
|
import { Extensions, JSONContent, TextSerializer } from '../types.js'
|
|
|
|
import { getSchema } from './getSchema.js'
|
|
|
|
import { getText } from './getText.js'
|
|
|
|
import { getTextSerializersFromSchema } from './getTextSerializersFromSchema.js'
|
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?: {
|
2023-02-03 00:37:33 +08:00
|
|
|
blockSeparator?: string
|
|
|
|
textSerializers?: Record<string, TextSerializer>
|
2021-09-10 05:51:05 +08:00
|
|
|
},
|
|
|
|
): string {
|
2023-02-03 00:37:33 +08:00
|
|
|
const { blockSeparator = '\n\n', textSerializers = {} } = options || {}
|
2021-09-10 05:51:05 +08:00
|
|
|
const schema = getSchema(extensions)
|
|
|
|
const contentNode = Node.fromJSON(schema, doc)
|
|
|
|
|
|
|
|
return getText(contentNode, {
|
|
|
|
blockSeparator,
|
|
|
|
textSerializers: {
|
2022-05-03 04:01:07 +08:00
|
|
|
...getTextSerializersFromSchema(schema),
|
2022-12-16 19:47:03 +08:00
|
|
|
...textSerializers,
|
2021-09-10 05:51:05 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|