Releases: springload/draftjs_exporter
v2.1.5
v2.1.4
v2.1.3
v2.1.2
v2.1.1
v2.1.0
Added
- Give block rendering components access to the current
block, when the component is rendered for a block, and theblockslist (#90). - Give text decorators renderers access to the current
blockandblockslist (#90). - Give style rendering components access to the current
block,blockslist, and current style type asinline_style_range.style(#87, #90).
Changed
- Performance improvements for text-only (no inline styles, no entities) blocks (#89).
v2.0.0
This release contains breaking changes that will require updating the exporter's configurations. Be sure to check out the "how to upgrade" section below.
Changed
- Change default DOM engine to
DOMString(#79, #85). - Add extra install for html5lib (#79, #85).
- Remove support for class-based decorators (#73, #84).
- Switch composite decorators to dict format like that of Draft.js, with
strategyandcomponentattributes. - Use dotted-path loading for custom engines (#64, #81).
- Use dotted-path loading for built-in engines.
- Raise
ImportErrorwhen loading an engine fails, notConfigException.
Removed
- Calls to
DOM.usemust use a valid engine, there is no default value anymore. - Stop supporting passing an engine class directly in the
engineoption, or toDOM.use. - Stop including tests in published package.
Fixed
- Stop loading html5lib engine on every use, even if unused (#80).
How to upgrade
New default engine
The specificities of the new engine are described in the documentation. To start using the new default,
- Remove the
engineproperty from the exporter configuration, or do'engine': DOM.STRING,. - You can also remove the
html5libandbeautifulsoup4dependencies from your project if they aren't used anywhere else.
To keep using the previous default, html5lib:
- Set the
engineproperty to'engine': DOM.HTML5LIB,. - Make sure you install the exporter with
pip install draftjs_exporter[html5lib].
Decorator component definitions
Decorator components now require the function syntax (see the relevant documentation).
# Before:
class OrderedList:
def render(self, props):
depth = props['block']['depth']
return DOM.create_element('ol', {
'class': 'list--depth-{0}'.format(depth)
}, props['children'])
# After:
def ordered_list(props):
depth = props['block']['depth']
return DOM.create_element('ol', {
'class': 'list--depth-{0}'.format(depth)
}, props['children'])If you were relying on the configuration capabilities of the class API, switch to composing components instead:
# Before:
class Link:
def __init__(self, use_new_window=False):
self.use_new_window = use_new_window
def render(self, props):
link_props = {
'href': props['url'],
}
if self.use_new_window:
link_props['target'] = '_blank'
link_props['rel'] = 'noreferrer noopener'
return DOM.create_element('a', link_props, props['children'])
# In the config:
ENTITY_TYPES.LINK: Link(use_new_window=True)
# After:
def link(props):
return DOM.create_element('a', props, props['children'])
def same_window_link(props):
return DOM.create_element(link, {
'href': props['url'],
}, props['children'])
})
def new_window_link(props):
return DOM.create_element(link, {
'href': props['url'],
'target': '_blank',
'rel': 'noreferrer noopener',
}, props['children'])
})The composite decorators API now looks closer to that of other decorators, and to Draft.js:
# Before:
class BR:
SEARCH_RE = re.compile(r'\n')
def render(self, props):
if props['block']['type'] == BLOCK_TYPES.CODE:
return props['children']
return DOM.create_element('br')
'composite_decorators': [
BR,
]
# After:
def br(props):
if props['block']['type'] == BLOCK_TYPES.CODE:
return props['children']
return DOM.create_element('br')
# In the config:
'composite_decorators': [
{
'strategy': re.compile(r'\n'),
'component': br,
},
],Engine configuration
# The `engine` field in the exporter config now has to be a dotted path string pointing to a valid engine.
- 'engine': 'html5lib',
+ 'engine': 'draftjs_exporter.engines.html5lib.DOM_HTML5LIB',
# Or, using the shorthand.
+ 'engine': DOM.HTML5LIB,
# It's not possible either to directly provide an engine implementation - use a dotted path instead.
- DOM.use(DOMTestImpl)
+ DOM.use('tests.test_dom.DOMTestImpl')v1.1.1
v1.1.0
Added
- Add new string-based dependency-free DOM backing engine, with much better performance, thanks to the expertise of @BertrandBordage (#77).
Changed
- Pre-compile regexes in html5lib engine for performance improvements (#76).
How to upgrade
There is no need to make any changes to keep using the previous engines (html5lib, lxml). To switch to the new string engine, opt-in via the config:
exporter = HTML({
+ # Specify which DOM backing engine to use.
+ 'engine': 'string',
})v1.0.0
This release is functionally identical to the previous one,
v0.9.0.
The project has reached a high-enough level of stability to be used in production, and breaking changes will now be reflected via major version changes.