edwh-editorjs 2.5.0a3__py3-none-any.whl → 2.6.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 +46 -34
- {edwh_editorjs-2.5.0a3.dist-info → edwh_editorjs-2.6.0.dist-info}/METADATA +3 -2
- edwh_editorjs-2.6.0.dist-info/RECORD +10 -0
- {edwh_editorjs-2.5.0a3.dist-info → edwh_editorjs-2.6.0.dist-info}/WHEEL +1 -1
- edwh_editorjs-2.5.0a3.dist-info/RECORD +0 -10
editorjs/__about__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "2.
|
|
1
|
+
__version__ = "2.6.0"
|
editorjs/blocks.py
CHANGED
|
@@ -5,15 +5,16 @@ mdast to editorjs
|
|
|
5
5
|
import abc
|
|
6
6
|
import re
|
|
7
7
|
import typing as t
|
|
8
|
-
from html.parser import HTMLParser
|
|
9
8
|
from urllib.parse import urlparse
|
|
10
9
|
|
|
10
|
+
import html2markdown
|
|
11
11
|
import humanize
|
|
12
|
+
import lxml.html
|
|
12
13
|
import markdown2
|
|
13
14
|
|
|
14
15
|
from .exceptions import TODO, Unreachable
|
|
15
16
|
from .types import EditorChildData, MDChildNode
|
|
16
|
-
|
|
17
|
+
|
|
17
18
|
|
|
18
19
|
class EditorJSBlock(abc.ABC):
|
|
19
20
|
@classmethod
|
|
@@ -53,6 +54,7 @@ def process_styled_content(item: MDChildNode, strict: bool = True) -> str:
|
|
|
53
54
|
A formatted HTML string based on the item type.
|
|
54
55
|
"""
|
|
55
56
|
_type = item.get("type")
|
|
57
|
+
|
|
56
58
|
html_wrappers = {
|
|
57
59
|
"text": "{value}",
|
|
58
60
|
"html": "{value}",
|
|
@@ -82,9 +84,16 @@ def process_styled_content(item: MDChildNode, strict: bool = True) -> str:
|
|
|
82
84
|
|
|
83
85
|
|
|
84
86
|
def default_to_text(node: MDChildNode):
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
if node["type"] == "paragraph":
|
|
88
|
+
return "".join(
|
|
89
|
+
process_styled_content(child) for child in node.get("children", [])
|
|
90
|
+
)
|
|
91
|
+
else:
|
|
92
|
+
return process_styled_content(node)
|
|
93
|
+
|
|
94
|
+
# return "".join(
|
|
95
|
+
# process_styled_content(child) for child in node.get("children", [])
|
|
96
|
+
# ) or process_styled_content(node)
|
|
88
97
|
|
|
89
98
|
|
|
90
99
|
@block("heading", "header")
|
|
@@ -248,8 +257,7 @@ class ParagraphBlock(EditorJSBlock):
|
|
|
248
257
|
|
|
249
258
|
@classmethod
|
|
250
259
|
def to_text(cls, node: MDChildNode) -> str:
|
|
251
|
-
return
|
|
252
|
-
# return default_to_text(node)
|
|
260
|
+
return default_to_text(node)
|
|
253
261
|
|
|
254
262
|
|
|
255
263
|
@block("list")
|
|
@@ -388,7 +396,7 @@ class CodeBlock(EditorJSBlock):
|
|
|
388
396
|
@classmethod
|
|
389
397
|
def to_markdown(cls, data: EditorChildData) -> str:
|
|
390
398
|
code = data.get("code", "")
|
|
391
|
-
return f"```\n
|
|
399
|
+
return f"```\n{code}\n```\n"
|
|
392
400
|
|
|
393
401
|
@classmethod
|
|
394
402
|
def to_json(cls, node: MDChildNode) -> list[dict]:
|
|
@@ -447,9 +455,9 @@ class ImageBlock(EditorJSBlock):
|
|
|
447
455
|
border = node.get("border") or ""
|
|
448
456
|
|
|
449
457
|
return f"""
|
|
450
|
-
<div class="ce-block {stretched and
|
|
458
|
+
<div class="ce-block {stretched and "ce-block--stretched"}">
|
|
451
459
|
<div class="ce-block__content">
|
|
452
|
-
<div class="cdx-block image-tool image-tool--filled {background and
|
|
460
|
+
<div class="cdx-block image-tool image-tool--filled {background and "image-tool--withBackground"} {stretched and "image-tool--stretched"} {border and "image-tool--withBorder"}">
|
|
453
461
|
<div class="image-tool__image">
|
|
454
462
|
<figure>
|
|
455
463
|
<img class="image-tool__image-picture" src="{url}" title="{caption}" alt="{caption}">
|
|
@@ -471,7 +479,7 @@ class QuoteBlock(EditorJSBlock):
|
|
|
471
479
|
result = f"> {text}\n"
|
|
472
480
|
if caption := data.get("caption", ""):
|
|
473
481
|
result += f"> <cite>{caption}</cite>\n"
|
|
474
|
-
return result
|
|
482
|
+
return result + "\n"
|
|
475
483
|
|
|
476
484
|
@classmethod
|
|
477
485
|
def to_json(cls, node: MDChildNode) -> list[dict]:
|
|
@@ -497,12 +505,13 @@ class QuoteBlock(EditorJSBlock):
|
|
|
497
505
|
|
|
498
506
|
@classmethod
|
|
499
507
|
def to_text(cls, node: MDChildNode) -> str:
|
|
500
|
-
return
|
|
508
|
+
return "".join(
|
|
509
|
+
process_styled_content(child) for child in node.get("children", [])
|
|
510
|
+
)
|
|
501
511
|
|
|
502
512
|
|
|
503
513
|
@block("raw", "html")
|
|
504
514
|
class RawBlock(EditorJSBlock):
|
|
505
|
-
|
|
506
515
|
@classmethod
|
|
507
516
|
def to_markdown(cls, data: EditorChildData) -> str:
|
|
508
517
|
text = data.get("html", "")
|
|
@@ -525,7 +534,6 @@ class RawBlock(EditorJSBlock):
|
|
|
525
534
|
|
|
526
535
|
@block("table")
|
|
527
536
|
class TableBlock(EditorJSBlock):
|
|
528
|
-
|
|
529
537
|
@classmethod
|
|
530
538
|
def to_markdown(cls, data: EditorChildData) -> str:
|
|
531
539
|
"""
|
|
@@ -644,7 +652,6 @@ class LinkBlock(EditorJSBlock):
|
|
|
644
652
|
|
|
645
653
|
@block("attaches")
|
|
646
654
|
class AttachmentBlock(EditorJSBlock):
|
|
647
|
-
|
|
648
655
|
@classmethod
|
|
649
656
|
def to_markdown(cls, data: EditorChildData) -> str:
|
|
650
657
|
title = data.get("title", "")
|
|
@@ -709,7 +716,7 @@ class AttachmentBlock(EditorJSBlock):
|
|
|
709
716
|
</div>
|
|
710
717
|
{file_size}
|
|
711
718
|
</div>
|
|
712
|
-
<a class="cdx-attaches__download-button" href="{node.get(
|
|
719
|
+
<a class="cdx-attaches__download-button" href="{node.get("file", "")}" target="_blank" rel="nofollow noindex noreferrer" title="{node.get("name", "")}">
|
|
713
720
|
<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>
|
|
714
721
|
</a>
|
|
715
722
|
</div>
|
|
@@ -761,7 +768,6 @@ class AlignmentBlock(EditorJSBlock):
|
|
|
761
768
|
|
|
762
769
|
@block("embed")
|
|
763
770
|
class EmbedBlock(EditorJSBlock):
|
|
764
|
-
|
|
765
771
|
@classmethod
|
|
766
772
|
def to_markdown(cls, data: EditorChildData) -> str:
|
|
767
773
|
service = data.get("service", "")
|
|
@@ -790,20 +796,6 @@ class EmbedBlock(EditorJSBlock):
|
|
|
790
796
|
### end blocks
|
|
791
797
|
|
|
792
798
|
|
|
793
|
-
class AttributeParser(HTMLParser):
|
|
794
|
-
def __init__(self):
|
|
795
|
-
super().__init__()
|
|
796
|
-
self.attributes = {}
|
|
797
|
-
self.data = None
|
|
798
|
-
|
|
799
|
-
def handle_starttag(self, tag, attrs):
|
|
800
|
-
# Collect attributes when the tag is encountered
|
|
801
|
-
self.attributes = dict(attrs)
|
|
802
|
-
|
|
803
|
-
def handle_data(self, data):
|
|
804
|
-
self.data = data
|
|
805
|
-
|
|
806
|
-
|
|
807
799
|
class EditorJSCustom(EditorJSBlock, markdown2.Extra):
|
|
808
800
|
"""
|
|
809
801
|
Special type of block to deal with custom attributes.
|
|
@@ -816,10 +808,29 @@ class EditorJSCustom(EditorJSBlock, markdown2.Extra):
|
|
|
816
808
|
|
|
817
809
|
@classmethod
|
|
818
810
|
def parse_html(cls, html: str):
|
|
819
|
-
|
|
820
|
-
|
|
811
|
+
"""
|
|
812
|
+
Extract attributes from the outermost HTML element and return its inner HTML.
|
|
813
|
+
|
|
814
|
+
This function parses the provided markup, identifies the root element,
|
|
815
|
+
returns its attributes as a dictionary, and serializes all direct child
|
|
816
|
+
nodes back into an HTML string.
|
|
817
|
+
|
|
818
|
+
Args:
|
|
819
|
+
html: A string containing a single root HTML element.
|
|
820
|
+
|
|
821
|
+
Returns:
|
|
822
|
+
A tuple of:
|
|
823
|
+
- dict[str, str]: Attributes of the root element
|
|
824
|
+
- str: Inner HTML of the root element
|
|
825
|
+
"""
|
|
826
|
+
root = lxml.html.fromstring(html)
|
|
827
|
+
|
|
828
|
+
attributes = dict(root.attrib)
|
|
829
|
+
inner_html = "".join(
|
|
830
|
+
lxml.html.tostring(child, encoding="unicode") for child in root
|
|
831
|
+
)
|
|
821
832
|
|
|
822
|
-
return
|
|
833
|
+
return attributes, inner_html
|
|
823
834
|
|
|
824
835
|
@classmethod
|
|
825
836
|
def to_markdown(cls, data: EditorChildData) -> str:
|
|
@@ -834,6 +845,7 @@ class EditorJSCustom(EditorJSBlock, markdown2.Extra):
|
|
|
834
845
|
handler = BLOCKS.get(_type)
|
|
835
846
|
|
|
836
847
|
if not handler:
|
|
848
|
+
raise ValueError(f"debug: {attrs = } {body = }") # fixme
|
|
837
849
|
raise ValueError(f"Unknown custom type {_type}")
|
|
838
850
|
|
|
839
851
|
return handler, attrs
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: edwh-editorjs
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.6.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>
|
|
@@ -15,6 +15,7 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
15
15
|
Requires-Python: >=3.10
|
|
16
16
|
Requires-Dist: html2markdown
|
|
17
17
|
Requires-Dist: humanize
|
|
18
|
+
Requires-Dist: lxml
|
|
18
19
|
Requires-Dist: markdown2
|
|
19
20
|
Requires-Dist: mdast
|
|
20
21
|
Provides-Extra: dev
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
editorjs/__about__.py,sha256=OEib63e0yPEGlhEXyrWE1OwRnleR0cHI7KSX7oZEQLs,22
|
|
2
|
+
editorjs/__init__.py,sha256=-OHUf7ZXfkbdFB1r85eIjpHRfql-GCNUCKuBEdEt2Rc,58
|
|
3
|
+
editorjs/blocks.py,sha256=QWua1EMZ1dnaIMHw_nY1T4FjNsvCdpa_uVqZsdxdFqk,29454
|
|
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.6.0.dist-info/METADATA,sha256=a_7OrfF1yVNADyKGr03a9H7ek_coxp3decstPniHbSM,1045
|
|
9
|
+
edwh_editorjs-2.6.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
10
|
+
edwh_editorjs-2.6.0.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
editorjs/__about__.py,sha256=_Fi21vxW1-XrA5cHGBb0PFyoSSWodIDwtSp_YSMc2l8,24
|
|
2
|
-
editorjs/__init__.py,sha256=-OHUf7ZXfkbdFB1r85eIjpHRfql-GCNUCKuBEdEt2Rc,58
|
|
3
|
-
editorjs/blocks.py,sha256=g8doq2Fykv78Z8Vytgz5IT0cdhTDvadaSDUTAq97iRA,28822
|
|
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.0a3.dist-info/METADATA,sha256=6uJqNbhmqS6w0Y50xPOCA1J2lVJUDvOvs6yNDsY7tSE,1027
|
|
9
|
-
edwh_editorjs-2.5.0a3.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
10
|
-
edwh_editorjs-2.5.0a3.dist-info/RECORD,,
|