storyblok-python-richtext-renderer

This package allows you to get an HTML string from the richtext field of Storyblok.

Install

pip install storyblok-richtext

Usage

Class Richtext

Instantiate the Richtext class:

from storyblok_richtext import Richtext

resolver = Richtext()

Use the function render() to get the html string from your richtext field.

# code below ...
data = {
    'type': 'doc',
    'content': [{
        'type': 'horizontal_rule'
    }]
}

resolver.render(data) # renders a html string: '<hr />'

How to define a custom schema for resolver?

Make a copy of the default schema storyblok_richtext/html_schema.py and add your own schema as parameter to the Richtext class.

resolver = Richtext(your_custom_schema)

Testing

Before the testing, we advise you to use an environment virtualization tool, for example, virtualenv:

# use virtualenv to create the environment
virtualenv -p python3 .

# activate the environment
source bin/activate

# you can execute the tests!

# to desactivate the environment
deactivate

We use unittest module for tests. In terminal, execute:

We use unittest module for tests. You can execute the following task to run the tests:

$ python -m unittest discover storyblok_richtext/tests -v

Contribution

Fork me on Github