Giter Club home page Giter Club logo

pyeditorjs's Introduction

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!

pyeditorjs's People

Contributors

skevo18 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pyeditorjs's Issues

Question about PyPI

Are you still planning to publish this library?
I'm potentially interested in using it for my site, if you're not going then I'll have to fork it :(

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.