# Peritext: A CRDT for Rich-Text Collaboration

## Metadata
- Author: [[Martin Kleppmann]]
- Full Title: Peritext: A CRDT for Rich-Text Collaboration
- Category: #articles
- URL: https://www.inkandswitch.com/peritext/
## Highlights
We could store each contiguous span of formatted text as an object containing the string text contents and a list of format markers ([View Highlight](https://read.readwise.io/read/01gvqz1swj9wegmctxvft23ar6))
Unfortunately, when we use the Automerge semantics for merging JSON documents, this representation does a poor job at preserving user intent. ([View Highlight](https://read.readwise.io/read/01gvqz2014b81wg92brw2yj82n))
Our goal is to produce a data structure that contains only the current text of the document (no deleted text), annotated with its current formatting. This is in line with how rich-text editing user interface components, such as [ProseMirror](https://prosemirror.net/), represent their document state. ([View Highlight](https://read.readwise.io/read/01gvqz43zwcg1k3e00phyqv88e))
To produce this data structure, we can iterate over the list of characters, converting each set of mark operations into a current formatting state for the corresponding span. ([View Highlight](https://read.readwise.io/read/01gvqz4a2565m1p16wt69de59j))
## New highlights added April 11, 2023 at 2:49 PM
For the editor UI, we chose to build on [ProseMirror](https://prosemirror.net/), a popular library which is already used in many collaborative editing contexts. Its modular design gave us the necessary flexibility to intervene in the editor’s dataflow at appropriate points. ([View Highlight](https://read.readwise.io/read/01gxrt359d5v44ngp8r25fqnhk))