The JSON Rich Text Editor (RTE) organizes its data into blocks and spans, ensuring a clean and structured JSON output. Each paragraph is represented as a block, each block contains an array, and each array includes multiple spans of text objects representing different nodes of text. This structure simplifies data processing on the backend.
The JSON RTE is built on a schema that defines the properties of each block. Below is the schema definition and an example:
{
"uid": { "type": "String", "required": true },
"type": { "type": "String", "required": true },
"attrs": { "type": "Object" },
"children": { "type": "Array[id(Block), Text]" }
}{
"type": "h1",
"uid": "3ddd280397cf44bcb8f",
"attrs": {},
"children": [
{
"text": "Hello World!",
"bold": true
},
{
"uid": "blta5aa9ca151e65333"
},
{
"text": "Welcome",
"bold": true
}
]
}The following code depicts the structure of the JSON Rich Text Editor:
{
"type": "doc",
"children": [
{
"type": "p",
"children": [
{
"text": "Paragraph"
}
]
},
{
"type": "h1",
"children": [
{
"text": "Heading One"
}
]
}
]
}Here, bold is a mark indicating that the text "I am Bold" should be styled as bold.
{
"text": "I am Bold",
"bold": true
}{
"text": "I am copy-pasted from Word/Google Docs",
"attrs": {
"style": {}
}
}Block nodes can be rendered in three ways:
Note: Use the type key for block nodes and the text key for text nodes, rather than relying on the attrs key.
Additional Resources: