tiptap/packages/core/src/helpers/generateText.ts
Philipp Kühn e07a5b625d
refactor: Use named exports instead of default exports (#2238)
* use named exports instead of default exports

* fix tests

Co-authored-by: Philipp Kühn <philippkuehn@MacBook-Pro-von-Philipp.local>
2021-12-06 12:00:09 +01:00

30 lines
786 B
TypeScript

import { Node } from 'prosemirror-model'
import { getSchema } from './getSchema'
import { Extensions, JSONContent, TextSerializer } from '../types'
import { getTextSeralizersFromSchema } from './getTextSeralizersFromSchema'
import { getText } from './getText'
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,
...getTextSeralizersFromSchema(schema),
},
})
}