Skip to content

spiegeltechlab/html-to-prosemirror

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚨 We’ve done a rewrite that you probably want to check out: ueberdosis/tiptap-php

HTML to ProseMirror

Integrate Sponsor

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

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

License

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

About

Takes HTML and outputs ProseMirror compatible JSON.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%