edwh-editorjs 1.0.1__py3-none-any.whl → 1.1.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.
- {edwh_editorjs-1.0.1.dist-info → edwh_editorjs-1.1.0.dist-info}/METADATA +37 -6
- edwh_editorjs-1.1.0.dist-info/RECORD +9 -0
- pyeditorjs/__about__.py +1 -1
- pyeditorjs/__init__.py +3 -1
- pyeditorjs/blocks.py +4 -0
- edwh_editorjs-1.0.1.dist-info/RECORD +0 -9
- {edwh_editorjs-1.0.1.dist-info → edwh_editorjs-1.1.0.dist-info}/WHEEL +0 -0
- {edwh_editorjs-1.0.1.dist-info → edwh_editorjs-1.1.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: edwh-editorjs
|
|
3
|
-
Version: 1.0
|
|
3
|
+
Version: 1.1.0
|
|
4
4
|
Summary: pyEditorJS
|
|
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>
|
|
@@ -25,7 +25,7 @@ Description-Content-Type: text/markdown
|
|
|
25
25
|
|
|
26
26
|
# edwh-editorjs
|
|
27
27
|
|
|
28
|
-
A minimal, fast Python 3.10+ package for parsing [Editor.js](https://editorjs.io) content.
|
|
28
|
+
A minimal, fast Python 3.10+ package for parsing [Editor.js](https://editorjs.io) content.
|
|
29
29
|
This package is a fork of [pyEditorJS by SKevo](https://github.com/SKevo18/pyEditorJS) with additional capabilities.
|
|
30
30
|
|
|
31
31
|
## New Features
|
|
@@ -46,7 +46,7 @@ pip install edwh-editorjs
|
|
|
46
46
|
### Quickstart
|
|
47
47
|
|
|
48
48
|
```python
|
|
49
|
-
from
|
|
49
|
+
from pyeditorjs import EditorJsParser
|
|
50
50
|
|
|
51
51
|
editor_js_data = ... # your Editor.js JSON data
|
|
52
52
|
parser = EditorJsParser(editor_js_data) # initialize the parser
|
|
@@ -58,15 +58,46 @@ print(html) # your clean HTML
|
|
|
58
58
|
### Enforcing Strict Block Types
|
|
59
59
|
|
|
60
60
|
```python
|
|
61
|
-
from
|
|
61
|
+
from pyeditorjs import EditorJsParser, EditorJSUnsupportedBlock
|
|
62
|
+
|
|
63
|
+
editor_js_data: dict = ...
|
|
64
|
+
parser = EditorJsParser(editor_js_data)
|
|
62
65
|
|
|
63
66
|
try:
|
|
64
|
-
|
|
65
|
-
html = parser.html()
|
|
67
|
+
html = parser.html(strict=True)
|
|
66
68
|
except EditorJSUnsupportedBlock as e:
|
|
67
69
|
print(f"Unsupported block type encountered: {e}")
|
|
68
70
|
```
|
|
69
71
|
|
|
72
|
+
### Adding a Custom Block
|
|
73
|
+
|
|
74
|
+
To add a custom block type, create a new class that subclasses `EditorJsBlock` and decorates it with `@block("name")`,
|
|
75
|
+
where `"name"` is the custom block type. Implement an `html` method to define how the block’s content should be
|
|
76
|
+
rendered. This method should accept a `sanitize` parameter and can access block data via `self.data`.
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from pyeditorjs import EditorJsParser, EditorJsBlock, block
|
|
80
|
+
|
|
81
|
+
@block("custom")
|
|
82
|
+
class CustomBlock(EditorJsBlock):
|
|
83
|
+
def html(self, sanitize: bool = False) -> str:
|
|
84
|
+
# Access data with self.data and return the rendered HTML
|
|
85
|
+
content = self.data.get("something", "")
|
|
86
|
+
if sanitize:
|
|
87
|
+
content = self.sanitize(content)
|
|
88
|
+
|
|
89
|
+
return f"<div class='custom-block'>{content}</div>"
|
|
90
|
+
|
|
91
|
+
# Usage
|
|
92
|
+
class CustomEditorJsParser(EditorJsParser):
|
|
93
|
+
pass # Custom blocks are automatically detected
|
|
94
|
+
|
|
95
|
+
editor_js_data = ... # Editor.js JSON data with a "customBlock" type
|
|
96
|
+
parser = CustomEditorJsParser(editor_js_data)
|
|
97
|
+
html = parser.html()
|
|
98
|
+
print(html) # Includes rendered custom blocks
|
|
99
|
+
```
|
|
100
|
+
|
|
70
101
|
## Disclaimer
|
|
71
102
|
|
|
72
103
|
This is a community-provided project and is not affiliated with the Editor.js team.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
pyeditorjs/__about__.py,sha256=LGVQyDsWifdACo7qztwb8RWWHds1E7uQ-ZqD8SAjyw4,22
|
|
2
|
+
pyeditorjs/__init__.py,sha256=63UoNCWJo6NuPXXYnANQE3SKm1PQu2ggs89KCXSq-44,807
|
|
3
|
+
pyeditorjs/blocks.py,sha256=4A8dXbh_oUKCctOHtMV6BrR7-UpyqFREPvwPEe_6vUo,8304
|
|
4
|
+
pyeditorjs/exceptions.py,sha256=Uni8r3FwJ-6xQIdSmBsHLs_htWLHD0Arp1KJEvjGU1U,439
|
|
5
|
+
pyeditorjs/parser.py,sha256=6DCqqi-FuXDFxn9xb-dgQ19alvVu7Pjx6x3rTAx9IsI,2154
|
|
6
|
+
edwh_editorjs-1.1.0.dist-info/METADATA,sha256=Aq3-6WNcqqhbufFvnigNO-txrmV_6OppGmliWoK7tf4,3519
|
|
7
|
+
edwh_editorjs-1.1.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
8
|
+
edwh_editorjs-1.1.0.dist-info/licenses/LICENSE,sha256=bY9MhHLeuW8w1aAl-i1O1uSNP5IMOGaL6AWvHcdnt0k,1062
|
|
9
|
+
edwh_editorjs-1.1.0.dist-info/RECORD,,
|
pyeditorjs/__about__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "1.0
|
|
1
|
+
__version__ = "1.1.0"
|
pyeditorjs/__init__.py
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
2
|
|
|
3
3
|
from .blocks import BLOCKS_MAP, EditorJsBlock, block
|
|
4
|
-
from .exceptions import EditorJsParseError
|
|
4
|
+
from .exceptions import EditorJsException, EditorJsParseError, EditorJSUnsupportedBlock
|
|
5
5
|
from .parser import EditorJsParser
|
|
6
6
|
|
|
7
7
|
__all__ = [
|
|
8
8
|
"EditorJsParser",
|
|
9
9
|
"EditorJsParseError",
|
|
10
|
+
"EditorJsException",
|
|
11
|
+
"EditorJSUnsupportedBlock",
|
|
10
12
|
"EditorJsBlock",
|
|
11
13
|
"block",
|
|
12
14
|
"BLOCKS_MAP",
|
pyeditorjs/blocks.py
CHANGED
|
@@ -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,,
|
|
File without changes
|
|
File without changes
|