Together-Pad · Document formats

Rich text: de.wappensc.together.format.richtext/1

Profile id
de.wappensc.together.format.richtext/1
Kind
A document profile of TDSP 2.0, the Together Document Sync Protocol
Status
Final, 15 November 2026. From now on this definition changes only compatibly; an incompatible change would be a new profile id with a new major version.
Address
https://wappensc.github.io/together-formats/richtext-1/, since 16 November 2026 (section 12)
Test vectors
vectors.json
Repository
github.com/wappensc/together-formats, with this text and its vectors for every version
Terms
Anyone may implement this profile, without asking and without fee. Text and test vectors are under the MIT licence.
Maintained by
WappenSC, the maker of Together-Pad

Diese Seite beschreibt das Format für formatierten Text, in dem Together-Pad Dokumente hält und über einen Messenger abgleicht. Sie richtet sich an Entwicklerinnen und Entwickler, die es in einem eigenen Programm lesen und schreiben wollen, und ist deshalb auf Englisch. Jede und jeder darf das Format umsetzen, ohne zu fragen und ohne Gebühr.

1. Overview

In TDSP, a document's content travels as updates of a CRDT, and the document's profile says what those bytes mean: which CRDT, which structure, and how the content is projected to plain text for author attribution (TDSP §5). This profile holds formatted text as a notes app knows it: paragraphs with styles (headings, code, quotes, indentation), lists and checklists, character formats, links, line breaks within a paragraph, images, and further embeds that later versions may add.

It is built on Yjs. The whole content is one flat text, a Y.Text named content, in which every paragraph ends with an embedded map, the paragraph end, that holds the paragraph's attributes. Splitting or joining paragraphs inserts or deletes a paragraph end and moves no text, so formats, positions that point into the text, and what others type at the same moment all stay where they are.

MUST, MUST NOT, SHOULD and MAY are used as in RFC 2119 and RFC 8174 when written in capitals. Y.Doc is a Yjs document, and Y.Text, Y.Map and Y.Array are its shared types, named as the JavaScript library of Yjs names them. An implementation need not use that library: it interoperates if it reads and writes the encodings below and merges as Yjs does.

2. What TDSP asks of a profile

TDSP's requirement PRF-1 lists what every profile defines; PRF-7 asks a profile defined outside TDSP to define each item publicly, with test vectors. Items 1 to 4 and 7 to 9 are the same as for TDSP's own profile yjs-paragraphs/1 (TDSP, Appendix A); they are restated here.

PRF-1 itemIn this profile
1. Update A Yjs update in encoding version 1, as Y.encodeStateAsUpdate writes and Y.applyUpdate reads it (not the …V2 functions). A full state and an incremental change are the same format. Updates applied in any order, with duplicates, yield the same state; an update whose predecessors are missing is held, not rejected.
2. Missing predecessors Yjs holds such an update as pending (store.pendingStructs, store.pendingDs); the Yjs client ids it carries name whose updates they are. What they take is the byte length of the pending structs' update plus that of the pending delete set; giving them up clears both, as if those updates had never arrived, so that an update that brings them again applies as any other.
3. State vector A Yjs state vector as Y.encodeStateVector writes it. An empty document's is the single byte 00 (Base64 AA==).
4. What a state vector lacks The structs the replica applied from each client's clock in the state vector on, and the delete set of its applied items, as Y.encodeStateAsUpdate(doc, stateVector) writes them; nothing it holds for missing predecessors (item 2), which that function adds while Yjs holds any. With the empty state vector, byte for byte the full state. The update that holds nothing, the full state of an empty Y.Doc, is the two bytes 00 00 (Base64 AAA=).
5. Initial state One paragraph end without other keys, the only unit of content: one empty paragraph (section 3). The creator seeds it in one change.
6. Plain-text projection Each unit of content as one character, the document's last paragraph end as none (section 6). Offsets count UTF-16 code units.
7. Splitting into pieces; indivisible units Each piece a Yjs update in encoding version 1 holding one contiguous run of one client's structs, or a part of the delete set. A run is cut between structs and, where a struct alone is too large, inside it: the prefix written as a shortened copy, the suffix as Yjs writes any partial struct; text is never cut inside a UTF-16 surrogate pair. Indivisible is content of length one: an embedded map, a value in a map or an array (such as an image's preview or one part of its original), a format, a shared type. Its encoded struct must fit a piece: (maxBytes − the other fields of an edit frame) × 3/4 bytes, about 3.1 MB at 4 MiB. Writers keep binaries far below that (section 9). Text is never such a unit.
8. What a replica deleted The update of no structs and the delete set of the items the replica applied, nothing it holds for missing predecessors (item 2), as Y.encodeStateAsUpdate(doc, Y.encodeStateVector(doc)) writes it in encoding version 1 while Yjs holds nothing pending: 00 for no structs, the number of clients, and for each client in descending order of its id: the id, the number of its ranges, and each range's clock and length, ascending and merged; every number a variable-length unsigned integer. A document that deleted nothing gives 00 00. Of the items a given state vector counts: the same, with each client's ranges cut at that client's clock in the state vector, and a client left without ranges left out.
9. Reading without applying An update is read as Y.decodeUpdate reads it, every struct and the whole delete set, and ends where its delete set ends; a state vector is read as Y.decodeStateVector reads it and ends after its last entry. Bytes with anything after that are neither.
Layers Admitted: top-level shared types beside content, each named by a layer id (section 10).

