Skip to content

Commit b7836dd

Browse files
authored
Update README.md
1 parent 8ed636c commit b7836dd

File tree

1 file changed

+168
-73
lines changed

1 file changed

+168
-73
lines changed

README.md

+168-73
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,38 @@
22
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
33
# Simple PHP Parser for Editor.js
44

5-
Parse to HTML clean JSON Data from [Editor.js](https://editorjs.io/ "Editor.js Homepage")
5+
Parse data for [Editor.js](https://editorjs.io/ "Editor.js Homepage") with 2 way:
6+
1. Parse JSON data to HTML
7+
2. Parse HTML to JSON data
8+
## Supported Tools
9+
10+
Package | Key | Main CSS Class<br>(with default prefix) | Additional / modificator CSS classes<br>(with default prefix)
11+
--- | --- | --- | ---
12+
`@editorjs/header`<br>`editorjs-header-with-alignment` | `header` | `.prs-header` | alignment:<br>`.prs_left`<br>`.prs_right`<br>`.prs_center`<br>`.prs_justify`
13+
`@editorjs/paragraph`<br>`editorjs-paragraph-with-alignment` | `paragraph` | `.prs-paragraph` | alignment:<br>`.prs_left`<br>`.prs_right`<br>`.prs_center`<br>`.prs_justify`
14+
`@editorjs/inline-code` | | |
15+
`@editorjs/marker` | | |
16+
`@editorjs/underline` | | |
17+
`@editorjs/list` | `list` | `.prs-list` | additional:<br>`.prs_ordered`
18+
`@editorjs/raw` | `raw` | |
19+
`@editorjs/simple-image` | `simpleImage` | `.prs-image` | additional:<br>`.prs_withborder`<br>`.prs_withbackground`<br>`.prs_stretched`
20+
`@editorjs/embed` | `embed` | `.prs-embed` | additional:<br>`.prs_youtube`<br>`.prs_codepen`<br>`.prs_vimeo`
21+
`@editorjs/link` | `linkTool` | `.prs-linktool` | additional:<br>`.prs_title`<br>`.prs_description`
22+
`@editorjs/delimiter` | `delimiter` | `.prs-delimiter` |
23+
`editorjs-alert` | `alert` | `.prs-alert` | alignment:<br>`.prs_left`<br>`.prs_right`<br>`.prs_center`<br>additional:<br>`.prs_primary`<br>`.prs_secondary`<br>`.prs_info`<br>`.prs_success`<br>`.prs_warning`<br>`.prs_danger`<br>`.prs_light`<br>`.prs_dark`
24+
`@editorjs/warning` | `warning` | `.prs-warning` |
25+
`@editorjs/table` | `table` | `.prs-table` | additional:<br>`.prs_withheadings`
26+
`@editorjs/quote` | `quote` | `.prs-quote` | alignment:<br>`.prs_left`<br>`.prs_center`
27+
`@editorjs/code` | `code` | `.prs-code`
628

729
## Installation
830

931
```
10-
composer require boring-dragon/editorjs-simple-html-parser
32+
composer require edd-g/editorjs-simple-html-parser
1133
```
34+
## 1. JSON to HTML Parser
1235

13-
## Usage
36+
### Usage
1437

1538
```php
1639
use Durlecode\EJSParser\Parser;
@@ -47,26 +70,7 @@ $parser->setPrefix("cat");
4770

4871
$parsed = $parser->toHtml();
4972
```
50-
51-
## Supported Tools
52-
53-
Package | Key | Main CSS Class
54-
--- | --- | ---
55-
`@editorjs/code` | `code` | `.prs-code`
56-
`@editorjs/embed` | `embed` | `.prs-embed`
57-
`@editorjs/delimiter` | `delimiter` | `.prs-delimiter`
58-
`@editorjs/header` | `header` | `.prs-h{header-level}`
59-
`@editorjs/inline-code` | |
60-
`@editorjs/link` | `link` | `.prs-link`
61-
`@editorjs/list` | `list` | `.prs-list`
62-
`@editorjs/marker` | |
63-
`@editorjs/paragraph` | `paragraph` | `.prs-paragraph`
64-
`@editorjs/raw` | `raw` |
65-
`@editorjs/simple-image` | `simpleImage` | `.prs-image`
66-
`@editorjs/warning` | `warning` | `.prs-warning`
67-
`@editorjs/quote` | `quote` | `.prs-quote`
68-
69-
## Methods
73+
### Methods
7074

7175
#### `toHtml()`
7276
Return generated HTML
@@ -88,87 +92,107 @@ Return Editor.js content blocks
8892

8993
### Generated HTML
9094

91-
##### Code
95+
##### Header
9296

9397
```html
94-
<div class="prs-code">
95-
<pre>
96-
<code></code>
97-
</pre>
98-
</div>
98+
<h2 class="prs-header prs_center">Lorem</h2>
9999
```
100100

101-
##### Embed
102-
###### *(Actually working with Youtube, Codepen & Gfycat)*
101+
##### Paragraph
103102

104103
```html
105-
<div class="prs-embed">
106-
<iframe src="" height="300"></iframe>
107-
</div>
104+
<p class="prs-paragraph prs_center">
105+
<code class="inline-code">Pellentesque</code>
106+
<i>malesuada fames</i>
107+
<mark class="cdx-marker">tempus</mark>
108+
</p>
108109
```
109110

110-
##### Delimiter
111+
##### Ordered List
111112

112113
```html
113-
<hr class="prs-delimiter">
114+
<ol class="prs-list prs_ordered">
115+
<li></li>
116+
</ol>
114117
```
115118

116-
##### Header
119+
##### Unordered List
117120

118121
```html
119-
<h2 class="prs-h2">Lorem</h2>
122+
<ul class="prs-list">
123+
<li></li>
124+
</ul>
120125
```
121126

122-
##### Link
127+
##### Table
123128

124129
```html
125-
<a href="https://github.com/" target="_blank" class="prs-link">
126-
<div class="prs-link-container-with-img">
127-
<div class="prs-link-title">Title</div>
128-
<div class="prs-link-description">Description</div>
129-
<div class="prs-link-url">https://example.com/</div>
130-
</div>
131-
<div class="prs-link-img-container">
132-
<img src="https://example.com/cat.png" alt="">
133-
</div>
134-
</a>
130+
<table class="prs-table prs_withheadings">
131+
<thead>
132+
<tr>
133+
<th>1</th><th>2</th>
134+
</tr>
135+
</thead>
136+
<tbody>
137+
<tr>
138+
<td>a</td><td>b</td>
139+
</tr>
140+
</tbody>
141+
</table>
135142
```
136143

137-
##### Ordered List
144+
##### Code
138145

139146
```html
140-
<div class="prs-list">
141-
<ol>
142-
<li></li>
143-
</ol>
147+
<div class="prs-code">
148+
<pre>
149+
<code></code>
150+
</pre>
144151
</div>
145152
```
146153

147-
##### Unordered List
154+
##### Embed
155+
###### *(Actually working with Youtube, Codepen & Gfycat)*
148156

149157
```html
150-
<div class="prs-list">
151-
<ul>
152-
<li></li>
153-
</ul>
154-
</div>
158+
<figure class="prs-embed prs_youtube">
159+
<iframe width="580" height="320" src="https://www.youtube.com/embed/CwXOrWvPBPk" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen="1"></iframe>
160+
<figcaption>Shrek (2001) Trailer</figcaption>
161+
</figure>
155162
```
156163

157-
##### Paragraph
164+
##### Delimiter
158165

159166
```html
160-
<p class="prs-paragraph">
161-
<code class="inline-code">Pellentesque</code>
162-
<i>malesuada fames</i>
163-
<mark class="cdx-marker">tempus</mark>
164-
</p>
167+
<hr class="prs-delimiter">
168+
```
169+
170+
##### Link / LinkTool
171+
172+
```html
173+
<figure class="prs-linkTool">
174+
<a href="https://github.com/">
175+
<img src="https://example.com/cat.png" alt="">
176+
<p class="prs_title">Title</p>
177+
<p class="prs_description">Description</p>
178+
</a>
179+
</figure>
165180
```
166181

167182
##### Image
168183

169184
```html
170-
<figure class="prs-image">
171-
<img src="" class="prs-image-border prs-image-background" alt="">
185+
<figure class="prs-image prs_withborder prs_withbackground prs_stretched">
186+
<img src="" alt="">
187+
<figcaption></figcaption>
188+
</figure>
189+
```
190+
191+
##### Quote
192+
193+
```html
194+
<figure class="prs-quote prs_center">
195+
<blockquote></blockquote>
172196
<figcaption></figcaption>
173197
</figure>
174198
```
@@ -177,18 +201,89 @@ Return Editor.js content blocks
177201

178202
```html
179203
<div class="prs-warning">
180-
<ion-icon name="information-outline" size="large" aria-label="information outline"></ion-icon>
181-
<div>
182-
<p>Title</p>
183-
<p>Message</p>
184-
</div>
204+
<i></i>
205+
<h4>Title</h4>
206+
<p>Message</p>
185207
</div>
186208
```
187209

210+
##### Alert
211+
212+
```html
213+
<p class="prs-alert prs_center prs_success">
214+
Alert!
215+
</p>
216+
```
217+
188218
##### Raw
189219

190220
```html
191221
<div class="prs-raw">
192222
Raw HTML ...
193223
</div>
194224
```
225+
226+
## 2. HTML to JSON Parser
227+
228+
### Usage
229+
230+
```php
231+
use Durlecode\EJSParser\HtmlParser;
232+
233+
$parser = new HtmlParser($html);
234+
235+
$blocks = $parser->toBlocks();
236+
237+
header("Content-Type: application/json");
238+
echo $blocks;
239+
```
240+
241+
Where `$html` is the HTML specially tagged with CSS classes *See examples of the generated HTML code above*
242+
243+
By default this will parse html with css classes with `prs` prefix, so if you want to change it, follow example below
244+
245+
```php
246+
use Durlecode\EJSParser\HtmlParser;
247+
248+
$parser = new HtmlParser($html);
249+
250+
$parser->setPrefix("cat");
251+
252+
$blocks = $parser->toBlocks();
253+
```
254+
255+
You may set time and version EditorJS generated blocks *By default: time generate auto, EditorJS version pass from config.php*:
256+
257+
```php
258+
use Durlecode\EJSParser\HtmlParser;
259+
260+
$parser = new HtmlParser($html);
261+
262+
$parser->setTime("1703787424242");
263+
$parser->setVersion("2.28.8");
264+
265+
$blocks = $parser->toBlocks();
266+
```
267+
268+
### Methods
269+
270+
#### `toBlocks()`
271+
Return generated EditorJS Blocks
272+
273+
#### `setPrefix(string $prefix)`
274+
Set CSS classes Prefix
275+
276+
#### `getPrefix()`
277+
Return current prefix
278+
279+
#### `setVersion(string $version)`
280+
Set Editor.js content version
281+
282+
#### `getVersion()`
283+
Return Editor.js content version
284+
285+
#### `getTime()`
286+
Return Editor.js content timestamp
287+
288+
#### `setTime(string $time)`
289+
Set Editor.js content timestamp

0 commit comments

Comments
 (0)