Library to convert rich text from Draft.js raw ContentState to HTML
Actively maintained. Last release 6 weeks ago, commits in 20 of the last 26 weeks. A safe choice.
pip install draftjs-exporterDraft.js exporter
Library to convert rich text from Draft.js raw ContentState to HTML.
Features
This project adheres to Semantic Versioning, and measures performance and code coverage. Code is checked with mypy.
- Extensive configuration of the generated HTML.
- Default, extensible block & inline style maps for common HTML elements.
- Convert line breaks to
<br>elements with decorators. - Define any attribute in the block map – custom class names for elements.
- React-like API to create custom components.
- Automatic conversion of entity data to HTML attributes (int & boolean to string, style object to style string).
- Nested lists (
<li>elements go inside<ul>or<ol>, with multiple levels). - Output inline styles as inline elements (
<em>,<strong>, pick and choose, with any attribute). - Overlapping inline style and entity ranges.
- Static type annotations.
It is developed alongside the Draftail rich text editor, for Wagtail. Check out the online demo, and our introductory blog post.
When to use the exporter
Draft.js is a rich text editor framework for React. Its approach is different from most rich text editors because it does not store data as HTML, but rather in its own representation called ContentState. This exporter is useful when the ContentState to HTML conversion has to be done in a Python ecosystem.
The initial use case was to gain more control over the content managed by rich text editors in a Wagtail/Django site. If you want to read the full story, have a look at our blog post: .