Joostb / prosemirror-to-html

Takes ProseMirror JSON and renders HTML.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HTML to ProseMirror

Takes ProseMirror JSON and outputs HTML.

Installation

composer require scrumpy/prosemirror-to-html

Usage

(new \Scrumpy\ProseMirrorToHtml\Renderer)->render([
    'type' => 'doc',
    'content' => [
        [
            'type' => 'paragraph',
            'content' => [
                [
                    'type' => 'text',
                    'text' => 'Example Paragraph',
                ],
            ],
        ],
    ],
])

Output

<p>Example Text</p>

Custom Nodes

Define your custom nodes as PHP classes:

<?php

class CustomNode extends \Scrumpy\ProseMirrorToHtml\Nodes\Node
{
    public function matching()
    {
        return $this->node->type === 'custom';
    }

    public function tag()
    {
        return 'marquee';
    }
}

And register them:

$renderer->addNode(CustomNode::class);

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

Takes ProseMirror JSON and renders HTML.

License:MIT License


Languages

Language:PHP 100.0%