From eb7e5df1c1d85d45e4ea57edcf1f951c2c65dfcd Mon Sep 17 00:00:00 2001 From: Nadar Date: Tue, 5 Dec 2023 09:22:33 +0000 Subject: [PATCH] readme --- README.md | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index db389ef..54c3d8b 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,12 @@ The **prosemirror-json-parser** is a versatile library designed to parse ProseMi It functions seamlessly with both TipTap and ProseMirror, given that TipTap is built upon ProseMirror. +[![PHPUnit Tests](https://github.com/nadar/prosemirror-json-parser/actions/workflows/phpunit.yml/badge.svg)](https://github.com/nadar/prosemirror-json-parser/actions/workflows/phpunit.yml) +[![Latest Stable Version](https://poser.pugx.org/nadar/prosemirror-json-parser/v/stable)](https://packagist.org/packages/nadar/prosemirror-json-parser) +[![Total Downloads](https://poser.pugx.org/nadar/prosemirror-json-parser/downloads)](https://packagist.org/packages/nadar/prosemirror-json-parser) +[![License](https://poser.pugx.org/nadar/prosemirror-json-parser/license)](https://packagist.org/packages/nadar/prosemirror-json-parser) + + **Key Features:** + Dependency-free: No additional libraries required for this parser. @@ -21,7 +27,8 @@ composer require nadar/prosemirror-json-parser Then add parser to your project and convert the input json code (which must be available as array, so you can use `json_decode($json, true)` to convert the json string into an array) into html: ```php -$html = (new Nadar\ProseMirror\Parser())->toHtml($json); +$html = (new Nadar\ProseMirror\Parser()) + ->toHtml($json); ``` ## Extending & Customizing @@ -31,9 +38,9 @@ Each node corresponds to a callable function within the parser, with the node's 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\ProseMirror\Parser(); -$parser->replaceNode(\Nadar\ProseMirror\Types::image, fn(\Nadar\ProseMirror\Node $node) => '' . $node->getAttr('alt') . ''); -$html = $parser->toHtml($json); +$html = (new \Nadar\ProseMirror\Parser()); + ->replaceNode(\Nadar\ProseMirror\Types::image, fn(\Nadar\ProseMirror\Node $node) => '') + ->toHtml($json); ``` > Check the Types class for all available node types. @@ -41,9 +48,9 @@ $html = $parser->toHtml($json); 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\ProseMirror\Parser(); -$parser->addNode('myCustomNode', fn(\Nadar\ProseMirror\Node $node) => '
...
'); -$html = $parser->toHtml($json); +$html = (new \Nadar\ProseMirror\Parser()) + ->addNode('myCustomNode', fn(\Nadar\ProseMirror\Node $node) => '
...
') + ->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