Files
tiptap/docs/src/docPages/api/schema/get-schema.md
2020-09-04 12:35:31 +02:00

1.3 KiB
Raw Blame History

Get the underlying ProseMirror schema

There are a few use cases where you need to work with the underlying schema. Youll need that if youre using the tiptap collaborative text editing features or if you want to manually render your content as HTML.

With an Editor

If you need this on the client side and need an editor instance anyway, its available through the editor:

import { Editor } from '@tiptap/core'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'

const editor = new Editor({
  extensions: [
    new Document,
    new Paragraph,
    new Text,
    // add more extensions here
  ])
})

const schema = editor.schema

Without an Editor

If you just want to have the schema without initializing an actual editor, you can use the getSchema helper function. It needs an array of available extensions and conveniently generates a ProseMirror schema for you:

import { getSchema } from '@tiptap/core'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'

const schema = getSchema([
  new Document,
  new Paragraph,
  new Text,
  // add more extensions here
])