Json-to-bbcode is a library written in PHP for converting ProseMirror json to BBCode
Use the package manager composer to install json-to-bbcode.
composer require litlife/json-to-bbcode
In this example, you can see how to convert json to a string of bb code
use Litlife\JsonToBBCode\Renderer;
$jsonString = <<<EOT
{
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Example text using strong",
"marks": [
{
"type": "bold"
}
]
}
]
}
]
}
EOT;
$jsonArray = json_decode($jsonString, true);
$bbCodeString = (new Renderer())->render($jsonArray);
echo ($bbCodeString);
Output:
[b]Example text using strong[/b]
use Litlife\JsonToBBCode\Marks\Italic;
$bbCodeString = (new Renderer())->addMark(Italic::class)->render($jsonArray);
use Litlife\JsonToBBCode\Nodes\Blockquote;
$bbCodeString = (new Renderer())->addNode(Blockquote::class)->render($jsonArray);
composer test