Draft.js exporter 🐍 - Markdown edition
Library to convert rich text from Draft.js raw ContentState to Markdown, based on Draft.js exporter.
🚧 This is an experimental exporter with limited Markdown support – please use with caution.
Usage
This package is a Markdown export configuration for the Draft.js exporter. Specifically, it provides:
- A Markdown-friendly exporter engine, with fallbacks to HTML tags.
- Configuration for basic Markdown formatting.
First, install the package:
pip install draftjs_exporter_markdown
Then, to convert Draft.js content to Markdown:
And in Python:
from draftjs_exporter.html import HTML
from draftjs_exporter_markdown import BLOCK_MAP, ENGINE, ENTITY_DECORATORS, STYLE_MAP
# Initialise the exporter.
exporter = HTML({
# Those configurations are overridable like for draftjs_exporter.
'block_map': BLOCK_MAP,
'style_map': STYLE_MAP,
'entity_decorators': ENTITY_DECORATORS,
'engine': ENGINE,
})
markdown = exporter.render({
'entityMap': {},
'blocks': [{
'key': '6mgfh',
'text': 'Hello, world!',
'type': 'unstyled',
'depth': 0,
'inlineStyleRanges': [],
'entityRanges': []
}]
})
print(markdown)
You can also run an example by downloading this repository and then using python example.py.
Configuration
Please refer to the Draft.js exporter configuration documentation.
Supported Markdown formatting
The built-in configuration provides support for:
- Inline styles: bold, italic, strikethrough, code
- Blocks: paragraphs, heading levels, bullet and number lists, code blocks, blockquote
- Images, links, and horizontal rules
Contrary to the main Draft.js exporter,
- Nested / overlapping styles aren't supported.
- None of the content is escaped (HTML escaping is unnecessary for Markdown, and there is no Markdown escaping).
Development
Requirements:
virtualenv,pyenv,twine
git clone git@github.com:thibaudcolas/draftjs_exporter_markdown.git
cd draftjs_exporter_markdown/
# Install dependencies
nvm install
npm install
# For tests and development in watch mode.
npm install -g nodemon
# Install the Python environment.
virtualenv .venv
source ./.venv/bin/activate
make init
# Install required Python versions
pyenv install --skip-existing 3.6.3
# Make required Python versions available globally.
pyenv global system 3.6.3
# Run the built-in example.
make dev
Releases
Use make release, which uses standard-version to generate the CHANGELOG and decide on the version bump based on the commits since the last release.
Credits
View the full list of contributors. MIT licensed.
Release files for draftjs-exporter-markdown 0.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| draftjs_exporter_markdown-0.2.4.tar.gz | 6.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| draftjs_exporter_markdown-0.2.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.0 kB
Release files / draftjs_exporter_markdown-0.2.4.tar.gz
| Download URL | draftjs_exporter_markdown-0.2.4.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
13d2d93f7e8d200e6f717b98352bf41cbbe730faeb9fa0a04decd28b888b4a98
|
|
BLAKE2b-256 checksum How to use checksums |
ce80141b6b0b0a7e41a1f2bc4c06656411d5a4f77c052e724a3e05550406a4ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.7.8
|
Release files / draftjs_exporter_markdown-0.2.4-py3-none-any.whl
| Download URL | draftjs_exporter_markdown-0.2.4-py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
85ef894a57a9d3f1d26572d8ecc2873d643d06cc0fbf41d80778c1e4d63954d9
|
|
BLAKE2b-256 checksum How to use checksums |
cbcc3bd94f14f5d443b9b2bb5660592574641969158e6f219c853e46710571e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.7.8
|