tiptap/docs/api/extensions.md
2023-03-29 18:18:12 +02:00

6.8 KiB
Raw Blame History

tableOfContents
true

Extensions

Introduction

Extensions add new capabilities to Tiptap and youll read the word extension here very often. Actually, there are literal Extensions. Those cant add to the schema, but can add functionality or change the behaviour of the editor.

There are also some extensions with more capabilities. We call them nodes and marks which can render content in the editor.

List of provided extensions

Title StarterKit (view) Source Code
BubbleMenu GitHub
CharacterCount GitHub
Collaboration GitHub
CollaborationCursor GitHub
Color GitHub
Dropcursor Included GitHub
FloatingMenu GitHub
Focus GitHub
FontFamily GitHub
Gapcursor Included GitHub
History Included GitHub
InvisibleCharacters Requires a Tiptap Pro subscription
Mathematics Requires a Tiptap Pro subscription
Placeholder GitHub
StarterKit GitHub
TextAlign GitHub
Typography GitHub
UniqueID Requires a Tiptap Pro subscription

You dont have to use it, but we prepared a @tiptap/starter-kit which includes the most common extensions. Read more about StarterKit.

Also a list of community extensions can be found in the Awesome Tiptap Repository. There is also a Discussion Thread about community extensions.

How extensions work

Although Tiptap tries to hide most of the complexity of ProseMirror, its built on top of its APIs and we recommend you to read through the ProseMirror Guide for advanced usage. Youll have a better understanding of how everything works under the hood and get more familiar with many terms and jargon used by Tiptap.

Existing nodes, marks and extensions can give you a good impression on how to approach your own extensions. To make it easier to switch between the documentation and the source code, we linked to the file on GitHub from every single extension documentation page.

We recommend to start with customizing existing extensions first, and create your own extensions with the gained knowledge later. Thats why all the examples below extend existing extensions, but all examples will work on newly created extensions aswell.

Create a new extension

Youre free to create your own extensions for Tiptap. Here is the boilerplate code thats needed to create and register your own extension:

import { Extension } from '@tiptap/core'

const CustomExtension = Extension.create({
  // Your code here
})

const editor = new Editor({
  extensions: [
    // Register your custom extension with the editor.
    CustomExtension,
    // … and dont forget all other extensions.
    Document,
    Paragraph,
    Text,
    // …
  ],
})

You can easily bootstrap a new extension via our CLI.

npm init tiptap-extension

Learn more about custom extensions in our guide.