edwh-editorjs 1.0.1__py3-none-any.whl → 2.0.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/core.py ADDED
@@ -0,0 +1,119 @@
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 ADDED
@@ -0,0 +1,3 @@
1
+ class TODO(NotImplementedError):
2
+ def __init__(self, msg: str = "todo"):
3
+ super().__init__(msg)
editorjs/helpers.py ADDED
@@ -0,0 +1,5 @@
1
+ import time
2
+
3
+
4
+ def unix_timestamp():
5
+ return round(time.time() * 1000)
editorjs/types.py ADDED
@@ -0,0 +1,43 @@
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
@@ -0,0 +1,28 @@
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
+
@@ -0,0 +1,11 @@
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,,
@@ -1,6 +1,7 @@
1
1
  MIT License
2
2
 
3
3
  Copyright (c) 2021 SKevo
4
+ Copyright (c) 2024 Education Warehouse
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
@@ -1,73 +0,0 @@
1
- Metadata-Version: 2.3
2
- Name: edwh-editorjs
3
- Version: 1.0.1
4
- Summary: pyEditorJS
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: bleach
19
- Provides-Extra: dev
20
- Requires-Dist: edwh; extra == 'dev'
21
- Requires-Dist: hatch; extra == 'dev'
22
- Requires-Dist: su6[all]; extra == 'dev'
23
- Requires-Dist: types-bleach; extra == 'dev'
24
- Description-Content-Type: text/markdown
25
-
26
- # edwh-editorjs
27
-
28
- A minimal, fast Python 3.10+ package for parsing [Editor.js](https://editorjs.io) content.
29
- This package is a fork of [pyEditorJS by SKevo](https://github.com/SKevo18/pyEditorJS) with additional capabilities.
30
-
31
- ## New Features
32
-
33
- - Expanded support for additional block types: Quote, Table, Code, Warning, and Raw blocks
34
- - Issues a warning if an unknown block type is encountered, rather than ignoring it
35
- - Adds a `strict` mode, raising an `EditorJSUnsupportedBlock` exception for unknown block types when `strict=True`
36
- - Allows adding new blocks by decorating a subclass of `EditorJsParser` with `@block("name")`
37
-
38
- ## Installation
39
-
40
- ```bash
41
- pip install edwh-editorjs
42
- ```
43
-
44
- ## Usage
45
-
46
- ### Quickstart
47
-
48
- ```python
49
- from edwh_editorjs import EditorJsParser
50
-
51
- editor_js_data = ... # your Editor.js JSON data
52
- parser = EditorJsParser(editor_js_data) # initialize the parser
53
-
54
- html = parser.html(sanitize=True) # `sanitize=True` uses the included `bleach` dependency
55
- print(html) # your clean HTML
56
- ```
57
-
58
- ### Enforcing Strict Block Types
59
-
60
- ```python
61
- from edwh_editorjs import EditorJsParser, EditorJSUnsupportedBlock
62
-
63
- try:
64
- parser = EditorJsParser(editor_js_data, strict=True)
65
- html = parser.html()
66
- except EditorJSUnsupportedBlock as e:
67
- print(f"Unsupported block type encountered: {e}")
68
- ```
69
-
70
- ## Disclaimer
71
-
72
- This is a community-provided project and is not affiliated with the Editor.js team.
73
- Contributions, bug reports, and suggestions are welcome!
@@ -1,9 +0,0 @@
1
- pyeditorjs/__about__.py,sha256=d4QHYmS_30j0hPN8NmNPnQ_Z0TphDRbu4MtQj9cT9e8,22
2
- pyeditorjs/__init__.py,sha256=Z0jH2OV2NkieVFU_URtWWhVsIMihIc4IGbUvCW_2Tm0,705
3
- pyeditorjs/blocks.py,sha256=qksJTNfKShzxinWVIk9DiCGRCJ5C7lp5jLG4Hbl1enk,8214
4
- pyeditorjs/exceptions.py,sha256=Uni8r3FwJ-6xQIdSmBsHLs_htWLHD0Arp1KJEvjGU1U,439
5
- pyeditorjs/parser.py,sha256=6DCqqi-FuXDFxn9xb-dgQ19alvVu7Pjx6x3rTAx9IsI,2154
6
- edwh_editorjs-1.0.1.dist-info/METADATA,sha256=iepsBS_cxIexYAfYzBaL3dApQ3yTAE0bw838NKyfUys,2422
7
- edwh_editorjs-1.0.1.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
8
- edwh_editorjs-1.0.1.dist-info/licenses/LICENSE,sha256=bY9MhHLeuW8w1aAl-i1O1uSNP5IMOGaL6AWvHcdnt0k,1062
9
- edwh_editorjs-1.0.1.dist-info/RECORD,,
pyeditorjs/__about__.py DELETED
@@ -1 +0,0 @@
1
- __version__ = "1.0.1"
pyeditorjs/__init__.py DELETED
@@ -1,28 +0,0 @@
1
- from pathlib import Path
2
-
3
- from .blocks import BLOCKS_MAP, EditorJsBlock, block
4
- from .exceptions import EditorJsParseError
5
- from .parser import EditorJsParser
6
-
7
- __all__ = [
8
- "EditorJsParser",
9
- "EditorJsParseError",
10
- "EditorJsBlock",
11
- "block",
12
- "BLOCKS_MAP",
13
- ]
14
-
15
-
16
- # Overwrite __doc__ with README, so that pdoc can render it:
17
- README_PATH = Path(__file__).parent.parent.absolute() / Path("README.md")
18
- try:
19
- with open(README_PATH, "r", encoding="UTF-8") as readme:
20
- __readme__ = readme.read()
21
- except Exception:
22
- __readme__ = "Failed to read README.md!" # fallback message, for example when there's no README
23
-
24
- __doc__ = __readme__
25
-
26
-
27
- if __name__ == "__main__":
28
- _ = [EditorJsParser]
pyeditorjs/blocks.py DELETED
@@ -1,309 +0,0 @@
1
- import abc
2
- import typing as t
3
- from dataclasses import dataclass
4
-
5
- import bleach
6
-
7
- from .exceptions import EditorJsParseError
8
-
9
- __all__ = [
10
- "block",
11
- "BLOCKS_MAP",
12
- "EditorJsBlock",
13
- ]
14
-
15
-
16
- def _sanitize(html: str) -> str:
17
- return bleach.clean(
18
- html,
19
- tags=["b", "i", "u", "a", "mark", "code"],
20
- attributes=["class", "data-placeholder", "href"],
21
- )
22
-
23
-
24
- BLOCKS_MAP: t.Dict[str, t.Type["EditorJsBlock"]] = {
25
- # 'header': HeaderBlock,
26
- # 'paragraph': ParagraphBlock,
27
- # 'list': ListBlock,
28
- # 'delimiter': DelimiterBlock,
29
- # 'image': ImageBlock,
30
- }
31
-
32
-
33
- def block(_type: str):
34
- def wrapper(cls: t.Type["EditorJsBlock"]):
35
- BLOCKS_MAP[_type] = cls
36
- return cls
37
-
38
- return wrapper
39
-
40
-
41
- @dataclass
42
- class EditorJsBlock(abc.ABC):
43
- """
44
- A generic parsed Editor.js block
45
- """
46
-
47
- _data: dict
48
- """The raw JSON data of the entire block"""
49
-
50
- @property
51
- def id(self) -> t.Optional[str]:
52
- """
53
- Returns ID of the block, generated client-side.
54
- """
55
-
56
- return self._data.get("id", None)
57
-
58
- @property
59
- def type(self) -> t.Optional[str]:
60
- """
61
- Returns the type of the block.
62
- """
63
-
64
- return self._data.get("type", None)
65
-
66
- @property
67
- def data(self) -> dict:
68
- """
69
- Returns the actual block data.
70
- """
71
-
72
- return self._data.get("data", {})
73
-
74
- @abc.abstractmethod
75
- def html(self, sanitize: bool = False) -> str:
76
- """
77
- Returns the HTML representation of the block.
78
-
79
- ### Parameters:
80
- - `sanitize` - if `True`, then the block's text/contents will be sanitized.
81
- """
82
-
83
- raise NotImplementedError()
84
-
85
-
86
- @block("header")
87
- class HeaderBlock(EditorJsBlock):
88
- VALID_HEADER_LEVEL_RANGE = range(1, 7)
89
- """Valid range for header levels. Default is `range(1, 7)` - so, `0` - `6`."""
90
-
91
- @property
92
- def text(self) -> str:
93
- """
94
- Returns the header's text.
95
- """
96
-
97
- return self.data.get("text", "")
98
-
99
- @property
100
- def level(self) -> int:
101
- """
102
- Returns the header's level (`0` - `6`).
103
- """
104
-
105
- _level = self.data.get("level", 1)
106
-
107
- if not isinstance(_level, int) or _level not in self.VALID_HEADER_LEVEL_RANGE:
108
- raise EditorJsParseError(f"`{_level}` is not a valid header level.")
109
-
110
- return _level
111
-
112
- def html(self, sanitize: bool = False) -> str:
113
- text = self.text
114
- if sanitize:
115
- text = _sanitize(text)
116
- return rf'<h{self.level} class="cdx-block ce-header">{text}</h{self.level}>'
117
-
118
-
119
- @block("paragraph")
120
- class ParagraphBlock(EditorJsBlock):
121
- @property
122
- def text(self) -> str:
123
- """
124
- The text content of the paragraph.
125
- """
126
-
127
- return self.data.get("text", "")
128
-
129
- def html(self, sanitize: bool = False) -> str:
130
- return rf'<p class="cdx-block ce-paragraph">{_sanitize(self.text) if sanitize else self.text}</p>'
131
-
132
-
133
- @block("list")
134
- class ListBlock(EditorJsBlock):
135
- VALID_STYLES = ("unordered", "ordered")
136
- """Valid list order styles."""
137
-
138
- @property
139
- def style(self) -> t.Optional[str]:
140
- """
141
- The style of the list. Can be `ordered` or `unordered`.
142
- """
143
-
144
- return self.data.get("style", None)
145
-
146
- @property
147
- def items(self) -> t.List[str]:
148
- """
149
- Returns the list's items, in raw format.
150
- """
151
-
152
- return self.data.get("items", [])
153
-
154
- def html(self, sanitize: bool = False) -> str:
155
- if self.style not in self.VALID_STYLES:
156
- raise EditorJsParseError(f"`{self.style}` is not a valid list style.")
157
-
158
- _items = [
159
- f"<li>{_sanitize(item) if sanitize else item}</li>" for item in self.items
160
- ]
161
- _type = "ul" if self.style == "unordered" else "ol"
162
- _items_html = "".join(_items)
163
-
164
- return rf'<{_type} class="cdx-block cdx-list cdx-list--{self.style}">{_items_html}</{_type}>'
165
-
166
-
167
- @block("delimiter")
168
- class DelimiterBlock(EditorJsBlock):
169
- def html(self, sanitize: bool = False) -> str:
170
- return r'<div class="cdx-block ce-delimiter"></div>'
171
-
172
-
173
- @block("image")
174
- class ImageBlock(EditorJsBlock):
175
- @property
176
- def file_url(self) -> str:
177
- """
178
- URL of the image file.
179
- """
180
-
181
- return self.data.get("file", {}).get("url", "")
182
-
183
- @property
184
- def caption(self) -> str:
185
- """
186
- The image's caption.
187
- """
188
-
189
- return self.data.get("caption", "")
190
-
191
- @property
192
- def with_border(self) -> bool:
193
- """
194
- Whether the image has a border.
195
- """
196
-
197
- return self.data.get("withBorder", False)
198
-
199
- @property
200
- def stretched(self) -> bool:
201
- """
202
- Whether the image is stretched.
203
- """
204
-
205
- return self.data.get("stretched", False)
206
-
207
- @property
208
- def with_background(self) -> bool:
209
- """
210
- Whether the image has a background.
211
- """
212
-
213
- return self.data.get("withBackground", False)
214
-
215
- def html(self, sanitize: bool = False) -> str:
216
- if self.file_url.startswith("data:image/"):
217
- _img = self.file_url
218
- else:
219
- _img = _sanitize(self.file_url) if sanitize else self.file_url
220
-
221
- parts = [
222
- rf'<div class="cdx-block image-tool image-tool--filled {"image-tool--stretched" if self.stretched else ""} {"image-tool--withBorder" if self.with_border else ""} {"image-tool--withBackground" if self.with_background else ""}">'
223
- r'<div class="image-tool__image">',
224
- r'<div class="image-tool__image-preloader"></div>',
225
- rf'<img class="image-tool__image-picture" src="{_img}"/>',
226
- r"</div>"
227
- rf'<div class="image-tool__caption" data-placeholder="{_sanitize(self.caption) if sanitize else self.caption}"></div>'
228
- r"</div>"
229
- r"</div>",
230
- ]
231
-
232
- return "".join(parts)
233
-
234
-
235
- @block("quote")
236
- class QuoteBlock(EditorJsBlock):
237
- def html(self, sanitize: bool = False) -> str:
238
- quote = self.data.get("text", "")
239
- caption = self.data.get("caption", "")
240
- if sanitize:
241
- quote = _sanitize(quote)
242
- caption = _sanitize(caption)
243
- _alignment = self.data.get("alignment", "left") # todo
244
- return f"""
245
- <blockquote class="cdx-block cdx-quote">
246
- <div class="cdx-input cdx-quote__text">{quote}</div>
247
- <cite class="cdx-input cdx-quote__caption">{caption}</cite>
248
- </blockquote>
249
- """
250
-
251
-
252
- @block("table")
253
- class TableBlock(EditorJsBlock):
254
- def html(self, sanitize: bool = False) -> str:
255
- content = self.data.get("content", [])
256
- _stretched = self.data.get("stretched", False) # todo
257
- _with_headings = self.data.get("withHeadings", False) # todo
258
-
259
- html_table = '<table class="tc-table">'
260
-
261
- # Add content rows
262
- for row in content:
263
- html_table += '<tr class="tc-row">'
264
- for cell in row:
265
- html_table += (
266
- f'<td class="tc-cell">{_sanitize(cell) if sanitize else cell}</td>'
267
- )
268
- html_table += "</tr>"
269
-
270
- html_table += "</table>"
271
- return html_table
272
-
273
-
274
- @block("code")
275
- class CodeBlock(EditorJsBlock):
276
- def html(self, sanitize: bool = False) -> str:
277
- code = self.data.get("code", "")
278
- if sanitize:
279
- code = _sanitize(code)
280
- return f"""
281
- <code class="ce-code__textarea cdx-input" data-empty="false">{code}</code>
282
- """
283
-
284
-
285
- @block("warning")
286
- class WarningBlock(EditorJsBlock):
287
- def html(self, sanitize: bool = False) -> str:
288
- title = self.data.get("title", "")
289
- message = self.data.get("message", "")
290
-
291
- if sanitize:
292
- title = _sanitize(title)
293
- message = _sanitize(message)
294
-
295
- return f"""
296
- <div class="cdx-block cdx-warning">
297
- <div class="cdx-input cdx-warning__title">{title}</div>
298
- <div class="cdx-input cdx-warning__message">{message}</div>
299
- </div>
300
- """
301
-
302
-
303
- @block("raw")
304
- class RawBlock(EditorJsBlock):
305
- def html(self, sanitize: bool = False) -> str:
306
- html = self.data.get("html", "")
307
- if sanitize:
308
- html = _sanitize(html)
309
- return html
pyeditorjs/exceptions.py DELETED
@@ -1,19 +0,0 @@
1
- __all__ = [
2
- "EditorJsException",
3
- "EditorJsParseError",
4
- "EditorJSUnsupportedBlock",
5
- ]
6
-
7
-
8
- class EditorJsException(Exception):
9
- """
10
- Base exception
11
- """
12
-
13
-
14
- class EditorJsParseError(EditorJsException):
15
- """Raised when a parse error occurs (example: the JSON data has invalid or malformed content)."""
16
-
17
-
18
- class EditorJSUnsupportedBlock(EditorJsException):
19
- """Raised when strict=True and using an unknown block type."""