Redactor can receive content as a JSON object. You are not limited and can get HTML output at any time, even if the data was set as JSON. The same is true for data set to HTML. You can always get them as JSON using the API.
Moreover, each block can be retrieved as a separate JSON object using the API.
JSON data is set using the editor's 'data' setting, which must be specified when running Redactor.
let app = Redactor('#entry', {
data: {
"version": "1.0.0",
"time" : 1650860257872,
"blocks": [
{
"type": "heading",
"content": "...",
"level": 1
},
{
"type": "text",
"content": "..."
},
{
"type": "image",
"src": "/path-to-image.jpg",
"alt": "Alt text",
"caption": "..."
},
{
"type": "heading",
"content": "...",
"level": 2
},
{
"type": "text",
"content": "..."
}
]
}
});
Version and time parameters are optional. Blocks is a mandatory parameter. See below for all parameters of each block.
You can get content from the editor as a JSON object.
To do this, use getJson
method.
// call editor
let app = Redactor('#entry');
// get content from outside scripts
let data = app.editor.getJson();
// get content in the plugin method
let data = this.app.editor.getJson();
String
String
Object
String
String
Object
String
Number
Boolean
The examples provide both mandatory and optional parameters. Required parameters are marked * (asterix).
String
{
"type": "address",
"classname": "address-block",
"content": "Address text"
}
Array
{
"type": "dlist",
"items": [
{
"term": "Term 1",
"desc": "Desc 1"
},
{
"term": "Term 2",
"desc": "Desc 2"
}
]
}
String
Boolean
String
{
"type": "embed",
"responsive": true,
"caption": "My video",
"content": "<iframe...>"
}
{
"type": "line"
}
Number
String
{
"type": "heading",
"content": "Title of text",
"level": 1
}
String
{
"type": "text",
"content": "Text"
}
Boolean
Array
{
"type": "list",
"items": [
"Item 1",
"Item 2"
]
}
// numbered list
{
"type": "list",
"numbered": true,
"items": [
"Item 1",
"Item 2"
]
}
Array
String
Boolean
{
"type": "todo",
"items": [
{
"content": "Todo item 1",
"checked": true
},
{
"content": "Todo item 2",
"checked": false
}
]
}
String
String
{
"type": "pre",
"caption": "My code",
"content": "function() {n echo 2;n}"
}
String
Object
{
"type": "wrapper",
"wrap": "div",
"children": [
{
"type": "wrapper",
"wrap": "div",
"style": { "border": "1px dashed #ccc" },
"classname": "mydiv",
"children": [
{
"type": "text",
"content": "This is a paragraph1 <b>inside</b> div."
},
{
"type": "text",
"content": "This is a paragraph2 <b>inside</b> div."
}
]
},
{
"type": "text",
"content": "This is a paragraph3 <b>inside</b> div."
}
]
}
Object
String
Object
{
"type": "layout",
"children": [
{
"type": "column",
"width": "40%",
"children": [
{
"type": "heading",
"level": 3,
"content": "Column 1"
},
{
"type": "text",
"content": "This is a paragraph"
}
]
},
{
"type": "column",
"width": "60%",
"children": [
{
"type": "heading",
"level": 3,
"content": "Column 2"
},
{
"type": "text",
"content": "This is a paragraph"
}
]
}
]
}
String
String
{
"type": "quote",
"placeholder": "Type here...",
"content": "This is a quote item.",
"caption": "I am the author!"
}
String
String
String
String
String
String
String
Boolean
Object
{
"type": "image",
"width": "200px",
"height": "100px",
"caption": "My image caption",
"src": "/photo.jpg",
"srcset": "photo.jpg 2x",
"url": "https://example.com",
"alt": "Hello world",
"img": {
"style": {
"width": "200px",
"height": "100px"
}
},
"attrs": {
"image": 2
}
}
Boolean
Boolean
Array
{
"type": "table",
"head": true,
"foot": true,
"items": [
["Head 1", "Head 2"],
["Cell 1", "Cell 2"],
["Cell 3", "Cell 4"],
["Foot 1", "Foot 2"]
]
}
String
{
"type": "noneditable",
"content": '...html...'
}