Rich text format (Hako Rich Text v1)
You read and write rich editor field values as JSON in a format called Hako Rich Text v1. The format is the same as ProseMirror and Tiptap JSON (type attrs content marks text). You can pass it unchanged to Tiptap’s generateHTML and similar functions.
| Situation | Format |
|---|---|
| Reading with the Content API | This format by default (normal form). With richText=html, an HTML string |
| Writing with the Content API and Admin API | JSON in this format, or an HTML string |
Example
Section titled “Example”{ "type": "doc", "content": [ { "type": "heading", "attrs": { "level": 2 }, "content": [{ "type": "text", "text": "はじめに" }] }, { "type": "paragraph", "content": [ { "type": "text", "text": "これは" }, { "type": "text", "text": "太字", "marks": [{ "type": "bold" }] }, { "type": "text", "text": "と" }, { "type": "text", "text": "リンク", "marks": [ { "type": "link", "attrs": { "href": "https://example.com" } } ] }, { "type": "text", "text": "です。" } ] } ]}An empty document is { "type": "doc" }.
Where nodes can go
Section titled “Where nodes can go”| Location | What can go there |
|---|---|
Directly under the document (doc) |
Blocks (0 or more) |
| Blocks | paragraph heading bulletList orderedList blockquote codeBlock horizontalRule image table embed |
Inside paragraph heading |
Inline (text hardBreak. 0 or more) |
Inside bulletList orderedList |
listItem (1 or more) |
Inside listItem blockquote |
Blocks (1 or more) |
Inside codeBlock |
text without marks (0 or more) |
Inside table |
tableRow (1 or more) |
Inside tableRow |
tableCell or tableHeader (1 or more) |
Inside tableCell tableHeader |
Blocks (1 or more) |
Node attributes
Section titled “Node attributes”Attributes with default values are omitted in normal form. When omitted, they are treated as the default value.
| Node | Attribute | Type | Required | Default | Description |
|---|---|---|---|---|---|
paragraph |
textAlign |
"left" "center" "right" "justify" |
None | Text alignment | |
heading |
level |
Integer from 1 to 6 | ○ | Heading level. Always present, even in normal form | |
textAlign |
Same as paragraph |
None | Text alignment | ||
orderedList |
start |
Integer | 1 |
Starting number | |
codeBlock |
language |
String | None | Language. In HTML, becomes <code class="language-xxx"> |
|
image |
src |
Non-empty string | ○ | Image URL | |
alt title |
String | None | Alternative text, title | ||
width height |
Positive integer | None | Width, height (px) | ||
embed |
src |
Non-empty string | ○ | URL to embed. In HTML, only https URLs become an iframe |
|
tableCell tableHeader |
colspan rowspan |
Integer of 1 or more | 1 |
Cell merging | |
colwidth |
Array of positive integers | None | Column width (px). For merged cells, lists the width of each column | ||
text |
text |
Non-empty string | ○ | Body text. A key of the node, not inside attrs |
|
marks |
Array of marks | None | See “Marks” below |
hardBreak (line break), horizontalRule (horizontal rule), bulletList, listItem, blockquote, table, and tableRow have no attributes.
| Mark | Attributes | Description |
|---|---|---|
link |
href (required. Non-empty string), target (default "_blank"), rel (default "noopener noreferrer nofollow"), class |
Link. In HTML, an href with a dangerous scheme such as javascript: becomes empty |
bold |
Bold | |
code |
Inline code | |
italic |
Italic | |
strike |
Strikethrough | |
underline |
Underline | |
customClass |
class (required. Non-empty string) |
Adds a class to the selected text (<span class="...">) |
The order in the table (link → bold → code → italic → strike → underline → customClass) is the nesting order in HTML (from the outside), and the order of marks in normal form.
Normal form
Section titled “Normal form”Values you write are normalized by the following rules before they are saved. Values returned by the Content API are also in this form. The same content always produces the same JSON.
| Rule | Example |
|---|---|
Omit attributes with default values, null attributes, and omittable attributes with empty strings |
{"start": 1} → omitted, {"textAlign": null} → omitted |
When no attributes remain, omit attrs entirely |
{"type": "paragraph", "attrs": {}} → {"type": "paragraph"} |
| Sort marks in the order of the table above, and keep only the first mark of each kind | [italic, bold] → [bold, italic] |
| Merge adjacent text with the same marks into one | "太" and "字" (both bold) → "太字" |
| Omit empty text | {"type": "text", "text": ""} → omitted |
Omit empty content and empty marks |
{"type": "paragraph", "content": []} → {"type": "paragraph"} |
| Discard unknown attributes and unknown keys of nodes and marks | foo in the attrs of image → discarded |
Order keys as type → attrs → content (for text, type → text → marks) |
Unknown attributes are discarded, not treated as errors. Unknown nodes and marks are errors (see “Write errors” below).
Writing HTML
Section titled “Writing HTML”When you send an HTML string, it is converted to Hako Rich Text v1 JSON and saved. For elements the editor cannot handle, only their content remains. <script> and similar elements are discarded. HTML never causes an error.
Write errors
Section titled “Write errors”When you send JSON that does not follow the rules, 400 is returned. issues lists the location within the field (path) and the reason (message). Errors are returned all together, not stopping at the first one.
The Content API returns the following.
{ "error": { "code": "bad_request", "message": "body.content[0].attrs.level: must be an integer from 1 to 6", "details": { "issues": [ { "path": "body.content[0].attrs.level", "message": "must be an integer from 1 to 6" } ] } }}In the Admin API, message and issues are at the top level of the body. Inside custom fields and repeaters, path traces the location like blocks[0].caption.content[0].
Reason (message) |
When it occurs |
|---|---|
must be a document ({"type": "doc", ...}) |
The value is not an object with type: "doc" (path is only the field ID) |
must be a node with a "type" |
A node has no type |
unknown node type "mystery" |
Unknown node |
"paragraph" is not allowed here (expected inline content (text, hardBreak)) |
It is in a place where it is not allowed |
"text" is not allowed here (expected block content) |
Text was placed directly under the document |
bulletList must contain at least 1 listItem |
Not enough content (in a “1 or more” location) |
must be an array |
content or marks is not an array |
text must be a string |
text is not a string |
must be an integer from 1 to 6 |
The heading level is not 1 to 6 |
must be one of left, center, right, justify |
The text alignment value is wrong |
is required (a non-empty string) |
A required attribute (src href class) is missing or empty |
must be a string / must be an integer / must be a positive integer |
The attribute type is wrong |
unknown mark type "glitter" |
Unknown mark |
must be a mark with a "type" |
A mark has no type |
Versioning rules
Section titled “Versioning rules”- Within v1, nodes, marks, and omittable attributes may be added. When omitted, anything added has the same meaning as before
- Within v1, the names and meanings of existing nodes, marks, and attributes, their default values, where they can go, and the normal form rules do not change
- Changes incompatible with the current format are added as a new format, and v1 can still be returned for a while. They are announced in the Changelog
When you render on your site, render only the content (content) of unknown nodes and ignore unknown marks and attributes. Then, even if something is added within v1, the display does not break.