mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-22 08:07:50 +08:00
e97630c639
* Require .js endings * add extension alias for cypress to resolve ts files with js endings
28 lines
788 B
TypeScript
28 lines
788 B
TypeScript
import { Node } from '@tiptap/pm/model'
|
|
|
|
import { Extensions, JSONContent, TextSerializer } from '../types.js'
|
|
import { getSchema } from './getSchema.js'
|
|
import { getText } from './getText.js'
|
|
import { getTextSerializersFromSchema } from './getTextSerializersFromSchema.js'
|
|
|
|
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: {
|
|
...getTextSerializersFromSchema(schema),
|
|
...textSerializers,
|
|
},
|
|
})
|
|
}
|