Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyeditorjs-1.0.0b0.tar.gz (5.7 kB view details)

Uploaded Source

File details

Details for the file pyeditorjs-1.0.0b0.tar.gz.

File metadata

  • Download URL: pyeditorjs-1.0.0b0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for pyeditorjs-1.0.0b0.tar.gz
Algorithm Hash digest
SHA256 a777a952dd84fc5efb623f7fe20bb3eafdda086e9996441294238a5d8a651a8e
MD5 13b56024daf85276548f78d31ed3ce4a
BLAKE2b-256 02a3d0cdc265d9cc8c55abfc3c518da1d0fd89205d28191a745aacc9a0551530

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page