muhammadsiyab / editorjs-parser-php
PHP parser for editorjs library
v1.0.1
2024-04-01 22:44 UTC
Requires
- php: >=7.4
Requires (Dev)
README
This package allows you to easily parse Editor.js JSON output to HTML using PHP. This package is currently able to parse the blocks from these plugins:
- Paragraph
- Header
- Image
- Quote
- List
- Nested List
- Code
- Embed (Currently, the following embed blocks are supported)
- Youtube
- Twitter/X
- Codepen
- Github (gist)
Requirements
PHP >=7.4
Installation
composer require muhammadsiyab/editorjs-parser-php
Using
require "vendor/autoload.php"; use MuhammadSiyab\EditorjsParserPhp\Parser; # The json output generated by Editor.js $content = '{"time": 1711232666978,"blocks": [{...}]}' ; $parser = new Parser(); $parsed = $parser->parse($content); echo $parsed; // outputs the generated HTML
Allow only specific blocks for parsing
# Only parses the `headings` and `paragraphs` $parsed = $parser ->only('header', 'paragraph') // can be parsed using the array syntax ['header', 'paragraph'] ->parse($content);
Disable specific blocks from being parsed
# Parses all the blocks except `list` and `code` $parsed = $parser ->except('list', 'code') // can be parsed using the array syntax ['list', 'code'] ->parse($content);
License
This Package is open-sourced software licensed under the MIT license