2
2
[ ![ License: GPL v3] ( https://img.shields.io/badge/License-GPLv3-blue.svg )] ( https://www.gnu.org/licenses/gpl-3.0 )
3
3
# Simple PHP Parser for Editor.js
4
4
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 `
6
28
7
29
## Installation
8
30
9
31
```
10
- composer require boring-dragon /editorjs-simple-html-parser
32
+ composer require edd-g /editorjs-simple-html-parser
11
33
```
34
+ ## 1. JSON to HTML Parser
12
35
13
- ## Usage
36
+ ### Usage
14
37
15
38
``` php
16
39
use Durlecode\EJSParser\Parser;
@@ -47,26 +70,7 @@ $parser->setPrefix("cat");
47
70
48
71
$parsed = $parser->toHtml();
49
72
```
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
70
74
71
75
#### ` toHtml() `
72
76
Return generated HTML
@@ -88,87 +92,107 @@ Return Editor.js content blocks
88
92
89
93
### Generated HTML
90
94
91
- ##### Code
95
+ ##### Header
92
96
93
97
``` html
94
- <div class =" prs-code" >
95
- <pre >
96
- <code ></code >
97
- </pre >
98
- </div >
98
+ <h2 class =" prs-header prs_center" >Lorem</h2 >
99
99
```
100
100
101
- ##### Embed
102
- ###### * (Actually working with Youtube, Codepen & Gfycat)*
101
+ ##### Paragraph
103
102
104
103
``` 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 >
108
109
```
109
110
110
- ##### Delimiter
111
+ ##### Ordered List
111
112
112
113
``` html
113
- <hr class =" prs-delimiter" >
114
+ <ol class =" prs-list prs_ordered" >
115
+ <li ></li >
116
+ </ol >
114
117
```
115
118
116
- ##### Header
119
+ ##### Unordered List
117
120
118
121
``` html
119
- <h2 class =" prs-h2" >Lorem</h2 >
122
+ <ul class =" prs-list" >
123
+ <li ></li >
124
+ </ul >
120
125
```
121
126
122
- ##### Link
127
+ ##### Table
123
128
124
129
``` 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 >
135
142
```
136
143
137
- ##### Ordered List
144
+ ##### Code
138
145
139
146
``` 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 >
144
151
</div >
145
152
```
146
153
147
- ##### Unordered List
154
+ ##### Embed
155
+ ###### * (Actually working with Youtube, Codepen & Gfycat)*
148
156
149
157
``` 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 >
155
162
```
156
163
157
- ##### Paragraph
164
+ ##### Delimiter
158
165
159
166
``` 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 >
165
180
```
166
181
167
182
##### Image
168
183
169
184
``` 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 >
172
196
<figcaption ></figcaption >
173
197
</figure >
174
198
```
@@ -177,18 +201,89 @@ Return Editor.js content blocks
177
201
178
202
``` html
179
203
<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 >
185
207
</div >
186
208
```
187
209
210
+ ##### Alert
211
+
212
+ ``` html
213
+ <p class =" prs-alert prs_center prs_success" >
214
+ Alert!
215
+ </p >
216
+ ```
217
+
188
218
##### Raw
189
219
190
220
``` html
191
221
<div class =" prs-raw" >
192
222
Raw HTML ...
193
223
</div >
194
224
```
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