# rich-text

> OT type for rich text

Latest version **4.1.0** (published 2020-04-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install rich-text
pnpm add rich-text
yarn add rich-text
bun add rich-text
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.1.0 |
| Published | 2020-04-03 |
| First published | 2014-09-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10 |
| Dependencies | 1 |
| Unpacked size | 15.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 320 |
| Author | Jason Chen |
| Maintainers | jhchen |
| Keywords | rich text, ot, operational transform, sharejs |

## Links

- npm: https://www.npmjs.com/package/rich-text
- Repository: https://github.com/ottypes/rich-text
- Issues: https://github.com/ottypes/rich-text/issues
- npm.io page: https://npm.io/package/rich-text

## Dependencies (1)

- [quill-delta](https://npm.io/package/quill-delta.md) ^4.2.1

## Alternatives

- [@sveltejs/kit](https://npm.io/package/@sveltejs/kit.md) — 2.2M weekly downloads
- [@atlaskit/theme](https://npm.io/package/@atlaskit/theme.md) — 402.0K weekly downloads
- [@tangle-network/brand](https://npm.io/package/@tangle-network/brand.md) — 10.0K weekly downloads
- [seneca](https://npm.io/package/seneca.md) — 7.4K weekly downloads
- [@bsb/base](https://npm.io/package/@bsb/base.md) — 7.2K weekly downloads

## Recent versions

- 4.1.0 (latest) — 2020-04-03
- 4.0.0 — 2019-06-03
- 3.1.0 — 2016-10-13
- 3.0.2 — 2016-08-01
- 3.0.1 — 2016-06-19
- 3.0.0 — 2016-04-11
- 2.1.1 — 2016-01-28
- 2.1.0 — 2015-08-07
- 2.0.0 — 2015-06-04
- 1.1.0 — 2015-03-14
- 1.0.3 — 2014-10-23
- 1.0.2 — 2014-10-20
- 1.0.1 — 2014-10-16
- 1.0.0 — 2014-10-08
- 0.1.0 — 2014-09-23

## README

# Rich Text OT Type [![Build Status](https://travis-ci.org/ottypes/rich-text.svg?branch=master)](https://travis-ci.org/ottypes/rich-text)

An OT Type for rich text documents.

For documentation on the spec this type implements, see [ottypes/docs](https://github.com/ottypes/docs). Rich Text does not implement the optional `invert`, but does implement `normalize`, tranformCursor, `serialize`, and `deserialize`. Please refer to [ottypes/docs](https://github.com/ottypes/docs) for documentation.

Rich Text uses [quill-delta](https://github.com/quilljs/delta) on the back end.


## Operations

Operations are an Array of changes, each operation describing a singular change to a document. They can be an [`insert`](#insert-operation), [`delete`](#delete-operation) or [`retain`](#retain-operation). Note operations do not take an index. They always describe the change at the current index. Use retains to "keep" or "skip" certain parts of the document.


### Insert Operation

Insert operations have an `insert` key defined. A String value represents inserting text. Any other type represents inserting an embed (however only one level of object comparison will be performed for equality).

In both cases of text and embeds, an optional `attributes` key can be defined with an Object to describe additonal formatting information. Formats can be changed by the [retain](#retain) operation.

```js
// Insert a bolded "Text"
{ insert: "Text", attributes: { bold: true } }

// Insert a link
{ insert: "Google", attributes: { href: 'https://www.google.com' } }

// Insert an embed
{
  insert: { image: 'https://octodex.github.com/images/labtocat.png' },
  attributes: { alt: "Lab Octocat" }
}

// Insert another embed
{
  insert: { video: 'https://www.youtube.com/watch?v=dMH0bHeiRNg' },
  attributes: {
    width: 420,
    height: 315
  }
}
```

### Delete Operation

Delete operations have a Number `delete` key defined representing the number of characters to delete. All embeds have a length of 1.

```js
// Delete the next 10 characters
{ delete: 10 }
```

### Retain Operation

Retain operations have a Number `retain` key defined representing the number of characters to keep (other libraries might use the name keep or skip). An optional `attributes` key can be defined with an Object to describe formatting changes to the character range. A value of `null` in the `attributes` Object represents removal of that key.

*Note: It is not necessary to retain the last characters of a document as this is implied.*

```js
// Keep the next 5 characters
{ retain: 5 }

// Keep and bold the next 5 characters
{ retain: 5, attributes: { bold: true } }

// Keep and unbold the next 5 characters
// More specifically, remove the bold key in the attributes Object
// in the next 5 characters
{ retain: 5, attributes: { bold: null } }
```


## Commentary

This library was originally implemented as part of a full fledged Google Docs like product called Stypi. Eventually, parts were open sourced--the editor became [Quill](https://github.com/quilljs/quill), the realtime engine became [tandem](https://github.com/tandem/tandem) and the document type became [tandem-core](https://github.com/tandem/tandem-core).

[ShareJS](https://github.com/josephg/ShareJS) was a more established open source realtime collaboration engine, so `tandem` and `tandem-core` were deprecated to unify support under one project. `tandem-core` was rewritten as `rich-text`, to adhere to ShareJS's [OT Type specification](https://github.com/ottypes/docs).

The needs of a realtime rich text document type was formerly a superset of a generalized rich text document type. As Quill has evolved, the reverse is becoming true. This `rich-text` library today provides the interface to use with ShareJS, but the underlying type and fuctionality is implemented in [`quill-delta`](https://github.com/quilljs/delta).

---
_Source: https://npm.io/package/rich-text · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
