From 75c4a8d6ba14d87f4e205f0528e4aa71ae75bed9 Mon Sep 17 00:00:00 2001 From: Nadar Date: Mon, 27 Nov 2023 09:51:57 +0000 Subject: [PATCH] readme --- README.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 55c0410..db389ef 100644 --- a/README.md +++ b/README.md @@ -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) => '' . $node->getAttr('alt') . ''); +$parser = new \Nadar\ProseMirror\Parser(); +$parser->replaceNode(\Nadar\ProseMirror\Types::image, fn(\Nadar\ProseMirror\Node $node) => '' . $node->getAttr('alt') . ''); $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) => '
...
'); +$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. \ No newline at end of file