mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-04 00:37:57 +08:00
8c6751f0c6
* chore: add precommit hook for eslint fixes, fix linting issues * chore: add eslint import sort plugin
31 lines
790 B
TypeScript
31 lines
790 B
TypeScript
import { Node } from 'prosemirror-model'
|
|
|
|
import { Extensions, JSONContent, TextSerializer } from '../types'
|
|
import { getSchema } from './getSchema'
|
|
import { getText } from './getText'
|
|
import { getTextSerializersFromSchema } from './getTextSerializersFromSchema'
|
|
|
|
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),
|
|
},
|
|
})
|
|
}
|