scrumpy/prosemirror-to-html

Takes HTML and outputs ProseMirror compatible JSON.

0.7.1 2019-08-16 08:15 UTC

README

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>

Supported Nodes

  • Blockquote
  • BulletList
  • CodeBlock
  • HardBreak
  • Heading
  • ListItem
  • OrderedList
  • Paragraph
  • Table
  • TableRow
  • TableHeader
  • TableCell

Supported Marks

  • Bold
  • Code
  • Italic
  • Link

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

Pull Requests are welcome.

Credits

License

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