This release is a pre-release and may not be stable for production use.
pyEditorJS
A minimal, fast, Python 3.6+ package for parsing Editor.js content.
Features
- Handles all out-of-the-box Editor.js elements;
- Optional sanitization via the
bleachlibrary; - Checks whether the data is valid (e. g.: a header can't have more than 6 levels), and raises
EditorJsParseErrorif data is malformed; - Uses Editor.js's class names for styles, so the output will be consistent with WYSIWYG (see Editor.js's example style and styles documentation)
Installation
pip install pyeditorjs
Optional: install bleach for clean HTML:
pip install bleach
Usage
Quickstart
from pyeditorjs import EditorJsParser
editor_js_data = ... # your Editor.js JSON data
parser = EditorJsParser(editor_js_data) # initialize the parser
html = parser.html(sanitize=True) # `sanitize=True` requires `bleach` to be installed
print(html) # your clean HTML
Obtain texts only (for creating audio-only version, for example)
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 for this.
#import bleach
from pyeditorjs import EditorJsParser
editor_js_data = ... # your Editor.js JSON data
parser = EditorJsParser(editor_js_data) # initialize the parser
all_texts = []
for block in parser:
text = getattr(block, 'text', None)
if text:
all_texts.append(text) # all_texts.append(bleach.clean(text))
print(all_texts)
Disclaimer
This is a community-provided project, and is not affiliated with the Editor.js team. It was created in my spare time. I cannot make sure that it will receive consistent updates.
Because of this, PRs, bug reports and suggestions are welcome!
Metadata
Release files for pyeditorjs 1.0.0b0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyeditorjs-1.0.0b0.tar.gz | 5.7 kB | Details |
Release files / pyeditorjs-1.0.0b0.tar.gz
| Download URL | pyeditorjs-1.0.0b0.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a777a952dd84fc5efb623f7fe20bb3eafdda086e9996441294238a5d8a651a8e
|
|
BLAKE2b-256 checksum How to use checksums |
02a3d0cdc265d9cc8c55abfc3c518da1d0fd89205d28191a745aacc9a0551530
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|