GithubHelp home page GithubHelp logo

plusplusco / html-to-draftjs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nyankiyoshi/html-to-draftjs

0.0 1.0 0.0 42 KB

Convert basic HTML into DraftJS JSON format.

License: MIT License

Python 100.00%

html-to-draftjs's Introduction

HTML to DraftJS

Convert HTML into DraftJS JSON format.

Requirement Status Coverage Status Version

Commits since latest release Supported versions Supported implementations

Installation

pip install html-to-draftjs

Usage

from html_to_draftjs import html_to_draftjs


json = html_to_draftjs("""
    <h1>My Page</h1>

    <h2>Introduction</h2>

    <p>Some <em>content</em> that is pretty <strong>interesting</strong></p>
    <p>Don't forget to <a href="https://example.com">follow me!</a></p>

    <h2>Illustration</h2>
    <p><img src="https://example.com/image.png" alt="image" /></p>
""")

API

html_to_draftjs(raw_html_content: str[, features="lxml", strict=False]) -> dict

Converts a given HTML input into JSON.

  • features the features for the HTML tree-builder. By default it is set to lxml which is fast and powerful.
  • strict (boolean), if false, it will only warn on invalid operations. If true, it will raise errors.

soup_to_draftjs(bs_object: BeautifulSoup[, strict=False]) -> dict

Converts a given beautiful soup into JSON. Useful if you have to select a given part of the HTML content to convert it (e.g. #content).

  • strict (boolean), if false, it will only warn on invalid operations. If true, it will raise errors.

Supported Tags and Attributes

Blocks

  • <div>, <p>
  • <h1> ... <h6>
  • <blockquote>
  • <li> and <ol> (doesn't support <ul> grouping)
  • Doesn't support the align attribute.

Inline Styling

  • <strong>, <b>
  • <em>, <i>

Entities

  • <img src="url" [alt="alt"] [height="123"] [width="123"]>
  • <a href="url">
  • <br/>
  • Doesn't support the title and align attributes.

Development

./setup.py develop
pip install -r requirements_dev.txt

html-to-draftjs's People

Contributors

agargenta avatar

Watchers

James Cloos avatar

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.