pyEditorJS
Project description
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
bleach
library; - Checks whether the data is valid (e. g.: a header can't have more than 6 levels), and raises
EditorJsParseError
if 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!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file edwh_editorjs-1.0.0.tar.gz
.
File metadata
- Download URL: edwh_editorjs-1.0.0.tar.gz
- Upload date:
- Size: 32.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 773ad26813736dd2bd022345d182e1a5b89b364f0974e08ac21af2ece06607ed |
|
MD5 | e9709993a9462fd3a3eca47a88b42623 |
|
BLAKE2b-256 | b78d8b2405cfacb09a70cbe487916d71534cf5907badf2ecd8e579627cad3844 |
File details
Details for the file edwh_editorjs-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: edwh_editorjs-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 599443fab0d839bc10e03a9194b091656e5fcb6d2f22b76307239bf0670e5b5a |
|
MD5 | 53f1bd002d508755cd8d696cefb81f2d |
|
BLAKE2b-256 | 13de09167d077bb64524f786fc5fa05e3b3d274491818be46a8304c6770e9467 |