Skip to main content

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

Metadata

Release files for html-to-draftjs 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for html-to-draftjs 1.0.1
File Size Uploaded Provenance Actions
html-to-draftjs-1.0.1.tar.gz 6.7 kB Without provenance Details for html-to-draftjs-1.0.1.tar.gz

Release files / html-to-draftjs-1.0.1.tar.gz

Download URL html-to-draftjs-1.0.1.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2212acf3b063c17b6dc91875f474159e1f730c1a4e5fbf74f9a66250f7040e9a
BLAKE2b-256 checksum
How to use checksums
840fe6f3d05e4e23fd1e9de9fb84376e65323c8c7a53bbef97ea4e69fbc93ba6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.2

Security for html-to-draftjs 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page