edwh-editorjs 2.3.2__py3-none-any.whl → 2.5.0a1__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 +35 -3
- editorjs/core.py +38 -11
- {edwh_editorjs-2.3.2.dist-info → edwh_editorjs-2.5.0a1.dist-info}/METADATA +1 -1
- edwh_editorjs-2.5.0a1.dist-info/RECORD +10 -0
- edwh_editorjs-2.3.2.dist-info/RECORD +0 -10
- {edwh_editorjs-2.3.2.dist-info → edwh_editorjs-2.5.0a1.dist-info}/WHEEL +0 -0
editorjs/__about__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "2.
|
|
1
|
+
__version__ = "2.5.0a1"
|
editorjs/blocks.py
CHANGED
|
@@ -406,7 +406,17 @@ class ImageBlock(EditorJSBlock):
|
|
|
406
406
|
def to_markdown(cls, data: EditorChildData) -> str:
|
|
407
407
|
url = data.get("url", "") or data.get("file", {}).get("url", "")
|
|
408
408
|
caption = data.get("caption", "")
|
|
409
|
-
|
|
409
|
+
|
|
410
|
+
with_border = "1" if data.get("withBorder") else ""
|
|
411
|
+
with_background = "1" if data.get("withBackground") else ""
|
|
412
|
+
stretched = "1" if data.get("stretched") else ""
|
|
413
|
+
|
|
414
|
+
# always custom type so we can render as <figure> instead of markdown2's default (simple <img>)
|
|
415
|
+
return f"""<editorjs type="image" caption="{caption}" border="{with_border}" background="{with_background}" stretched="{stretched}" url="{url}" />\n\n"""
|
|
416
|
+
|
|
417
|
+
@classmethod
|
|
418
|
+
def _caption(cls, node: MDChildNode):
|
|
419
|
+
return node.get("alt") or node.get("caption") or ""
|
|
410
420
|
|
|
411
421
|
@classmethod
|
|
412
422
|
def to_json(cls, node: MDChildNode) -> list[dict]:
|
|
@@ -414,15 +424,37 @@ class ImageBlock(EditorJSBlock):
|
|
|
414
424
|
{
|
|
415
425
|
"type": "image",
|
|
416
426
|
"data": {
|
|
417
|
-
"caption": cls.to_text(node),
|
|
418
427
|
"file": {"url": node.get("url")},
|
|
428
|
+
"caption": cls._caption(node),
|
|
429
|
+
"withBorder": bool(node.get("border", False)),
|
|
430
|
+
"stretched": bool(node.get("stretched", False)),
|
|
431
|
+
"withBackground": bool(node.get("background", False)),
|
|
419
432
|
},
|
|
420
433
|
}
|
|
421
434
|
]
|
|
422
435
|
|
|
423
436
|
@classmethod
|
|
424
437
|
def to_text(cls, node: MDChildNode) -> str:
|
|
425
|
-
|
|
438
|
+
caption = cls._caption(node)
|
|
439
|
+
url = node.get("url")
|
|
440
|
+
|
|
441
|
+
background = node.get("background") or ""
|
|
442
|
+
stretched = node.get("stretched") or ""
|
|
443
|
+
border = node.get("border") or ""
|
|
444
|
+
|
|
445
|
+
return f"""
|
|
446
|
+
<div class="ce-block {stretched and 'ce-block--stretched'}">
|
|
447
|
+
<div class="ce-block__content">
|
|
448
|
+
<div class="cdx-block image-tool image-tool--filled {background and 'image-tool--withBackground'} {stretched and 'image-tool--stretched'} {border and 'image-tool--withBorder'}">
|
|
449
|
+
<div class="image-tool__image">
|
|
450
|
+
<figure>
|
|
451
|
+
<img class="image-tool__image-picture" src="{url}" title="{caption}" alt="{caption}">
|
|
452
|
+
<figcaption>{caption}</figcaption>
|
|
453
|
+
</figure>
|
|
454
|
+
</div>
|
|
455
|
+
</div>
|
|
456
|
+
</div>
|
|
457
|
+
"""
|
|
426
458
|
|
|
427
459
|
|
|
428
460
|
@block("blockquote", "quote")
|
editorjs/core.py
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import typing as t
|
|
3
|
+
import warnings
|
|
3
4
|
|
|
4
5
|
import markdown2
|
|
5
6
|
import mdast
|
|
6
7
|
from typing_extensions import Self
|
|
7
8
|
|
|
8
9
|
from .blocks import BLOCKS
|
|
10
|
+
from .exceptions import TODO
|
|
9
11
|
from .helpers import unix_timestamp
|
|
10
12
|
from .types import MDRootNode
|
|
11
13
|
|
|
@@ -41,13 +43,26 @@ class EditorJS:
|
|
|
41
43
|
for child in blocks:
|
|
42
44
|
_type = child["type"]
|
|
43
45
|
if not (block := BLOCKS.get(_type)):
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
warnings.warn(
|
|
47
|
+
f"from_json: Unsupported block type `{_type}`",
|
|
48
|
+
category=RuntimeWarning,
|
|
49
|
+
)
|
|
50
|
+
continue
|
|
51
|
+
|
|
52
|
+
try:
|
|
53
|
+
data = child.get("data", {})
|
|
54
|
+
# forward any 'tunes' via data:
|
|
55
|
+
data["tunes"] = data.get("tunes") or child.get("tunes") or {}
|
|
56
|
+
|
|
57
|
+
markdown_items.append(block.to_markdown(data))
|
|
58
|
+
except Exception as e:
|
|
59
|
+
warnings.warn(
|
|
60
|
+
"from_json: Oh oh, unexpected block failure!",
|
|
61
|
+
category=RuntimeWarning,
|
|
62
|
+
source=e,
|
|
63
|
+
)
|
|
64
|
+
# if isinstance(e, TODO):
|
|
65
|
+
# raise e
|
|
51
66
|
|
|
52
67
|
markdown = "".join(markdown_items)
|
|
53
68
|
return cls.from_markdown(markdown)
|
|
@@ -76,9 +91,22 @@ class EditorJS:
|
|
|
76
91
|
for child in self._mdast["children"]:
|
|
77
92
|
_type = child["type"]
|
|
78
93
|
if not (block := BLOCKS.get(_type)):
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
94
|
+
warnings.warn(
|
|
95
|
+
f"to_json: Unsupported block type `{_type}`",
|
|
96
|
+
category=RuntimeWarning,
|
|
97
|
+
)
|
|
98
|
+
continue
|
|
99
|
+
|
|
100
|
+
try:
|
|
101
|
+
blocks.extend(block.to_json(child))
|
|
102
|
+
except Exception as e:
|
|
103
|
+
warnings.warn(
|
|
104
|
+
"to_json: Oh oh, unexpected block failure!",
|
|
105
|
+
category=RuntimeWarning,
|
|
106
|
+
source=e,
|
|
107
|
+
)
|
|
108
|
+
# if isinstance(e, TODO):
|
|
109
|
+
# raise e
|
|
82
110
|
|
|
83
111
|
data = {"time": unix_timestamp(), "blocks": blocks, "version": EDITORJS_VERSION}
|
|
84
112
|
|
|
@@ -107,7 +135,6 @@ class EditorJS:
|
|
|
107
135
|
Export HTML string
|
|
108
136
|
"""
|
|
109
137
|
md = self.to_markdown()
|
|
110
|
-
# todo: deal with custom elements like linktool, attaches
|
|
111
138
|
return self._md.convert(md)
|
|
112
139
|
|
|
113
140
|
def __repr__(self):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: edwh-editorjs
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.5.0a1
|
|
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=YLKqewJZL65Iqq73XcOTOPmBl9fywRqGC_-S7MYAKkE,24
|
|
2
|
+
editorjs/__init__.py,sha256=-OHUf7ZXfkbdFB1r85eIjpHRfql-GCNUCKuBEdEt2Rc,58
|
|
3
|
+
editorjs/blocks.py,sha256=rGonr0_ODCS5PK_wigI4rpHBwQXb7LZhXwcNJJEWnH8,28682
|
|
4
|
+
editorjs/core.py,sha256=4igv2l8Rm1S92kxKrIXGIUlNHh6pnjq8F28XQr91I9o,4510
|
|
5
|
+
editorjs/exceptions.py,sha256=oKuWqi4CSnFGZfVZWtTZ2XZeHXm5xF-nAtX_1YLm6sI,230
|
|
6
|
+
editorjs/helpers.py,sha256=q861o5liNibMTp-Ozay17taF7CTNsRe901lYhhxdwHg,73
|
|
7
|
+
editorjs/types.py,sha256=W7IZWMWgzJaQulybIt0Gx5N63rVj4mEy73VJWo4VAQA,1029
|
|
8
|
+
edwh_editorjs-2.5.0a1.dist-info/METADATA,sha256=PAVb54js3j2DF7P-K72xPCrwq3vw2rbss9_xwAx5RKc,998
|
|
9
|
+
edwh_editorjs-2.5.0a1.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
10
|
+
edwh_editorjs-2.5.0a1.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
editorjs/__about__.py,sha256=J4CRnpR3v72FGOMp8gqSua_XWZpAfXuqgVWiQFB-gTY,22
|
|
2
|
-
editorjs/__init__.py,sha256=-OHUf7ZXfkbdFB1r85eIjpHRfql-GCNUCKuBEdEt2Rc,58
|
|
3
|
-
editorjs/blocks.py,sha256=dT54-wCL4sm9fO7OiJO8Q0SgTuHq3wtv7KQiOF81oks,27138
|
|
4
|
-
editorjs/core.py,sha256=WSBmAIKwSqHIP_NFmUVUJiyHPgq7D8902Jm9HRf1nSk,3669
|
|
5
|
-
editorjs/exceptions.py,sha256=oKuWqi4CSnFGZfVZWtTZ2XZeHXm5xF-nAtX_1YLm6sI,230
|
|
6
|
-
editorjs/helpers.py,sha256=q861o5liNibMTp-Ozay17taF7CTNsRe901lYhhxdwHg,73
|
|
7
|
-
editorjs/types.py,sha256=W7IZWMWgzJaQulybIt0Gx5N63rVj4mEy73VJWo4VAQA,1029
|
|
8
|
-
edwh_editorjs-2.3.2.dist-info/METADATA,sha256=798OipvvgiexYoOa7x3KFac2MouJVMYQA5KzF6bR1ss,996
|
|
9
|
-
edwh_editorjs-2.3.2.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
10
|
-
edwh_editorjs-2.3.2.dist-info/RECORD,,
|
|
File without changes
|