Convert Figma logo to code with AI

ProseMirror logoprosemirror

The ProseMirror WYSIWYM editor

7,603
336
7,603
124

Top Related Projects

In-browser code editor (version 5, legacy)

43,060

Quill is a modern WYSIWYG editor built for compatibility and extensibility

22,569

A React framework for building text editors.

29,602

A completely customizable framework for building rich text editors. (Currently in beta.)

14,837

The world's #1 JavaScript library for rich text editing. Available for React, Vue and Angular

Powerful rich text editor framework with a modular architecture, modern integrations, and features like collaborative editing.

Quick Overview

ProseMirror is a toolkit for building rich-text editors on the web. It provides a set of building blocks for creating powerful, customizable editors with features like collaborative editing, schema validation, and modular architecture. ProseMirror is designed to be flexible and adaptable to various use cases.

Pros

  • Highly customizable and extensible
  • Strong focus on data consistency and schema validation
  • Supports collaborative editing out of the box
  • Modular architecture allows for easy integration of plugins and extensions

Cons

  • Steep learning curve for beginners
  • Documentation can be complex and sometimes lacking for advanced use cases
  • Requires more setup and configuration compared to simpler WYSIWYG editors
  • Performance can be an issue with very large documents or complex schemas

Code Examples

  1. Creating a basic editor:
import {EditorState} from "prosemirror-state"
import {EditorView} from "prosemirror-view"
import {Schema, DOMParser} from "prosemirror-model"
import {schema} from "prosemirror-schema-basic"

let state = EditorState.create({
  doc: DOMParser.fromSchema(schema).parse(document.querySelector("#content"))
})

let view = new EditorView(document.querySelector("#editor"), {state})
  1. Adding a simple plugin:
import {Plugin} from "prosemirror-state"

let myPlugin = new Plugin({
  props: {
    handleKeyDown(view, event) {
      if (event.key === "Enter" && event.shiftKey) {
        // Custom behavior for Shift+Enter
        return true
      }
      return false
    }
  }
})

let state = EditorState.create({
  schema,
  plugins: [myPlugin]
})
  1. Applying a transaction:
import {TextSelection} from "prosemirror-state"

view.dispatch(
  view.state.tr.insertText("Hello, ProseMirror!")
    .setSelection(TextSelection.create(
      view.state.doc,
      view.state.selection.from + 18
    ))
)

Getting Started

To get started with ProseMirror, follow these steps:

  1. Install the necessary packages:

    npm install prosemirror-state prosemirror-view prosemirror-model prosemirror-schema-basic
    
  2. Create a basic editor setup:

    import {EditorState} from "prosemirror-state"
    import {EditorView} from "prosemirror-view"
    import {Schema} from "prosemirror-model"
    import {schema} from "prosemirror-schema-basic"
    
    let state = EditorState.create({schema})
    let view = new EditorView(document.querySelector("#editor"), {state})
    
  3. Customize the editor by adding plugins, modifying the schema, or extending functionality as needed.

Competitor Comparisons

In-browser code editor (version 5, legacy)

Pros of CodeMirror 5

  • More mature and widely adopted, with a larger ecosystem of plugins and extensions
  • Better performance for handling large documents and syntax highlighting
  • Extensive language support out-of-the-box

Cons of CodeMirror 5

  • Less flexible for custom document structures and collaborative editing
  • More complex API and configuration compared to ProseMirror
  • Limited support for rich text editing features

Code Comparison

ProseMirror:

import {EditorState} from "prosemirror-state"
import {EditorView} from "prosemirror-view"
import {Schema} from "prosemirror-model"

let state = EditorState.create({schema: new Schema({/* ... */})})
let view = new EditorView(document.body, {state})

CodeMirror 5:

import CodeMirror from 'codemirror'
import 'codemirror/mode/javascript/javascript'

let editor = CodeMirror(document.body, {
  value: "function myScript() {\n\treturn 100;\n}",
  mode: "javascript"
})

