scrumpy / html-to-prosemirror
Takes HTML and outputs ProseMirror compatible JSON.
Fund package maintenance!
ueberdosis/
Installs: 94 515
Dependents: 0
Suggesters: 0
Security: 0
Stars: 63
Watchers: 5
Forks: 17
Open Issues: 2
Requires
- php: ^7.1.3|^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.15
- league/climate: ^3.5
- phpunit/phpunit: ^7.0|^8.0|^9.0
README
🚨 We’ve done a rewrite that you probably want to check out: ueberdosis/tiptap-php
HTML to ProseMirror
Takes HTML and outputs ProseMirror compatible JSON.
Installation
composer require ueberdosis/html-to-prosemirror
Usage
(new \HtmlToProseMirror\Renderer)->render('<p>Example Text</p>')
Output
{ "type": "doc", "content": [ { "type": "paragraph", "content": [ { "type": "text", "text": "Example Text" } ] } ] }
Supported nodes
- Blockquote
- BulletList
- CodeBlock
- HardBreak
- Heading
- Image
- ListItem
- OrderedList
- Paragraph
- Table
- TableCell
- TableHeader
- TableRow
- User
Supported marks
Custom nodes
Define your custom nodes as PHP classes:
<?php class CustomNode extends \HtmlToProseMirror\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
- tiptap by @ueberdosis
- html-to-prosemirror-js by @enVolt
License
The MIT License (MIT). Please see License File for more information.