edwh-editorjs 1.0.0__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.
@@ -0,0 +1,104 @@
1
+ Metadata-Version: 2.3
2
+ Name: edwh-editorjs
3
+ Version: 1.1.0
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 pyeditorjs 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 pyeditorjs import EditorJsParser, EditorJSUnsupportedBlock
62
+
63
+ editor_js_data: dict = ...
64
+ parser = EditorJsParser(editor_js_data)
65
+
66
+ try:
67
+ html = parser.html(strict=True)
68
+ except EditorJSUnsupportedBlock as e:
69
+ print(f"Unsupported block type encountered: {e}")
70
+ ```
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
+
101
+ ## Disclaimer
102
+
103
+ This is a community-provided project and is not affiliated with the Editor.js team.
104
+ Contributions, bug reports, and suggestions are welcome!
@@ -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.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
@@ -47,6 +47,10 @@ class EditorJsBlock(abc.ABC):
47
47
  _data: dict
48
48
  """The raw JSON data of the entire block"""
49
49
 
50
+ @classmethod
51
+ def sanitize(cls, html: str) -> str:
52
+ return _sanitize(html)
53
+
50
54
  @property
51
55
  def id(self) -> t.Optional[str]:
52
56
  """
@@ -1,92 +0,0 @@
1
- Metadata-Version: 2.3
2
- Name: edwh-editorjs
3
- Version: 1.0.0
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
- # pyEditorJS
27
-
28
- A minimal, fast, Python 3.6+ package for parsing [Editor.js](https://editorjs.io) content.
29
-
30
- ## Features
31
-
32
- - Handles all out-of-the-box Editor.js elements;
33
- - Optional sanitization via the `bleach` library;
34
- - Checks whether the data is valid (e. g.: a header can't have more than 6 levels), and raises `EditorJsParseError` if data is malformed;
35
- - Uses Editor.js's class names for styles, so the output will be consistent with WYSIWYG (see [Editor.js's example style](https://github.com/codex-team/editor.js/blob/8ae8823dcd6877d63241fcb94694a8a18744485d/example/assets/demo.css) and [styles documentation](https://editorjs.io/styles))
36
-
37
- ## Installation
38
-
39
- ```bash
40
- pip install pyeditorjs
41
- ```
42
-
43
- **Optional:** install [bleach](https://pypi.org/project/bleach) for clean HTML:
44
-
45
- ```bash
46
- pip install bleach
47
- ```
48
-
49
- ## Usage
50
-
51
- ### Quickstart
52
-
53
- ```python
54
- from pyeditorjs import EditorJsParser
55
-
56
- editor_js_data = ... # your Editor.js JSON data
57
- parser = EditorJsParser(editor_js_data) # initialize the parser
58
-
59
- html = parser.html(sanitize=True) # `sanitize=True` requires `bleach` to be installed
60
- print(html) # your clean HTML
61
- ```
62
-
63
- ### Obtain texts only (for creating audio-only version, for example)
64
-
65
- > **WARNING:** This does not sanitize the texts! Please, call `bleach.clean(...)` directly. This also doesn't obtain text from bold texts, markers, etc... - you should use [BeautifulSoup](https://pypi.org/project/beautifulsoup4/) for this.
66
-
67
- ```python
68
- #import bleach
69
- from pyeditorjs import EditorJsParser
70
-
71
- editor_js_data = ... # your Editor.js JSON data
72
- parser = EditorJsParser(editor_js_data) # initialize the parser
73
-
74
- all_texts = []
75
-
76
- for block in parser:
77
- text = getattr(block, 'text', None)
78
-
79
- if text:
80
- all_texts.append(text) # all_texts.append(bleach.clean(text))
81
-
82
- print(all_texts)
83
- ```
84
-
85
- ## Disclaimer
86
-
87
- This is a community-provided project, and is not affiliated with the Editor.js team.
88
- It was created in my spare time. I cannot make sure that it will receive consistent updates.
89
-
90
- Because of this, PRs, bug reports and suggestions are welcome!
91
-
92
- <a href="https://www.buymeacoffee.com/skevo"><img src="https://img.buymeacoffee.com/button-api/?text=Support me&emoji=🐣&slug=skevo&button_colour=ffa200&font_colour=000000&font_family=Poppins&outline_colour=000000&coffee_colour=FFDD00" /></a>
@@ -1,9 +0,0 @@
1
- pyeditorjs/__about__.py,sha256=J-j-u0itpEFT6irdmWmixQqYMadNl1X91TxUmoiLHMI,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.0.dist-info/METADATA,sha256=CIRh9bLb2wwbKecMPayxr8TyY4z3GkYlr2L7FJIjCxI,3269
7
- edwh_editorjs-1.0.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
8
- edwh_editorjs-1.0.0.dist-info/licenses/LICENSE,sha256=bY9MhHLeuW8w1aAl-i1O1uSNP5IMOGaL6AWvHcdnt0k,1062
9
- edwh_editorjs-1.0.0.dist-info/RECORD,,