prosemirror-to-html
prosemirror-to-html copied to clipboard
Takes ProseMirror JSON and renders HTML.
🚨 We’ve done a rewrite that you probably want to check out: ueberdosis/tiptap-php
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
- TableCell
- TableHeader
- TableRow
Supported marks
Custom nodes
Define your custom nodes as PHP classes:
<?php
class CustomNode extends \ProseMirrorToHtml\Nodes\Node
{
protected $nodeType = '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
- Hans Pagel
- sauerbraten
- WiebkeVog
- All Contributors
Related packages
- tiptap by @ueberdosis
- prosemirror-to-html-js by @enVolt
License
The MIT License (MIT). Please see License File for more information.