edwh-editorjs 2.2.2__py3-none-any.whl → 2.3.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
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "2.
|
|
1
|
+
__version__ = "2.3.0"
|
editorjs/blocks.py
CHANGED
|
@@ -4,10 +4,12 @@ mdast to editorjs
|
|
|
4
4
|
|
|
5
5
|
import abc
|
|
6
6
|
import re
|
|
7
|
+
import traceback
|
|
7
8
|
import typing as t
|
|
8
9
|
from html.parser import HTMLParser
|
|
9
10
|
from urllib.parse import urlparse
|
|
10
11
|
|
|
12
|
+
import humanize
|
|
11
13
|
import markdown2
|
|
12
14
|
|
|
13
15
|
from .exceptions import TODO
|
|
@@ -199,7 +201,6 @@ class ParagraphBlock(EditorJSBlock):
|
|
|
199
201
|
if child.get("value", "").endswith("/>"):
|
|
200
202
|
# self-closing
|
|
201
203
|
result.append(EditorJSCustom.to_json(node))
|
|
202
|
-
continue
|
|
203
204
|
else:
|
|
204
205
|
# <editorjs>something</editorjs> = 3 children
|
|
205
206
|
result.extend(
|
|
@@ -207,7 +208,8 @@ class ParagraphBlock(EditorJSBlock):
|
|
|
207
208
|
)
|
|
208
209
|
|
|
209
210
|
skip = 2
|
|
210
|
-
|
|
211
|
+
|
|
212
|
+
continue
|
|
211
213
|
|
|
212
214
|
elif _type == "image":
|
|
213
215
|
if current_text:
|
|
@@ -480,7 +482,13 @@ class RawBlock(EditorJSBlock):
|
|
|
480
482
|
|
|
481
483
|
@classmethod
|
|
482
484
|
def to_json(cls, node: MDChildNode) -> list[dict]:
|
|
483
|
-
|
|
485
|
+
# todo: apply same logic as paragraph block to find <editorjs/> items!!!
|
|
486
|
+
raw = cls.to_text(node)
|
|
487
|
+
|
|
488
|
+
if raw.startswith("<editorjs"):
|
|
489
|
+
return EditorJSCustom.to_json({"children": [node]})
|
|
490
|
+
else:
|
|
491
|
+
return [raw_block(raw)]
|
|
484
492
|
|
|
485
493
|
@classmethod
|
|
486
494
|
def to_text(cls, node: MDChildNode) -> str:
|
|
@@ -610,9 +618,14 @@ class AttachmentBlock(EditorJSBlock):
|
|
|
610
618
|
|
|
611
619
|
@classmethod
|
|
612
620
|
def to_markdown(cls, data: EditorChildData) -> str:
|
|
613
|
-
file = data.get("file", {}).get("url", "")
|
|
614
621
|
title = data.get("title", "")
|
|
615
|
-
|
|
622
|
+
file = data.get("file", {})
|
|
623
|
+
url = file.get("url", "")
|
|
624
|
+
name = file.get("name", "")
|
|
625
|
+
extension = file.get("extension", "")
|
|
626
|
+
size = file.get("size", "")
|
|
627
|
+
|
|
628
|
+
return f"""<editorjs type="attaches" file="{url}" name="{name}" extension="{extension}" size="{size}">{title}</editorjs>\n\n"""
|
|
616
629
|
|
|
617
630
|
@classmethod
|
|
618
631
|
def to_json(cls, node: MDChildNode) -> list[dict]:
|
|
@@ -620,7 +633,12 @@ class AttachmentBlock(EditorJSBlock):
|
|
|
620
633
|
{
|
|
621
634
|
"type": "attaches",
|
|
622
635
|
"data": {
|
|
623
|
-
"file": {
|
|
636
|
+
"file": {
|
|
637
|
+
"url": node.get("file", ""),
|
|
638
|
+
"name": node.get("name", ""),
|
|
639
|
+
"extension": node.get("extension", ""),
|
|
640
|
+
"size": node.get("size", ""),
|
|
641
|
+
},
|
|
624
642
|
"title": node.get("body", ""),
|
|
625
643
|
},
|
|
626
644
|
}
|
|
@@ -628,19 +646,41 @@ class AttachmentBlock(EditorJSBlock):
|
|
|
628
646
|
|
|
629
647
|
@classmethod
|
|
630
648
|
def to_text(cls, node: MDChildNode) -> str:
|
|
649
|
+
# {'type': 'attaches', 'file': 'https://py4web.leiden.dockers.local/img/upload/8.deb?hash=778760cf05483147b2ff0fa0ddeab2b22d9343e8', 'name': 'gemistdownloadermd5-08d0e3cdb4f7e81986bdd0c60294dec03.0.0.5-1.deb', 'extension': 'deb', 'size': '1613660', 'body': 'gemistdownloader...
|
|
650
|
+
|
|
651
|
+
extension = node.get("extension", "")
|
|
652
|
+
|
|
653
|
+
file_icon = (
|
|
654
|
+
f"""
|
|
655
|
+
<div class="cdx-attaches__file-icon-background"></div>
|
|
656
|
+
<div class="cdx-attaches__file-icon-label" title="{extension}">{extension}</div>
|
|
657
|
+
"""
|
|
658
|
+
if extension
|
|
659
|
+
else """
|
|
660
|
+
<div class="cdx-attaches__file-icon-background">
|
|
661
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.3236 8.43554L9.49533 12.1908C9.13119 12.5505 8.93118 13.043 8.9393 13.5598C8.94741 14.0767 9.163 14.5757 9.53862 14.947C9.91424 15.3182 10.4191 15.5314 10.9422 15.5397C11.4653 15.5479 11.9637 15.3504 12.3279 14.9908L16.1562 11.2355C16.8845 10.5161 17.2845 9.53123 17.2682 8.4975C17.252 7.46376 16.8208 6.46583 16.0696 5.72324C15.3184 4.98066 14.3086 4.55425 13.2624 4.53782C12.2162 4.52138 11.2193 4.91627 10.4911 5.63562L6.66277 9.39093C5.57035 10.4699 4.97032 11.9473 4.99467 13.4979C5.01903 15.0485 5.66578 16.5454 6.79264 17.6592C7.9195 18.7731 9.43417 19.4127 11.0034 19.4374C12.5727 19.462 14.068 18.8697 15.1604 17.7907L18.9887 14.0354"></path></svg>
|
|
662
|
+
</div>
|
|
663
|
+
"""
|
|
664
|
+
)
|
|
665
|
+
|
|
666
|
+
file_size = (
|
|
667
|
+
f"""<div class="cdx-attaches__size">{humanize.naturalsize(int(size))}</div>"""
|
|
668
|
+
if (size := node.get("size", ""))
|
|
669
|
+
else ""
|
|
670
|
+
)
|
|
671
|
+
|
|
631
672
|
return f"""
|
|
632
673
|
<div class="cdx-attaches cdx-attaches--with-file">
|
|
633
674
|
<div class="cdx-attaches__file-icon">
|
|
634
|
-
|
|
635
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.3236 8.43554L9.49533 12.1908C9.13119 12.5505 8.93118 13.043 8.9393 13.5598C8.94741 14.0767 9.163 14.5757 9.53862 14.947C9.91424 15.3182 10.4191 15.5314 10.9422 15.5397C11.4653 15.5479 11.9637 15.3504 12.3279 14.9908L16.1562 11.2355C16.8845 10.5161 17.2845 9.53123 17.2682 8.4975C17.252 7.46376 16.8208 6.46583 16.0696 5.72324C15.3184 4.98066 14.3086 4.55425 13.2624 4.53782C12.2162 4.52138 11.2193 4.91627 10.4911 5.63562L6.66277 9.39093C5.57035 10.4699 4.97032 11.9473 4.99467 13.4979C5.01903 15.0485 5.66578 16.5454 6.79264 17.6592C7.9195 18.7731 9.43417 19.4127 11.0034 19.4374C12.5727 19.462 14.068 18.8697 15.1604 17.7907L18.9887 14.0354"></path></svg>
|
|
636
|
-
</div>
|
|
675
|
+
{file_icon}
|
|
637
676
|
</div>
|
|
638
677
|
<div class="cdx-attaches__file-info">
|
|
639
678
|
<div class="cdx-attaches__title" data-placeholder="File title" data-empty="false">
|
|
640
|
-
|
|
679
|
+
{node.get("body", "")}
|
|
641
680
|
</div>
|
|
681
|
+
{file_size}
|
|
642
682
|
</div>
|
|
643
|
-
<a class="cdx-attaches__download-button" href="{node.get('file', '')}" target="_blank" rel="nofollow noindex noreferrer">
|
|
683
|
+
<a class="cdx-attaches__download-button" href="{node.get('file', '')}" target="_blank" rel="nofollow noindex noreferrer" title="{node.get('name', '')}">
|
|
644
684
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M7 10L11.8586 14.8586C11.9367 14.9367 12.0633 14.9367 12.1414 14.8586L17 10"></path></svg>
|
|
645
685
|
</a>
|
|
646
686
|
</div>
|
|
@@ -690,6 +730,41 @@ class AlignmentBlock(EditorJSBlock):
|
|
|
690
730
|
return f"<{tag} style='text-align: {alignment}'>{body}</{tag}>"
|
|
691
731
|
|
|
692
732
|
|
|
733
|
+
@block("embed")
|
|
734
|
+
class EmbedBlock(EditorJSBlock):
|
|
735
|
+
|
|
736
|
+
@classmethod
|
|
737
|
+
def to_markdown(cls, data: EditorChildData) -> str:
|
|
738
|
+
service = data.get("service", "")
|
|
739
|
+
source = data.get("source", "")
|
|
740
|
+
embed = data.get("embed", "")
|
|
741
|
+
caption = data.get("caption", "")
|
|
742
|
+
|
|
743
|
+
return f"<editorjs type='embed' service='{service}' source='{source}' embed='{embed}' caption='{caption}'/>\n\n"
|
|
744
|
+
|
|
745
|
+
@classmethod
|
|
746
|
+
def to_json(cls, node: MDChildNode) -> list[dict]:
|
|
747
|
+
return [{"type": "embed", "data": node}]
|
|
748
|
+
|
|
749
|
+
@classmethod
|
|
750
|
+
def to_text(cls, node: MDChildNode) -> str:
|
|
751
|
+
source = node.get("source", "")
|
|
752
|
+
embed = node.get("embed", "")
|
|
753
|
+
caption = node.get("caption", "")
|
|
754
|
+
return f"""
|
|
755
|
+
<div class="cdx-block embed-tool">
|
|
756
|
+
<preloader class="embed-tool__preloader">
|
|
757
|
+
<div class="embed-tool__url">{source}</div>
|
|
758
|
+
</preloader>
|
|
759
|
+
<iframe style="width:100%;" height="320" frameborder="0" allowfullscreen="" src="{embed}" class="embed-tool__content"></iframe>
|
|
760
|
+
<div class="cdx-input embed-tool__caption" contenteditable="true" data-placeholder="Enter a caption" data-empty="false">{caption}</div>
|
|
761
|
+
</div>
|
|
762
|
+
"""
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
### end blocks
|
|
766
|
+
|
|
767
|
+
|
|
693
768
|
class AttributeParser(HTMLParser):
|
|
694
769
|
def __init__(self):
|
|
695
770
|
super().__init__()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: edwh-editorjs
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.3.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>
|
|
@@ -13,6 +13,7 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.12
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.13
|
|
15
15
|
Requires-Python: >=3.10
|
|
16
|
+
Requires-Dist: humanize
|
|
16
17
|
Requires-Dist: markdown2
|
|
17
18
|
Requires-Dist: mdast
|
|
18
19
|
Provides-Extra: dev
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
editorjs/__about__.py,sha256=
|
|
1
|
+
editorjs/__about__.py,sha256=CpK8IH_dCUAwg9tqv7zm9FxbBFkxCnED1JUiRe7cftU,22
|
|
2
2
|
editorjs/__init__.py,sha256=-OHUf7ZXfkbdFB1r85eIjpHRfql-GCNUCKuBEdEt2Rc,58
|
|
3
|
-
editorjs/blocks.py,sha256=
|
|
3
|
+
editorjs/blocks.py,sha256=WHxlQMLWLzM7EzNOznOUkpr4gmAoBLgoLlRpFIKLZ60,27342
|
|
4
4
|
editorjs/core.py,sha256=WSBmAIKwSqHIP_NFmUVUJiyHPgq7D8902Jm9HRf1nSk,3669
|
|
5
5
|
editorjs/exceptions.py,sha256=TyfHvk2Z5RbKxTDK7lrjgwAgVgInXIuDW63eO5jzVFw,106
|
|
6
6
|
editorjs/helpers.py,sha256=q861o5liNibMTp-Ozay17taF7CTNsRe901lYhhxdwHg,73
|
|
7
7
|
editorjs/types.py,sha256=W7IZWMWgzJaQulybIt0Gx5N63rVj4mEy73VJWo4VAQA,1029
|
|
8
|
-
edwh_editorjs-2.
|
|
9
|
-
edwh_editorjs-2.
|
|
10
|
-
edwh_editorjs-2.
|
|
8
|
+
edwh_editorjs-2.3.0.dist-info/METADATA,sha256=cyn9LNNokE60J1r6eEtstPiAkXACF8b3DbLJMhnk5fY,996
|
|
9
|
+
edwh_editorjs-2.3.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
10
|
+
edwh_editorjs-2.3.0.dist-info/RECORD,,
|
|
File without changes
|