edwh-editorjs 2.1.1__py3-none-any.whl → 2.2.1__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 +73 -0
- editorjs/core.py +8 -2
- {edwh_editorjs-2.1.1.dist-info → edwh_editorjs-2.2.1.dist-info}/METADATA +1 -1
- edwh_editorjs-2.2.1.dist-info/RECORD +10 -0
- edwh_editorjs-2.1.1.dist-info/RECORD +0 -10
- {edwh_editorjs-2.1.1.dist-info → edwh_editorjs-2.2.1.dist-info}/WHEEL +0 -0
editorjs/__about__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "2.
|
|
1
|
+
__version__ = "2.2.1"
|
editorjs/blocks.py
CHANGED
|
@@ -93,10 +93,25 @@ class HeadingBlock(EditorJSBlock):
|
|
|
93
93
|
def to_markdown(cls, data: EditorChildData) -> str:
|
|
94
94
|
level = data.get("level", 1)
|
|
95
95
|
text = data.get("text", "")
|
|
96
|
+
tunes = data.get("tunes", {})
|
|
96
97
|
|
|
97
98
|
if not (1 <= level <= 6):
|
|
98
99
|
raise ValueError("Header level must be between 1 and 6.")
|
|
99
100
|
|
|
101
|
+
if (
|
|
102
|
+
tunes.get("alignmentTune")
|
|
103
|
+
and (alignment := tunes["alignmentTune"].get("alignment"))
|
|
104
|
+
and (alignment != "left")
|
|
105
|
+
):
|
|
106
|
+
# can't just return regular HTML because then it will turn into a raw block
|
|
107
|
+
return AlignmentBlock.to_markdown(
|
|
108
|
+
{
|
|
109
|
+
"text": text,
|
|
110
|
+
"tag": f"h{level}",
|
|
111
|
+
"alignment": alignment,
|
|
112
|
+
}
|
|
113
|
+
)
|
|
114
|
+
|
|
100
115
|
return f"{'#' * level} {text}\n"
|
|
101
116
|
|
|
102
117
|
@classmethod
|
|
@@ -143,6 +158,21 @@ class ParagraphBlock(EditorJSBlock):
|
|
|
143
158
|
@classmethod
|
|
144
159
|
def to_markdown(cls, data: EditorChildData) -> str:
|
|
145
160
|
text = data.get("text", "")
|
|
161
|
+
tunes = data.get("tunes", {})
|
|
162
|
+
|
|
163
|
+
if (
|
|
164
|
+
tunes.get("alignmentTune")
|
|
165
|
+
and (alignment := tunes["alignmentTune"].get("alignment"))
|
|
166
|
+
and (alignment != "left")
|
|
167
|
+
):
|
|
168
|
+
return AlignmentBlock.to_markdown(
|
|
169
|
+
{
|
|
170
|
+
"text": text,
|
|
171
|
+
"tag": "p",
|
|
172
|
+
"alignment": alignment,
|
|
173
|
+
}
|
|
174
|
+
)
|
|
175
|
+
|
|
146
176
|
return f"{text}\n\n"
|
|
147
177
|
|
|
148
178
|
@classmethod
|
|
@@ -617,6 +647,49 @@ class AttachmentBlock(EditorJSBlock):
|
|
|
617
647
|
"""
|
|
618
648
|
|
|
619
649
|
|
|
650
|
+
@block("alignment")
|
|
651
|
+
class AlignmentBlock(EditorJSBlock):
|
|
652
|
+
@classmethod
|
|
653
|
+
def to_markdown(cls, data: EditorChildData) -> str:
|
|
654
|
+
tag = data["tag"]
|
|
655
|
+
alignment = data["alignment"]
|
|
656
|
+
content = data["text"]
|
|
657
|
+
|
|
658
|
+
return f"<editorjs type='alignment' tag='{tag}' alignment='{alignment}'>{content}</editorjs>\n\n"
|
|
659
|
+
|
|
660
|
+
@classmethod
|
|
661
|
+
def to_json(cls, node: MDChildNode) -> list[dict]:
|
|
662
|
+
# only paragraph and headers can be aligned
|
|
663
|
+
tag: str = node["tag"]
|
|
664
|
+
text: str = node["body"]
|
|
665
|
+
alignment = node["alignment"]
|
|
666
|
+
data = {"text": text}
|
|
667
|
+
|
|
668
|
+
if tag == "p":
|
|
669
|
+
_type = "paragraph"
|
|
670
|
+
elif tag.startswith("h"):
|
|
671
|
+
_type = "header"
|
|
672
|
+
data["level"] = int(tag.removeprefix("h"))
|
|
673
|
+
else:
|
|
674
|
+
# doesn't support alignment
|
|
675
|
+
raise TODO(f"Unsupported tag for alignment: {tag}")
|
|
676
|
+
|
|
677
|
+
return [
|
|
678
|
+
{
|
|
679
|
+
"type": _type,
|
|
680
|
+
"data": data,
|
|
681
|
+
"tunes": {"alignmentTune": {"alignment": alignment}},
|
|
682
|
+
}
|
|
683
|
+
]
|
|
684
|
+
|
|
685
|
+
@classmethod
|
|
686
|
+
def to_text(cls, node: MDChildNode) -> str:
|
|
687
|
+
tag = node["tag"]
|
|
688
|
+
body = node["body"]
|
|
689
|
+
alignment = node["alignment"]
|
|
690
|
+
return f"<{tag} style='text-align: {alignment}'>{body}</{tag}>"
|
|
691
|
+
|
|
692
|
+
|
|
620
693
|
class AttributeParser(HTMLParser):
|
|
621
694
|
def __init__(self):
|
|
622
695
|
super().__init__()
|
editorjs/core.py
CHANGED
|
@@ -43,7 +43,11 @@ class EditorJS:
|
|
|
43
43
|
if not (block := BLOCKS.get(_type)):
|
|
44
44
|
raise TypeError(f"Unsupported block type `{_type}`")
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
data = child.get("data", {})
|
|
47
|
+
# forward any 'tunes' via data:
|
|
48
|
+
data["tunes"] = data.get("tunes") or child.get("tunes") or {}
|
|
49
|
+
|
|
50
|
+
markdown_items.append(block.to_markdown(data))
|
|
47
51
|
|
|
48
52
|
markdown = "".join(markdown_items)
|
|
49
53
|
return cls.from_markdown(markdown)
|
|
@@ -88,7 +92,9 @@ class EditorJS:
|
|
|
88
92
|
# idk why this happens:
|
|
89
93
|
md = md.replace(r"\[ ]", "[ ]")
|
|
90
94
|
md = md.replace(r"\[x]", "[x]")
|
|
91
|
-
return md
|
|
95
|
+
return md.replace(
|
|
96
|
+
" <", " <"
|
|
97
|
+
) # replace double space (added by mdast) with single one
|
|
92
98
|
|
|
93
99
|
def to_mdast(self) -> str:
|
|
94
100
|
"""
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: edwh-editorjs
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.1
|
|
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=4dqvKTDgbqeyzbWj6hYiNdzxsI8j1YOKSLM8vF6a0j4,22
|
|
2
|
+
editorjs/__init__.py,sha256=-OHUf7ZXfkbdFB1r85eIjpHRfql-GCNUCKuBEdEt2Rc,58
|
|
3
|
+
editorjs/blocks.py,sha256=p5vPOM-YGbx_UL8b2pA2tXXmCrTMn4K-UaeUdsiZp5A,24528
|
|
4
|
+
editorjs/core.py,sha256=FtdPWeY05PWOQ2JY1rPdZdnXL5g_LrrCfRy0HfjkXqM,3649
|
|
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.2.1.dist-info/METADATA,sha256=S_ulJgMQGRsEbnCziWID8qMF1gp74brQiuJWGc9hjQ8,972
|
|
9
|
+
edwh_editorjs-2.2.1.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
10
|
+
edwh_editorjs-2.2.1.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
editorjs/__about__.py,sha256=zPJIgPGcoSNiD0qme18OnYJYE3A9VVytlhO-V5DaAW0,22
|
|
2
|
-
editorjs/__init__.py,sha256=-OHUf7ZXfkbdFB1r85eIjpHRfql-GCNUCKuBEdEt2Rc,58
|
|
3
|
-
editorjs/blocks.py,sha256=x6qWTsxT_NUciF3-mKIk7ylu_6ponb27iUnB91N1UMg,22295
|
|
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.1.dist-info/METADATA,sha256=0CpDziqphQngdwM3sy_6WCLRSAcA38NAlmajdGEiPJs,972
|
|
9
|
-
edwh_editorjs-2.1.1.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
10
|
-
edwh_editorjs-2.1.1.dist-info/RECORD,,
|
|
File without changes
|