3. Structure

A receiver MUST NOT reject an update because what it holds breaks this structure, and MUST apply it like any other: a CRDT cannot refuse part of the state everyone else converges to. The projection (section 6) is defined for any content, and a reader shows what breaks the structure as follows. Text after the last paragraph end is a paragraph of its own, without an end, in body text. An embedded value that is no Y.Map, or a Y.Map without a string type, is a placeholder, with the map's fallback where it has one. A top-level type beside content that no layer id names is not in the projection, and a change of it counts as a change of the content (TDSP LAY-6). A reader always reads content as a Y.Text.

Example: a heading, a paragraph of two lines, and an empty last paragraph, as a Yjs delta:

[ { insert: "Shopping" },
  { insert: Y.Map { type: "paragraph", block: "h1" } },
  { insert: "Milk\nBread" },
  { insert: Y.Map { type: "paragraph" } },
  { insert: Y.Map { type: "paragraph" } } ]

4. Attributes

4.1 Paragraph attributes: keys of the paragraph end

KeyValuesMeaning
block absent Body text
"h1" to "h6" A heading of level 1 to 6
"code" A line of monospaced text; consecutive ones form a code block
"bullet", "dash", "ordered", "check" A list item: with a bullet, with a dash, numbered, or a checklist item with a checkbox
indent an integer from 1 to 8; absent is 0 The indentation level of a list item or of body text
checked true; absent is not A checklist item is done
start an integer from 0 to 999 999 999 The number of an ordered list's first item, set on that item
quote true The paragraph is quoted, whatever its block
table, row, col reserved for tables A paragraph end with table ends a table cell. Version 1 defines only how cells project (section 6); until tables are defined further, a reader shows each cell as a paragraph and a writer does not write these keys.

One key block holds every style rather than a key per style: when two people set different styles on one paragraph at the same moment, one value wins, as for any key of a Y.Map, and no reader needs a rule for which style counts.

4.2 Character formats: Yjs text attributes

AttributeValueMeaning
bold, italic, underline, strike true Bold, italic, underlined, struck through
code true Inline code, in a monospaced font
link the address, a string that is not empty A link

An absent attribute, or one set to null (as Yjs removes a format), means unformatted. Formats apply to characters and embeds alike. A format on a paragraph end means nothing, and a reader ignores it: it arises when someone formats a range while someone else inserts a paragraph end in it.

Links. A reader MUST NOT load anything for a link, SHOULD open one only when the person asks for it (by a click, say), and SHOULD open only these addresses: the value without the spaces at its ends, with no control character (U+0000 to U+001F, U+007F to U+009F), whose scheme (the letters, digits, +, . and - before the first colon, beginning with a letter, in any case) is https or http and continues after the colon with // and a character that is no /, ?, # or white space, or is mailto and continues with something other than white space. It shows any other link as text, and keeps its value.

5. Embeds

An embed is a unit of a paragraph, like a character: an image alone on a line is a paragraph that holds one embed. Every embed is a Y.Map with at least:

KeyValue
typeA string other than "paragraph": what kind of embed it is
fallbackA string: what a reader that does not know the type shows in its place

Version 1 defines one type, "image". A reader that does not know an embed's type shows its fallback as a placeholder and keeps the embed unchanged.

5.1 The image type

