Skip to main content

Library to convert rich text from Draft.js raw ContentState to Markdown, based on draftjs_exporter

Project description

Draft.js exporter 🐍 - Markdown edition

PyPI PyPI downloads Travis Coveralls Total alerts Language grade: Python

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

draftjs_exporter_markdown-0.2.2.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

draftjs_exporter_markdown-0.2.2-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file draftjs_exporter_markdown-0.2.2.tar.gz.

File metadata

  • Download URL: draftjs_exporter_markdown-0.2.2.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.20.1 setuptools/46.1.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.2

File hashes

Hashes for draftjs_exporter_markdown-0.2.2.tar.gz
Algorithm Hash digest
SHA256 e9ecd8016028ed1e1d6d8a8ce635dac90031f26fda33d2a355d404ba4337f380
MD5 a59c5784f613f9ce0a0714448ed373e8
BLAKE2b-256 b79ff4e605f3cd068c6b4d00b24ef62fb1a6d39f94ea34177cd7e3caedf5d7c5

See more details on using hashes here.

Provenance

File details

Details for the file draftjs_exporter_markdown-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: draftjs_exporter_markdown-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.20.1 setuptools/46.1.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.2

File hashes

Hashes for draftjs_exporter_markdown-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b2841228b8dc7c8fba0697a954663a51ac610795232fa370e9238c71b6fc9979
MD5 3f038cb9b207333bf65b0e4a8782a3c2
BLAKE2b-256 b5c55d1bbc1fa5b0e69a3f64248b1dfb02ae7f3af7e5bcbea682729e70071965

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page