edwh-editorjs 2.5.0a4__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 +36 -36
- editorjs/core.py +0 -2
- {edwh_editorjs-2.5.0a4.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.0a4.dist-info → edwh_editorjs-2.6.0.dist-info}/WHEEL +1 -1
- edwh_editorjs-2.5.0a4.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,15 @@ 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
|
-
import html2markdown
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
class EditorJSBlock(abc.ABC):
|
|
@@ -55,8 +55,6 @@ def process_styled_content(item: MDChildNode, strict: bool = True) -> str:
|
|
|
55
55
|
"""
|
|
56
56
|
_type = item.get("type")
|
|
57
57
|
|
|
58
|
-
print('process_styled_content', _type)
|
|
59
|
-
|
|
60
58
|
html_wrappers = {
|
|
61
59
|
"text": "{value}",
|
|
62
60
|
"html": "{value}",
|
|
@@ -110,9 +108,9 @@ class HeadingBlock(EditorJSBlock):
|
|
|
110
108
|
raise ValueError("Header level must be between 1 and 6.")
|
|
111
109
|
|
|
112
110
|
if (
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
tunes.get("alignmentTune")
|
|
112
|
+
and (alignment := tunes["alignmentTune"].get("alignment"))
|
|
113
|
+
and (alignment != "left")
|
|
116
114
|
):
|
|
117
115
|
# can't just return regular HTML because then it will turn into a raw block
|
|
118
116
|
return AlignmentBlock.to_markdown(
|
|
@@ -172,9 +170,9 @@ class ParagraphBlock(EditorJSBlock):
|
|
|
172
170
|
tunes = data.get("tunes", {})
|
|
173
171
|
|
|
174
172
|
if (
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
173
|
+
tunes.get("alignmentTune")
|
|
174
|
+
and (alignment := tunes["alignmentTune"].get("alignment"))
|
|
175
|
+
and (alignment != "left")
|
|
178
176
|
):
|
|
179
177
|
return AlignmentBlock.to_markdown(
|
|
180
178
|
{
|
|
@@ -216,7 +214,7 @@ class ParagraphBlock(EditorJSBlock):
|
|
|
216
214
|
else:
|
|
217
215
|
# <editorjs>something</editorjs> = 3 children
|
|
218
216
|
result.extend(
|
|
219
|
-
EditorJSCustom.to_json({"children": nodes[idx: idx + 2]})
|
|
217
|
+
EditorJSCustom.to_json({"children": nodes[idx : idx + 2]})
|
|
220
218
|
)
|
|
221
219
|
|
|
222
220
|
skip = 2
|
|
@@ -398,7 +396,7 @@ class CodeBlock(EditorJSBlock):
|
|
|
398
396
|
@classmethod
|
|
399
397
|
def to_markdown(cls, data: EditorChildData) -> str:
|
|
400
398
|
code = data.get("code", "")
|
|
401
|
-
return f"```\n
|
|
399
|
+
return f"```\n{code}\n```\n"
|
|
402
400
|
|
|
403
401
|
@classmethod
|
|
404
402
|
def to_json(cls, node: MDChildNode) -> list[dict]:
|
|
@@ -457,9 +455,9 @@ class ImageBlock(EditorJSBlock):
|
|
|
457
455
|
border = node.get("border") or ""
|
|
458
456
|
|
|
459
457
|
return f"""
|
|
460
|
-
<div class="ce-block {stretched and
|
|
458
|
+
<div class="ce-block {stretched and "ce-block--stretched"}">
|
|
461
459
|
<div class="ce-block__content">
|
|
462
|
-
<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"}">
|
|
463
461
|
<div class="image-tool__image">
|
|
464
462
|
<figure>
|
|
465
463
|
<img class="image-tool__image-picture" src="{url}" title="{caption}" alt="{caption}">
|
|
@@ -514,7 +512,6 @@ class QuoteBlock(EditorJSBlock):
|
|
|
514
512
|
|
|
515
513
|
@block("raw", "html")
|
|
516
514
|
class RawBlock(EditorJSBlock):
|
|
517
|
-
|
|
518
515
|
@classmethod
|
|
519
516
|
def to_markdown(cls, data: EditorChildData) -> str:
|
|
520
517
|
text = data.get("html", "")
|
|
@@ -537,7 +534,6 @@ class RawBlock(EditorJSBlock):
|
|
|
537
534
|
|
|
538
535
|
@block("table")
|
|
539
536
|
class TableBlock(EditorJSBlock):
|
|
540
|
-
|
|
541
537
|
@classmethod
|
|
542
538
|
def to_markdown(cls, data: EditorChildData) -> str:
|
|
543
539
|
"""
|
|
@@ -656,7 +652,6 @@ class LinkBlock(EditorJSBlock):
|
|
|
656
652
|
|
|
657
653
|
@block("attaches")
|
|
658
654
|
class AttachmentBlock(EditorJSBlock):
|
|
659
|
-
|
|
660
655
|
@classmethod
|
|
661
656
|
def to_markdown(cls, data: EditorChildData) -> str:
|
|
662
657
|
title = data.get("title", "")
|
|
@@ -721,7 +716,7 @@ class AttachmentBlock(EditorJSBlock):
|
|
|
721
716
|
</div>
|
|
722
717
|
{file_size}
|
|
723
718
|
</div>
|
|
724
|
-
<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", "")}">
|
|
725
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>
|
|
726
721
|
</a>
|
|
727
722
|
</div>
|
|
@@ -773,7 +768,6 @@ class AlignmentBlock(EditorJSBlock):
|
|
|
773
768
|
|
|
774
769
|
@block("embed")
|
|
775
770
|
class EmbedBlock(EditorJSBlock):
|
|
776
|
-
|
|
777
771
|
@classmethod
|
|
778
772
|
def to_markdown(cls, data: EditorChildData) -> str:
|
|
779
773
|
service = data.get("service", "")
|
|
@@ -802,20 +796,6 @@ class EmbedBlock(EditorJSBlock):
|
|
|
802
796
|
### end blocks
|
|
803
797
|
|
|
804
798
|
|
|
805
|
-
class AttributeParser(HTMLParser):
|
|
806
|
-
def __init__(self):
|
|
807
|
-
super().__init__()
|
|
808
|
-
self.attributes = {}
|
|
809
|
-
self.data = None
|
|
810
|
-
|
|
811
|
-
def handle_starttag(self, tag, attrs):
|
|
812
|
-
# Collect attributes when the tag is encountered
|
|
813
|
-
self.attributes = dict(attrs)
|
|
814
|
-
|
|
815
|
-
def handle_data(self, data):
|
|
816
|
-
self.data = data
|
|
817
|
-
|
|
818
|
-
|
|
819
799
|
class EditorJSCustom(EditorJSBlock, markdown2.Extra):
|
|
820
800
|
"""
|
|
821
801
|
Special type of block to deal with custom attributes.
|
|
@@ -828,10 +808,29 @@ class EditorJSCustom(EditorJSBlock, markdown2.Extra):
|
|
|
828
808
|
|
|
829
809
|
@classmethod
|
|
830
810
|
def parse_html(cls, html: str):
|
|
831
|
-
|
|
832
|
-
|
|
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
|
+
)
|
|
833
832
|
|
|
834
|
-
return
|
|
833
|
+
return attributes, inner_html
|
|
835
834
|
|
|
836
835
|
@classmethod
|
|
837
836
|
def to_markdown(cls, data: EditorChildData) -> str:
|
|
@@ -846,6 +845,7 @@ class EditorJSCustom(EditorJSBlock, markdown2.Extra):
|
|
|
846
845
|
handler = BLOCKS.get(_type)
|
|
847
846
|
|
|
848
847
|
if not handler:
|
|
848
|
+
raise ValueError(f"debug: {attrs = } {body = }") # fixme
|
|
849
849
|
raise ValueError(f"Unknown custom type {_type}")
|
|
850
850
|
|
|
851
851
|
return handler, attrs
|
editorjs/core.py
CHANGED
|
@@ -100,13 +100,11 @@ class EditorJS:
|
|
|
100
100
|
try:
|
|
101
101
|
blocks.extend(block.to_json(child))
|
|
102
102
|
except Exception as e:
|
|
103
|
-
|
|
104
103
|
warnings.warn(
|
|
105
104
|
"to_json: Oh oh, unexpected block failure!",
|
|
106
105
|
category=RuntimeWarning,
|
|
107
106
|
source=e,
|
|
108
107
|
)
|
|
109
|
-
raise e
|
|
110
108
|
# if isinstance(e, TODO):
|
|
111
109
|
# raise e
|
|
112
110
|
|
|
@@ -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=NsEXgGmZNz_m0FN93bP4ym1D0nmcEnCsVmXyWVDMaGI,24
|
|
2
|
-
editorjs/__init__.py,sha256=-OHUf7ZXfkbdFB1r85eIjpHRfql-GCNUCKuBEdEt2Rc,58
|
|
3
|
-
editorjs/blocks.py,sha256=Iq6JzxoD5a00ud3KsaUFacBD-zDf9wu1FL5ipxJI_h8,29140
|
|
4
|
-
editorjs/core.py,sha256=9qYmKHr-Wp8TqmMQNfmk0ZCgeARPo0QRS1IV_sLPRag,4535
|
|
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.0a4.dist-info/METADATA,sha256=iIPI5nHDiIjmqlXj3yhPe3AiEpIzGoIgxCGFr8oc3nk,1027
|
|
9
|
-
edwh_editorjs-2.5.0a4.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
10
|
-
edwh_editorjs-2.5.0a4.dist-info/RECORD,,
|