edwh-editorjs 2.0.0__py3-none-any.whl → 2.0.0b1__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.
- edwh_editorjs-2.0.0b1.dist-info/METADATA +104 -0
- edwh_editorjs-2.0.0b1.dist-info/RECORD +9 -0
- {edwh_editorjs-2.0.0.dist-info → edwh_editorjs-2.0.0b1.dist-info}/licenses/LICENSE +0 -1
- pyeditorjs/__about__.py +1 -0
- pyeditorjs/__init__.py +30 -0
- pyeditorjs/blocks.py +313 -0
- pyeditorjs/exceptions.py +19 -0
- pyeditorjs/parser.py +75 -0
- editorjs/__about__.py +0 -1
- editorjs/__init__.py +0 -5
- editorjs/blocks.py +0 -670
- editorjs/core.py +0 -119
- editorjs/exceptions.py +0 -3
- editorjs/helpers.py +0 -5
- editorjs/types.py +0 -43
- edwh_editorjs-2.0.0.dist-info/METADATA +0 -28
- edwh_editorjs-2.0.0.dist-info/RECORD +0 -11
- {edwh_editorjs-2.0.0.dist-info → edwh_editorjs-2.0.0b1.dist-info}/WHEEL +0 -0
editorjs/core.py
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import typing as t
|
|
3
|
-
|
|
4
|
-
import markdown2
|
|
5
|
-
import mdast
|
|
6
|
-
from typing_extensions import Self
|
|
7
|
-
|
|
8
|
-
from .blocks import BLOCKS
|
|
9
|
-
from .helpers import unix_timestamp
|
|
10
|
-
from .types import MDRootNode
|
|
11
|
-
|
|
12
|
-
EDITORJS_VERSION = "2.30.6"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class EditorJS:
|
|
16
|
-
# internal representation is mdast, because we can convert to other types
|
|
17
|
-
_mdast: MDRootNode
|
|
18
|
-
|
|
19
|
-
def __init__(
|
|
20
|
-
self,
|
|
21
|
-
_mdast: str | dict,
|
|
22
|
-
extras: list = ("task_list", "fenced-code-blocks", "tables", "editorjs"),
|
|
23
|
-
):
|
|
24
|
-
if not isinstance(_mdast, str | dict):
|
|
25
|
-
raise TypeError("Only `str` or `dict` is supported!")
|
|
26
|
-
|
|
27
|
-
self._mdast = t.cast(
|
|
28
|
-
MDRootNode, json.loads(_mdast) if isinstance(_mdast, str) else _mdast
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
self._md = markdown2.Markdown(extras=extras) # todo: striketrough, ?
|
|
32
|
-
|
|
33
|
-
@classmethod
|
|
34
|
-
def from_json(cls, data: str | dict) -> Self:
|
|
35
|
-
"""
|
|
36
|
-
Load from EditorJS JSON Blocks
|
|
37
|
-
"""
|
|
38
|
-
data = data if isinstance(data, dict) else json.loads(data)
|
|
39
|
-
markdown_items = []
|
|
40
|
-
for child in data["blocks"]:
|
|
41
|
-
_type = child["type"]
|
|
42
|
-
if not (block := BLOCKS.get(_type)):
|
|
43
|
-
raise TypeError(f"Unsupported block type `{_type}`")
|
|
44
|
-
|
|
45
|
-
markdown_items.append(block.to_markdown(child.get("data", {})))
|
|
46
|
-
|
|
47
|
-
markdown = "".join(markdown_items)
|
|
48
|
-
return cls.from_markdown(markdown)
|
|
49
|
-
|
|
50
|
-
@classmethod
|
|
51
|
-
def from_markdown(cls, data: str) -> Self:
|
|
52
|
-
"""
|
|
53
|
-
Load from markdown string
|
|
54
|
-
"""
|
|
55
|
-
|
|
56
|
-
return cls(mdast.md_to_json(data))
|
|
57
|
-
|
|
58
|
-
@classmethod
|
|
59
|
-
def from_mdast(cls, data: str | dict) -> Self:
|
|
60
|
-
"""
|
|
61
|
-
Existing mdast representation
|
|
62
|
-
"""
|
|
63
|
-
return cls(data)
|
|
64
|
-
|
|
65
|
-
def to_json(self) -> str:
|
|
66
|
-
"""
|
|
67
|
-
Export EditorJS JSON Blocks
|
|
68
|
-
"""
|
|
69
|
-
# logic based on https://github.com/carrara88/editorjs-md-parser/blob/main/src/MarkdownImporter.js
|
|
70
|
-
blocks = []
|
|
71
|
-
for child in self._mdast["children"]:
|
|
72
|
-
_type = child["type"]
|
|
73
|
-
if not (block := BLOCKS.get(_type)):
|
|
74
|
-
raise TypeError(f"Unsupported block type `{_type}`")
|
|
75
|
-
|
|
76
|
-
blocks.extend(block.to_json(child))
|
|
77
|
-
|
|
78
|
-
data = {"time": unix_timestamp(), "blocks": blocks, "version": EDITORJS_VERSION}
|
|
79
|
-
|
|
80
|
-
return json.dumps(data)
|
|
81
|
-
|
|
82
|
-
def to_markdown(self) -> str:
|
|
83
|
-
"""
|
|
84
|
-
Export Markdown string
|
|
85
|
-
"""
|
|
86
|
-
md = mdast.json_to_md(self.to_mdast())
|
|
87
|
-
# idk why this happens:
|
|
88
|
-
md = md.replace(r"\[ ]", "[ ]")
|
|
89
|
-
md = md.replace(r"\[x]", "[x]")
|
|
90
|
-
return md
|
|
91
|
-
|
|
92
|
-
def to_mdast(self) -> str:
|
|
93
|
-
"""
|
|
94
|
-
Export mdast representation
|
|
95
|
-
"""
|
|
96
|
-
return json.dumps(self._mdast)
|
|
97
|
-
|
|
98
|
-
def to_html(self) -> str:
|
|
99
|
-
"""
|
|
100
|
-
Export HTML string
|
|
101
|
-
"""
|
|
102
|
-
md = self.to_markdown()
|
|
103
|
-
# todo: deal with custom elements like linktool, attaches
|
|
104
|
-
return self._md.convert(md)
|
|
105
|
-
|
|
106
|
-
def __repr__(self):
|
|
107
|
-
md = self.to_markdown()
|
|
108
|
-
md = md.replace("\n", "\\n")
|
|
109
|
-
return f"EditorJS({md})"
|
|
110
|
-
|
|
111
|
-
def __str__(self):
|
|
112
|
-
return self.to_markdown()
|
|
113
|
-
|
|
114
|
-
# def __eq__(self, other: Self) -> bool:
|
|
115
|
-
# a = self.to_markdown()
|
|
116
|
-
# b = other.to_markdown()
|
|
117
|
-
#
|
|
118
|
-
# remove = string.punctuation + string.whitespace
|
|
119
|
-
# return a.translate(remove) == b.translate(remove)
|
editorjs/exceptions.py
DELETED
editorjs/helpers.py
DELETED
editorjs/types.py
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import typing as t
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class MDPosition(t.TypedDict):
|
|
5
|
-
line: int
|
|
6
|
-
column: int
|
|
7
|
-
offset: int
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class MDPositionRange(t.TypedDict):
|
|
11
|
-
start: MDPosition
|
|
12
|
-
end: MDPosition
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class MDChildNode(t.TypedDict, total=False):
|
|
16
|
-
type: str # General identifier for node types
|
|
17
|
-
children: list["MDChildNode"] # Recursive children of any node type
|
|
18
|
-
position: MDPositionRange
|
|
19
|
-
value: str # Optional, for nodes like text that hold a value
|
|
20
|
-
depth: int # Optional, for nodes like headings that have a depth
|
|
21
|
-
url: t.NotRequired[str]
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class MDRootNode(t.TypedDict):
|
|
25
|
-
type: t.Literal["root"] # Constrains to 'root' for the root node
|
|
26
|
-
children: list[MDChildNode] # Allows any ChildNode type in children
|
|
27
|
-
position: MDPositionRange
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class EditorChildData(t.TypedDict, total=False):
|
|
31
|
-
text: str
|
|
32
|
-
items: list["EditorChildNode"]
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
class EditorChildNode(t.TypedDict):
|
|
36
|
-
type: str
|
|
37
|
-
data: EditorChildData
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
class EditorRootNode(t.TypedDict):
|
|
41
|
-
time: int
|
|
42
|
-
blocks: list[EditorChildNode]
|
|
43
|
-
version: str
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.3
|
|
2
|
-
Name: edwh-editorjs
|
|
3
|
-
Version: 2.0.0
|
|
4
|
-
Summary: EditorJS.py
|
|
5
|
-
Project-URL: Homepage, https://github.com/educationwarehouse/edwh-EditorJS
|
|
6
|
-
Author-email: SKevo <skevo.cw@gmail.com>, Robin van der Noord <robin.vdn@educationwarehouse.nl>
|
|
7
|
-
License: MIT
|
|
8
|
-
License-File: LICENSE
|
|
9
|
-
Keywords: bleach,clean,editor,editor.js,html,javascript,json,parser,wysiwyg
|
|
10
|
-
Classifier: Development Status :: 4 - Beta
|
|
11
|
-
Classifier: Intended Audience :: Developers
|
|
12
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
-
Requires-Python: >=3.10
|
|
18
|
-
Requires-Dist: markdown2
|
|
19
|
-
Requires-Dist: mdast
|
|
20
|
-
Provides-Extra: dev
|
|
21
|
-
Requires-Dist: edwh; extra == 'dev'
|
|
22
|
-
Requires-Dist: hatch; extra == 'dev'
|
|
23
|
-
Requires-Dist: su6[all]; extra == 'dev'
|
|
24
|
-
Requires-Dist: types-bleach; extra == 'dev'
|
|
25
|
-
Description-Content-Type: text/markdown
|
|
26
|
-
|
|
27
|
-
# edwh-editorjs
|
|
28
|
-
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
editorjs/__about__.py,sha256=_7OlQdbVkK4jad0CLdpI0grT-zEAb-qgFmH5mFzDXiA,22
|
|
2
|
-
editorjs/__init__.py,sha256=-OHUf7ZXfkbdFB1r85eIjpHRfql-GCNUCKuBEdEt2Rc,58
|
|
3
|
-
editorjs/blocks.py,sha256=CTZPKIxjRQy1R1LPrqpB9NTvhSeSjekcMls6QAPdDoI,21664
|
|
4
|
-
editorjs/core.py,sha256=CdZnprX-vkjFJATxPfG1acDqGKkHa3mDfbMEeXiR6eI,3331
|
|
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.0.0.dist-info/METADATA,sha256=WnNAx-XckoOeSuXbNdJQHs2zto0xSeN1g3yPXXZ8T34,1007
|
|
9
|
-
edwh_editorjs-2.0.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
10
|
-
edwh_editorjs-2.0.0.dist-info/licenses/LICENSE,sha256=zzllbk0pvnmgzk31iq8Zkg0GkA8vVx_Zc3OHjVlTjxo,1101
|
|
11
|
-
edwh_editorjs-2.0.0.dist-info/RECORD,,
|
|
File without changes
|