Skip to main content

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

Project description

> 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.


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': []


You can also run an example by downloading this repository and then using python


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).


> Requirements: virtualenv, pyenv, twine

git clone
cd draftjs_exporter_markdown/

# Install the git hooks.

# 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 2.7.11
pyenv install --skip-existing 3.6.3
# Make required Python versions available globally.
pyenv global system 2.7.11 3.6.3

# Run the built-in example.
make dev


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.


View the full list of contributors. MIT licensed.

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
draftjs_exporter_markdown-0.2.1.tar.gz (9.9 kB) Copy SHA256 hash SHA256 Source None Sep 16, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page