KeyValue
type"image"
fallback Shown by a reader that cannot show the image; writers use its file name in square brackets, such as "[photo.jpg]"
mime"image/jpeg" or "image/png": the format of the original
nameThe file name, or ""
width, heightThe original's size in pixels, integers greater than 0
sizeThe original's length in bytes, an integer greater than 0
sha256The SHA-256 of the original, 64 lowercase hexadecimal digits
preview Binary (a Yjs Uint8Array): a JPEG of the image, its longest edge at most 640 pixels, at most 64 000 bytes
parts A Y.Array of binaries that, joined in order, are the original

Reading. A reader shows the preview until the original is complete — the lengths of the parts add up to size, and the SHA-256 of the parts joined is sha256 — and the original from then on. An image embed that lacks one of these keys, or holds a value of another kind or a mime not listed, is shown by its fallback and kept, like an embed of unknown type: a further image format would come as a new value of mime, which older readers show by the fallback. Keys beyond these are kept and ignored.

Writing. A writer inserts the embed with its metadata, its preview and an empty parts first, and then appends the parts, each in a change of its own: everyone sees the preview soon, and no single change is larger than a part. A writer SHOULD encode an image anew before it inserts it, without metadata such as the place where a photo was taken.

6. Plain-text projection

TDSP attributes text to its authors by offsets into a plain-text projection, which every implementation must compute to the same character (TDSP §5.4). The projection of this profile is the units of content in order, each as:

Offsets count UTF-16 code units. Two values of table or row are equal when they are the same string, the same number (0 equals −0; NaN equals nothing), the same big integer, the same boolean, or both null; maps, arrays, binaries and other JSON objects never equal another value. A key whose value is Yjs's undefined counts as absent, and two absent values of row are equal. Formats, paragraph attributes, list markers, checkboxes and list numbers add nothing; layers and other top-level types are never part of the projection (TDSP LAY-3).

So every position of the projection is the same position in content, and the projection is one character shorter than content whenever the document ends, as it should, with a paragraph end. The last paragraph end projects nothing so that the initial state projects the empty text, as one empty paragraph does in yjs-paragraphs/1, and so that every character of the projection comes from a change someone made and can be attributed.

Example: "Title", an end with block: "h1", "A" and "B" each ending a cell of row "r1" of table "t1", "Photo: ", an image, the last end — 19 units — project to the 18 characters "Title\nA\tB\nPhoto: ".

7. What a reader shows

So that every implementation shows the same document, a reader normalizes each paragraph:

List numbers. Going through the paragraphs in order, a reader keeps, for each indent, the next number of the ordered list open at that indent:

So consecutive ordered items of one indent form a list, deeper items nest without ending it, and a quote does not end a list.

8. What a reader does not know

Version 1 can grow without a new profile id: later versions of this definition may add paragraph keys, values, formats and embed types, compatibly. Therefore:

9. Writing, and its limits

10. Layers

This profile admits layers (TDSP §5.6): data beside the content, each a top-level shared type named by its layer id, such as comments. A layer is never part of the projection and never changes attribution. A layer that points into the content SHOULD do so by Yjs relative positions into content; since splitting and joining paragraphs moves no text, such positions keep their place.

11. Test vectors

vectors.json holds the test vectors PRF-7 asks for. For each vector:

An implementation passes a vector when its updates, applied to an empty document in any order and with duplicates, give that content, projection, state vector, deletions and reader view.

VectorShows
initial-stateThe initial state; it projects the empty text
paragraphsParagraph ends; the last one projects nothing
line-breakA line break within a paragraph
paragraph-stylesHeadings, code, quote, indented body text; a change of attributes alone
listsChecklists, bullets, dashes, numbered lists with start and nesting; list numbers
formatsEvery format, links that open and one that does not
embedAn embed of unknown type, its fallback and U+FFFC
imageAn image with metadata, preview and its original in two parts; shown as the original
image-parts-missingThe same image before its parts arrive; shown as the preview
unknown-and-out-of-rangeUnknown keys, values, formats and image formats kept; values out of range; a format on a paragraph end
table-cellsCell ends projected as tab or line feed
concurrentThree writers; concurrent insertions and styles converge
deletionsDeleted text, and two paragraphs joined; the canonical encoding of deletions
utf-16Offsets in UTF-16 code units
beside-contentA layer, and a top-level type that breaks the structure; neither projected
after-the-last-endText after the last paragraph end, which breaks the structure

12. Versions

Version 1: draft of 22 October 2026, final on 15 November 2026.

The address of this definition changed on 16 November 2026, to https://wappensc.github.io/together-formats/richtext-1/. The format and its test vectors are unchanged; only the address that vectors.json names under definition is new.