tiptap/packages/core/src/helpers/generateText.ts
Ben Asher e97630c639
Require file extensions for imports and exports (#4001)
* Require .js endings

* add extension alias for cypress to resolve ts files with js endings
2023-06-30 21:03:49 +02:00

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,
},
})
}