EditorJS Backend is a library for parsing, validating, and sanitizing JSON data generated by the Editor.js rich text editor. It provides a robust and extensible way to handle Editor.js blocks in PHP applications.
composer require devscast/editorjs
Parsing and Sanitizing Editor.js Data The Editor class is the main entry point for processing Editor.js JSON data. It parses the JSON into blocks, validates the structure, and sanitizes the resulting HTML output.
<?php
use Devscast\EditorJs\Editor;
$data = <<<JSON
{
"time": 1635603431943,
"blocks": [
{
"id": "1",
"type": "header",
"data": {
"text": "Hello, Editor.js!",
"level": 2
}
},
{
"id": "2",
"type": "paragraph",
"data": {
"text": "This is a paragraph block."
}
}
],
"version": "2.31.0"
}
JSON;
$editor = new Editor($data);
// Get sanitized HTML output
echo $editor->getHtml();