Both libraries offer powerful text editing capabilities, but they serve different purposes. ProseMirror is more suited for rich text editing and custom document structures, while CodeMirror 5 excels in code editing with syntax highlighting and language support.

43,060

Quill is a modern WYSIWYG editor built for compatibility and extensibility

Pros of Quill

  • Easier to set up and use out of the box
  • More extensive documentation and examples
  • Larger community and ecosystem

Cons of Quill

  • Less flexible and customizable than ProseMirror
  • Limited support for complex document structures
  • Slower performance for large documents

Code Comparison

Quill initialization:

var quill = new Quill('#editor', {
  theme: 'snow'
});

ProseMirror initialization:

let view = new EditorView(document.querySelector("#editor"), {
  state: EditorState.create({
    schema: mySchema
  })
});

Both ProseMirror and Quill are powerful rich text editors for web applications. ProseMirror offers more flexibility and customization options, making it suitable for complex document editing needs. It uses a modular architecture that allows developers to build custom editing experiences.

Quill, on the other hand, provides a more straightforward setup and is easier to use for simpler editing requirements. It has better documentation and a larger community, which can be beneficial for developers who need quick solutions and support.

ProseMirror's performance is generally better for large documents, while Quill may struggle with extensive content. However, Quill's simplicity and out-of-the-box features make it a popular choice for many projects that don't require advanced customization.

22,569

A React framework for building text editors.

Pros of Draft.js

  • Simpler API and easier learning curve for React developers
  • Better integration with React ecosystem and components
  • More lightweight and focused on core text editing functionality

Cons of Draft.js

  • Less flexible for complex document structures
  • Limited built-in features compared to ProseMirror
  • Lack of active development and maintenance (archived repository)

Code Comparison

ProseMirror example:

import {EditorState} from "prosemirror-state"
import {EditorView} from "prosemirror-view"
import {Schema} from "prosemirror-model"

let state = EditorState.create({schema: new Schema({/* ... */})})
let view = new EditorView(document.body, {state})

Draft.js example:

import {Editor, EditorState} from 'draft-js';

const [editorState, setEditorState] = useState(EditorState.createEmpty());

<Editor editorState={editorState} onChange={setEditorState} />

Both ProseMirror and Draft.js are powerful rich text editing frameworks, but they cater to different needs. ProseMirror offers more flexibility and features for complex document structures, while Draft.js provides a simpler API that integrates well with React applications. ProseMirror is actively maintained and developed, whereas Draft.js is now archived by Facebook. The choice between the two depends on the specific requirements of your project and your familiarity with React.

29,602

A completely customizable framework for building rich text editors. (Currently in beta.)

Pros of Slate

  • More flexible and customizable architecture
  • Easier to implement complex, nested document structures
  • Better support for collaborative editing

Cons of Slate

  • Steeper learning curve due to its flexibility
  • Less mature ecosystem compared to ProseMirror
  • May require more boilerplate code for basic functionality

Code Comparison

ProseMirror example:

const view = new EditorView(document.body, {
  state: EditorState.create({
    doc: schema.node("doc", null, [
      schema.node("paragraph", null, [schema.text("Hello ProseMirror")])
    ]),
    plugins: [keymap(baseKeymap)]
  })
})

Slate example:

const editor = withReact(createEditor())
const [value, setValue] = useState([
  {
    type: 'paragraph',
    children: [{ text: 'Hello Slate' }],
  },
])

return <Slate editor={editor} value={value} onChange={setValue}>
  <Editable />
</Slate>

Both ProseMirror and Slate are powerful rich text editing frameworks, but they differ in their approach and architecture. ProseMirror offers a more opinionated structure, while Slate provides greater flexibility at the cost of increased complexity.

14,837

The world's #1 JavaScript library for rich text editing. Available for React, Vue and Angular

Pros of TinyMCE

  • More feature-rich out of the box, with a wide range of plugins and customization options
  • Easier to set up and use for non-technical users
  • Better browser compatibility, especially for older versions

