Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Nov 27, 2023
1 parent 35b5b27 commit 75c4a8d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,22 @@ $html = (new Nadar\ProseMirror\Parser())->toHtml($json);

Each node corresponds to a callable function within the parser, with the node's name serving as the key. This setup facilitates the easy addition or modification of nodes.

For instance, suppose you want to adjust the rendering of the image node. In that case, you can achieve this by incorporating your own function into the parser:
For instance, suppose you want to adjust the rendering of the image node. In that case, you can achieve this by incorporating your own function into the parser using the `replaceNode()` method:

```php
$parser = new \Nadar\ProseMirrorParser();
$parser->overwriteNode(\Nadar\ProseMirror\Types::image, fn(\Nadar\ProseMirror\Node $node) => '<img src="' . $node->getAttr('src') . '" alt="' . $node->getAttr('alt') . '" class="this-is-my-class" />');
$parser = new \Nadar\ProseMirror\Parser();
$parser->replaceNode(\Nadar\ProseMirror\Types::image, fn(\Nadar\ProseMirror\Node $node) => '<img src="' . $node->getAttr('src') . '" alt="' . $node->getAttr('alt') . '" class="this-is-my-class" />');
$html = $parser->toHtml($json);
```

Or if you have a custom node which a custom name you can add it to the parser:
> Check the Types class for all available node types.
Or if you have a custom node with a custom name you can add it to the parser using `addNode` method:

```php
$parser = new \Nadar\ProseMirrorParser();
$parser = new \Nadar\ProseMirror\Parser();
$parser->addNode('myCustomNode', fn(\Nadar\ProseMirror\Node $node) => '<div class="my-custom-node">...</div>');
$html = $parser->toHtml($json);
```

> The `addNode()` and `replaceNode()` methods are internal almost the same, except of that replaceNode should only be used for existing defualt nodes, which are listed in the Types enum class.

0 comments on commit 75c4a8d

Please sign in to comment.