edwh-editorjs 2.0.1__py3-none-any.whl → 2.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- editorjs/__about__.py +1 -1
- editorjs/blocks.py +23 -7
- editorjs/core.py +4 -3
- {edwh_editorjs-2.0.1.dist-info → edwh_editorjs-2.1.0.dist-info}/METADATA +1 -1
- edwh_editorjs-2.1.0.dist-info/RECORD +10 -0
- edwh_editorjs-2.0.1.dist-info/RECORD +0 -10
- {edwh_editorjs-2.0.1.dist-info → edwh_editorjs-2.1.0.dist-info}/WHEEL +0 -0
editorjs/__about__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "2.0
|
|
1
|
+
__version__ = "2.1.0"
|
editorjs/blocks.py
CHANGED
|
@@ -130,12 +130,20 @@ class HeadingBlock(EditorJSBlock):
|
|
|
130
130
|
return child.get("value", "")
|
|
131
131
|
|
|
132
132
|
|
|
133
|
+
def paragraph_block(text: str):
|
|
134
|
+
return {"type": "paragraph", "data": {"text": text}}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def raw_block(html: str):
|
|
138
|
+
return {"type": "raw", "data": {"html": html}}
|
|
139
|
+
|
|
140
|
+
|
|
133
141
|
@block("paragraph")
|
|
134
142
|
class ParagraphBlock(EditorJSBlock):
|
|
135
143
|
@classmethod
|
|
136
144
|
def to_markdown(cls, data: EditorChildData) -> str:
|
|
137
145
|
text = data.get("text", "")
|
|
138
|
-
return f"{text}\n"
|
|
146
|
+
return f"{text}\n\n"
|
|
139
147
|
|
|
140
148
|
@classmethod
|
|
141
149
|
def to_json(cls, node: MDChildNode) -> list[dict]:
|
|
@@ -165,7 +173,7 @@ class ParagraphBlock(EditorJSBlock):
|
|
|
165
173
|
else:
|
|
166
174
|
# <editorjs>something</editorjs> = 3 children
|
|
167
175
|
result.extend(
|
|
168
|
-
EditorJSCustom.to_json({"children": nodes[idx: idx + 2]})
|
|
176
|
+
EditorJSCustom.to_json({"children": nodes[idx : idx + 2]})
|
|
169
177
|
)
|
|
170
178
|
|
|
171
179
|
skip = 2
|
|
@@ -173,9 +181,14 @@ class ParagraphBlock(EditorJSBlock):
|
|
|
173
181
|
|
|
174
182
|
elif _type == "image":
|
|
175
183
|
if current_text:
|
|
176
|
-
|
|
184
|
+
# {"id":"zksvpxQTDD","type":"raw","data":{"html":"<marquee> raw </marquee>"}}
|
|
185
|
+
result.append(
|
|
186
|
+
raw_block(current_text)
|
|
187
|
+
if any_html
|
|
188
|
+
else paragraph_block(current_text)
|
|
189
|
+
)
|
|
177
190
|
current_text = ""
|
|
178
|
-
any_html = False
|
|
191
|
+
any_html = False # reset
|
|
179
192
|
|
|
180
193
|
result.extend(ImageBlock.to_json(child))
|
|
181
194
|
else:
|
|
@@ -194,7 +207,9 @@ class ParagraphBlock(EditorJSBlock):
|
|
|
194
207
|
|
|
195
208
|
# final text after image:
|
|
196
209
|
if current_text:
|
|
197
|
-
result.append(
|
|
210
|
+
result.append(
|
|
211
|
+
raw_block(current_text) if any_html else paragraph_block(current_text)
|
|
212
|
+
)
|
|
198
213
|
|
|
199
214
|
return result
|
|
200
215
|
|
|
@@ -430,7 +445,8 @@ class RawBlock(EditorJSBlock):
|
|
|
430
445
|
|
|
431
446
|
@classmethod
|
|
432
447
|
def to_markdown(cls, data: EditorChildData) -> str:
|
|
433
|
-
|
|
448
|
+
text = data.get("html", "")
|
|
449
|
+
return f"{text}\n\n"
|
|
434
450
|
|
|
435
451
|
@classmethod
|
|
436
452
|
def to_json(cls, node: MDChildNode) -> list[dict]:
|
|
@@ -499,7 +515,7 @@ class TableBlock(EditorJSBlock):
|
|
|
499
515
|
"data": {
|
|
500
516
|
"content": table,
|
|
501
517
|
"withHeadings": with_headings,
|
|
502
|
-
}
|
|
518
|
+
},
|
|
503
519
|
}
|
|
504
520
|
]
|
|
505
521
|
|
editorjs/core.py
CHANGED
|
@@ -31,13 +31,14 @@ class EditorJS:
|
|
|
31
31
|
self._md = markdown2.Markdown(extras=extras) # todo: striketrough, ?
|
|
32
32
|
|
|
33
33
|
@classmethod
|
|
34
|
-
def from_json(cls, data: str | dict) -> Self:
|
|
34
|
+
def from_json(cls, data: str | dict | list) -> Self:
|
|
35
35
|
"""
|
|
36
36
|
Load from EditorJS JSON Blocks
|
|
37
37
|
"""
|
|
38
|
-
data = data if isinstance(data, dict) else json.loads(data)
|
|
38
|
+
data = data if isinstance(data, (dict, list)) else json.loads(data)
|
|
39
|
+
blocks = data["blocks"] if isinstance(data, dict) else data
|
|
39
40
|
markdown_items = []
|
|
40
|
-
for child in
|
|
41
|
+
for child in blocks:
|
|
41
42
|
_type = child["type"]
|
|
42
43
|
if not (block := BLOCKS.get(_type)):
|
|
43
44
|
raise TypeError(f"Unsupported block type `{_type}`")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: edwh-editorjs
|
|
3
|
-
Version: 2.0
|
|
3
|
+
Version: 2.1.0
|
|
4
4
|
Summary: EditorJS.py
|
|
5
5
|
Project-URL: Homepage, https://github.com/educationwarehouse/edwh-EditorJS
|
|
6
6
|
Author-email: SKevo <skevo.cw@gmail.com>, Robin van der Noord <robin.vdn@educationwarehouse.nl>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
editorjs/__about__.py,sha256=Xybt2skBZamGMNlLuOX1IG-h4uIxqUDGAO8MIGWrJac,22
|
|
2
|
+
editorjs/__init__.py,sha256=-OHUf7ZXfkbdFB1r85eIjpHRfql-GCNUCKuBEdEt2Rc,58
|
|
3
|
+
editorjs/blocks.py,sha256=kQxmx8QDDVhb1YP6JTFOCKGTYHfcbGswtkryorp1Cn8,22285
|
|
4
|
+
editorjs/core.py,sha256=T_7pOzLp7dBxxFSgfG0-ogZShVKaUBd5h_PEEuuSzdQ,3406
|
|
5
|
+
editorjs/exceptions.py,sha256=TyfHvk2Z5RbKxTDK7lrjgwAgVgInXIuDW63eO5jzVFw,106
|
|
6
|
+
editorjs/helpers.py,sha256=q861o5liNibMTp-Ozay17taF7CTNsRe901lYhhxdwHg,73
|
|
7
|
+
editorjs/types.py,sha256=W7IZWMWgzJaQulybIt0Gx5N63rVj4mEy73VJWo4VAQA,1029
|
|
8
|
+
edwh_editorjs-2.1.0.dist-info/METADATA,sha256=DmCP8FVdXpma3tupQeNLLTOKMSVpt6qYZTIAxaRo6qY,972
|
|
9
|
+
edwh_editorjs-2.1.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
10
|
+
edwh_editorjs-2.1.0.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
editorjs/__about__.py,sha256=wAxkK8w13vqoF47A8iqWdSlIgRRXmZiQ0R4wePZfzhs,22
|
|
2
|
-
editorjs/__init__.py,sha256=-OHUf7ZXfkbdFB1r85eIjpHRfql-GCNUCKuBEdEt2Rc,58
|
|
3
|
-
editorjs/blocks.py,sha256=QBHiAck6lX6454XhixRuWWzzsYEcMWTUGlxHzG1B8gM,21871
|
|
4
|
-
editorjs/core.py,sha256=CdZnprX-vkjFJATxPfG1acDqGKkHa3mDfbMEeXiR6eI,3331
|
|
5
|
-
editorjs/exceptions.py,sha256=TyfHvk2Z5RbKxTDK7lrjgwAgVgInXIuDW63eO5jzVFw,106
|
|
6
|
-
editorjs/helpers.py,sha256=q861o5liNibMTp-Ozay17taF7CTNsRe901lYhhxdwHg,73
|
|
7
|
-
editorjs/types.py,sha256=W7IZWMWgzJaQulybIt0Gx5N63rVj4mEy73VJWo4VAQA,1029
|
|
8
|
-
edwh_editorjs-2.0.1.dist-info/METADATA,sha256=ojEg0-0U-zubbzWHmU6raAtHdgwSWNWFSvyrNHk2iy8,972
|
|
9
|
-
edwh_editorjs-2.0.1.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
10
|
-
edwh_editorjs-2.0.1.dist-info/RECORD,,
|
|
File without changes
|