Cons of TinyMCE

  • Larger file size and potentially slower performance
  • Less flexible for complex custom editing solutions
  • More challenging to extend or modify core functionality

Code Comparison

TinyMCE initialization:

tinymce.init({
  selector: '#myTextarea',
  plugins: 'link image table',
  toolbar: 'undo redo | formatselect | bold italic'
});

ProseMirror setup:

import {EditorState} from "prosemirror-state"
import {EditorView} from "prosemirror-view"
import {schema} from "prosemirror-schema-basic"

let state = EditorState.create({schema})
let view = new EditorView(document.body, {state})

TinyMCE provides a more straightforward setup with configuration options, while ProseMirror requires more manual setup but offers greater flexibility in defining the editor's behavior and structure.

Powerful rich text editor framework with a modular architecture, modern integrations, and features like collaborative editing.

Pros of CKEditor 5

  • More comprehensive out-of-the-box features and UI components
  • Extensive documentation and learning resources
  • Strong focus on accessibility and internationalization

Cons of CKEditor 5

  • Larger bundle size and potentially heavier performance impact
  • Less flexible for custom schema and document structure
  • Steeper learning curve for deep customizations

Code Comparison

CKEditor 5:

import ClassicEditor from '@ckeditor/ckeditor5-build-classic';

ClassicEditor
    .create(document.querySelector('#editor'))
    .then(editor => {
        console.log('Editor was initialized', editor);
    })
    .catch(error => {
        console.error(error);
    });

ProseMirror:

import {EditorState} from "prosemirror-state"
import {EditorView} from "prosemirror-view"
import {schema} from "prosemirror-schema-basic"

let state = EditorState.create({schema})
let view = new EditorView(document.querySelector("#editor"), {state})

Both CKEditor 5 and ProseMirror are powerful rich text editing solutions, but they cater to different needs. CKEditor 5 offers a more complete package with ready-to-use features, while ProseMirror provides a flexible foundation for building custom editors. The choice between them depends on the specific requirements of your project, such as the level of customization needed and the desired out-of-the-box functionality.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

prosemirror

[ WEBSITE | ISSUES | FORUM ]

ProseMirror is a well-behaved rich semantic content editor based on contentEditable, with support for collaborative editing and custom document schemas.

The ProseMirror library consists of a number of separate modules. This repository just serves as a central issue tracker, and holds a script to help easily check out all the core modules for development.

The project page has more information, a number of examples and the documentation.

This code is released under an MIT license. There's a forum for general discussion and support requests, and the Github bug tracker is the place to report issues.

STOP READING HERE IF YOU'RE SIMPLY USING PROSEMIRROR. YOU CAN INSTALL THE SEPARATE NPM MODULES FOR THAT. THE INSTRUCTIONS BELOW ONLY APPLY WHEN DEVELOPING PROSEMIRROR!

Setting up a dev environment

Clone this repository, and make sure you have node and yarn (due to a string of issues with NPM 5, NPM is not currently supported) installed. Next, from the cloned directory run:

bin/pm install

This will fetch the submodules, install their dependencies, and build them.

The bin/pm script in this repository provides functionality for working with the repositories:

  • bin/pm build rebuilds all the modules

  • bin/pm watch sets up a process that automatically rebuilds the modules when they change

  • bin/pm status prints the git status of all submodules

  • bin/pm commit <args> runs git commit with the given arguments in all submodules that have pending changes

  • bin/pm test runs the (non-browser) tests in all modules

  • bin/pm push runs git push in all modules

  • bin/pm grep <pattern> greps through the source code for the modules for the given pattern

  • bin/pm dev-start starts a server that rebuilds the packages whenever their sources change, and exposes the demo (demo/*) under a webserver on port 8080

(Functionality for managing releases will be added in the future.)

Community

Development of ProseMirror happens in the various repositories exposed under the ProseMirror organization on GitHub. Bugs for core packages are tracked in the bug tracker for the meta repository.

We aim to be an inclusive, welcoming community. To make that explicit, we have a code of conduct that applies to communication around the project.

NPM DownloadsLast 30 Days