mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-04 00:37:57 +08:00
fe6a3e7491
* move getTextBetween method * add getText method * refactoring * refactoring * refactoring * move renderText to schema, add generateText method * add GenerateText demo * docs: update * remove demo from html page
30 lines
782 B
TypeScript
30 lines
782 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 default 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),
|
|
},
|
|
})
|
|
}
|