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 item | In 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 document MUST keep all its content in one
Y.Textnamedcontent. A unit ofcontentis one UTF-16 code unit of its text, or one embedded value; Yjs counts an embed as length one. -
A paragraph end is an embedded
Y.Mapwhose keytypeholds the string"paragraph". Its other keys are the attributes of its paragraph (section 4.1). A paragraph is the units after the previous paragraph end, or from the start, up to its own end. - A document MUST end with a paragraph end, and a writer inserts text before it, never after it.
- A line break within a paragraph is the character U+000A (line feed) in the text.
-
Every other embedded value is an embed (section 5): a
Y.Mapwith a stringtypeother than"paragraph"and a stringfallback. - Characters and embeds carry their formats as Yjs text attributes (section 4.2).
-
Beside
content, a document MUST NOT hold a top-level shared type except a layer, named by its layer id.
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
| Key | Values | Meaning |
|---|---|---|
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
| Attribute | Value | Meaning |
|---|---|---|
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:
| Key | Value |
|---|---|
type | A string other than "paragraph": what kind of embed it is |
fallback | A 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
| Key | Value |
|---|---|
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 |
name | The file name, or "" |
width, height | The original's size in pixels, integers greater than 0 |
size | The original's length in bytes, an integer greater than 0 |
sha256 | The 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:
- a character: itself, a line break included;
-
a paragraph end: a line feed U+000A; a tab U+0009 instead when it ends a table cell (it has a key
table) and the next paragraph end after it ends a cell of the same table and row (equal values oftableand ofrow); and nothing at all when it is the last unit ofcontent; - any other embedded value: one U+FFFC (object replacement character).
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:
-
blockcounts only with a value of section 4.1; any other value shows body text. -
indentcounts only on list items and body text, and only as an integer from 1 to 8; otherwise the paragraph is not indented. checkedcounts only on a"check"item, and only astrue.quotecounts only astrue.-
startcounts only on an"ordered"item, as an integer from 0 to 999 999 999, and only where that item begins a list. - A value that does not count is ignored for showing and stays in the document.
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:
- a paragraph that is no list item closes every list;
- a list item at indent n closes the lists at indents deeper than n;
- a list item at indent n that is not
"ordered"also closes the list at n, and shows no number; -
an
"ordered"item at indent n shows the next number of the list open at n; if none is open, it begins one with its ownstartwhere that counts, else 1; the list's next number is then one more.
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:
-
A reader MUST keep what it does not know and pass it on unchanged: unknown keys and values of a
paragraph end, unknown formats and unknown values of known formats, embeds of an unknown type, and
image embeds it cannot read. It shows an unknown paragraph style as body text, an unknown format as
none, and an unknown embed by its
fallback. -
A writer MUST write only what the person changed: the same characters with other formats by
Y.Text.formatwith the changed attributes only, a paragraph's attributes by setting or deleting the changed keys of its end only. It MUST NOT rewrite a paragraph end, an embed or a run of text that the person did not change. - A writer MUST NOT delete an embed of a type it does not know, except as part of a selection the person deletes, and SHOULD tell the person before that that the selection holds something it cannot show.
-
Only this definition adds paragraph keys, values, formats and embed types; a writer writes only
those it defines. The name
example— as an embed type, a paragraph key or value, a format — and the image formatimage/examplewill never be defined: the test vectors use them for what a reader does not know.
9. Writing, and its limits
-
A writer gives every insertion its formats explicitly, an empty set included: Yjs's
Y.Text.insertwithout attributes takes over the formats of the character before it. -
A new paragraph is a new paragraph end, a
Y.Mapof its own. Splitting a paragraph inserts one; joining two deletes the end between them, and the joined paragraph keeps the attributes of the end that remains. - Limits, checked by a writer when it writes: an image's original at most 1 000 000 bytes, its preview at most 64 000 bytes, each part at most 1 000 000 bytes; a document at most 10 000 000 bytes, counted as the length of its full state as one update (PRF-1 item 4, with the empty state vector) as a replica that loaded it afresh encodes it, that is without deleted content that only an undo history still holds. The document's limit is checked when an image goes in: a writer does not insert an image that would take the document over it.
- A reader accepts every document and every image, whatever its size, so that a later version can raise the 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:
updates: Yjs updates in encoding version 1, Base64, in the order they were made;-
content: the delta of theY.Textcontentafter applying them, a run of characters as a string and an embedded value as oneinsert, with the run's formats asattributes. In values, aY.Mapis{"map": {…}}with its keys sorted, aY.Array{"array": […]}, binary data{"binary": "<Base64>"}, and any other JSON value Yjs stores{"json": …}; beside: the names of the top-level shared types other thancontent;-
projectionandprojectionLength, its length in UTF-16 code units; -
stateVectoranddeleted(PRF-1 items 3 and 8), Base64, byte for byte;state, the result as one update as Yjs encodes it — another encoder may group items differently, but applied to an empty document its update must give the same content; -
paragraphs: what a reader shows of each paragraph (section 7): its text with each embed as U+FFFC,block(nullfor body text),indent,checked,quote, andnumberfor an ordered item; -
images, where there are any: for each embed of type"image", its unit incontentand what a reader shows:"original","preview"or"fallback".
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.
| Vector | Shows |
|---|---|
initial-state | The initial state; it projects the empty text |
paragraphs | Paragraph ends; the last one projects nothing |
line-break | A line break within a paragraph |
paragraph-styles | Headings, code, quote, indented body text; a change of attributes alone |
lists | Checklists, bullets, dashes, numbered lists with start and nesting; list numbers |
formats | Every format, links that open and one that does not |
embed | An embed of unknown type, its fallback and U+FFFC |
image | An image with metadata, preview and its original in two parts; shown as the original |
image-parts-missing | The same image before its parts arrive; shown as the preview |
unknown-and-out-of-range | Unknown keys, values, formats and image formats kept; values out of range; a format on a paragraph end |
table-cells | Cell ends projected as tab or line feed |
concurrent | Three writers; concurrent insertions and styles converge |
deletions | Deleted text, and two paragraphs joined; the canonical encoding of deletions |
utf-16 | Offsets in UTF-16 code units |
beside-content | A layer, and a top-level type that breaks the structure; neither projected |
after-the-last-end | Text 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.