cjprinse / prosemirror-to-html
Takes HTML and outputs ProseMirror compatible JSON.
Fund package maintenance!
ueberdosis/
Requires
- php: ^7.1.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.15
- league/climate: ^3.5
- phpunit/phpunit: ^7.0|^8.0|^9.0
This package is not auto-updated.
Last update: 2024-11-16 10:36:49 UTC
README
We need your support to maintain this package. 💖 https://github.com/sponsors/ueberdosis
ProseMirror to HTML
Takes ProseMirror JSON and outputs HTML.
Installation
composer require ueberdosis/prosemirror-to-html
Usage
(new \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
- Image
- ListItem
- OrderedList
- Paragraph
- Table
- TableRow
- TableHeader
- TableCell
Supported Marks
- Bold
- Code
- Italic
- Link
- Strike
- Subscript
- Superscript
- Underline
Custom Nodes
Define your custom nodes as PHP classes:
<?php class CustomNode extends \ProseMirrorToHtml\Nodes\Node { protected $markType = 'custom'; protected $tagName = 'marquee'; }
And register them:
$renderer->addNode(CustomNode::class);
Or overwrite the enabled nodes:
$renderer->withNodes([ CustomNode::class, ]);
Or overwrite the enabled marks:
$renderer->withMarks([ Bold::class, ]);
Or replace just one mark or node:
$renderer->replaceNode( CodeBlock::class, CustomCodeBlock::class ); $renderer->replaceMark( Bold::class, CustomBold::class );
Contributing
Pull Requests are welcome.
Credits
Related packages
- prosemirror-to-html-js by @enVolt
License
The MIT License (MIT). Please see License File for more information.