Download the PHP package nadar/prosemirror-json-parser without Composer
On this page you can find all versions of the php package nadar/prosemirror-json-parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nadar/prosemirror-json-parser
More information about nadar/prosemirror-json-parser
Files in nadar/prosemirror-json-parser
Package prosemirror-json-parser
Short Description A library that easily converts ProseMirror/TipTap JSON into customizable HTML elements.
License MIT
Informations about the package prosemirror-json-parser
ProseMirror JSON Parser
The ProseMirror JSON Parser (prosemirror-json-parser) is a versatile PHP library crafted for effortless conversion of ProseMirror/TipTap JSON Model content into HTML. With dependency-free operation and exceptional parsing speed, this library ensures high-performance HTML generation. Seamlessly integrating with TipTap and ProseMirror, it offers customization through easy addition or modification of nodes. Effortlessly install via Composer, utilize the toHtml
function and explore extensive customization options for tailored JSON to HTML conversion.
It functions seamlessly with both TipTap and ProseMirror because TipTap is built upon ProseMirror.
Key Features:
- Dependency-free: No additional libraries required for this parser.
- Exceptional speed: Offers high-performance parsing capabilities.
- Highly extendible: Enables the addition of custom nodes as per your requirements.
- 100% Code Coverage and Testing: Ensures comprehensive test coverage, guaranteeing reliability and stability.
- Robust out-of-the-box HTML generation: Generates high-quality HTML seamlessly without requiring modifications, ensuring ease of use and reliability.
Installation & Usage
To install the library using Composer, execute the following command:
After installing the library, integrate the parser into your project. Utilize the toHtml
function to convert your JSON value into renderable HTML code. Note that the toHtml
function solely accepts an array. Therefore, if your content is in JSON format, employ json_decode($json, true)
to initially convert the JSON string into an array and pass it toHtml(json_decode($json, true))
.
Extending & Customizing
Each node corresponds to a callable function within the parser, using the node's name as the key. This setup allows for easy addition or modification of nodes.
For example, to adjust the rendering of the image node, you can include your own function into the parser using the replaceNode()
method:
To see all default nodes declared, refer to the
Types
class.
If you have a custom node with a specific name, you can add it to the parser using the addNode()
method:
The
addNode()
andreplaceNode()
methods are almost identical internally, except thatreplaceNode
should only be used when altering the output of default nodes. You can view all by-default declared nodes in theTypes
class.
The text and image were enhanced by an AI, as English is not my first language and I am quite lazy. Even this sentence was generated by AI.