Added
- Add simplified block mapping format:
BLOCK_TYPES.HEADER_TWO: 'h2'.
- Raise exception when
style_map does not define an element for the style.
- Add support for any props on
style_map.
- Automatically convert
style prop from a dict of camelCase properties to a string, on all elements (if style is already a string, it will be output as is).
- Support components (
render function returning create_element nodes) in style_map.
- Add more defaults in the style map:
BOLD = 'strong'
CODE = 'code'
ITALIC = 'em'
UNDERLINE = 'u'
STRIKETHROUGH = 's'
SUPERSCRIPT = 'sup'
SUBSCRIPT = 'sub'
MARK = 'mark'
QUOTATION = 'q'
SMALL = 'small'
SAMPLE = 'samp'
INSERT = 'ins'
DELETE = 'del'
KEYBOARD = 'kbd'
- Add new
pre block type.
- Support components (
render function returning create_element nodes) in block_map, for both element and wrapper.
Removed
- Remove array-style block element and wrapper declarations (
['ul'], ['ul', {'class': 'bullet-list'}]).
- Remove
DOM.create_text_node method.
Changed
- Replace array-style mapping declarations of block element and wrapper props with
props and wrapper_props attributes (dictionaries of props).
- Moved and renamed
BlockException to ConfigException.
- Replace
style_map config format to the one of the block_map.
- Move internal
camel_to_dash method to DOM for official use.
- Change ordering of inline styles - now using alphabetical ordering of style key instead of tag name.
STRIKETHROUGH styles in default style map now map to s tag.
UNDERLINE styles in default style map now map to u tag.
- By default,
code-block blocks are now rendered inside a combination of pre and code tags.
- For entities, directly pass
data dict as props instead of whole entity map declaration.
Fixed
- Fix block ordering with block components and wrapper. Fix #55.
How to upgrade
# Change element-only block declarations:
- BLOCK_TYPES.HEADER_TWO: {'element': 'h2'},
+ BLOCK_TYPES.HEADER_TWO: 'h2',
# Change array-style block declarations:
- BLOCK_TYPES.BLOCKQUOTE: ['blockquote', {'class': 'c-pullquote'}]
+ BLOCK_TYPES.BLOCKQUOTE: {'element': 'blockquote', 'props': {'class': 'c-pullquote'}}
# Change block wrapper declarations:
- 'wrapper': ['ul', {'class': 'bullet-list'}],
+ 'wrapper': 'ul',
+ 'wrapper_props': {'class': 'bullet-list'},
# Change location and name of exceptions:
- from draftjs_exporter.wrapper_state import BlockException
+ from draftjs_exporter.options import ConfigException
# Change element-only style declarations:
- 'KBD': {'element': 'kbd'},
+ 'KBD': 'kbd',
# Change object-style style declarations:
- 'HIGHLIGHT': {'element': 'strong', 'textDecoration': 'underline'},
+ 'HIGHLIGHT': {'element': 'strong', 'props': {'style': {'textDecoration': 'underline'}}},
# Create custom STRIKETHROUGH styles:
+ 'STRIKETHROUGH': {'element': 'span', 'props': {'style': {'textDecoration': 'line-through'}}},
# Create custom UNDERLINE styles:
+ 'UNDERLINE': {'element': 'span', 'props': {'style': {'textDecoration': 'underline'}}},
# New camel_to_dash location:
- from draftjs_exporter.style_state import camel_to_dash
- camel_to_dash()
+ from draftjs_exporter.dom import DOM
+ DOM.camel_to_dash()
# New default rendering for code-block:
- BLOCK_TYPES.CODE: 'pre',
+ BLOCK_TYPES.CODE: lambda props: DOM.create_element('pre', {}, DOM.create_element('code', {}, props['children'])),
# Use the new pre block to produce the previous result, or override the default for code-block.
+ BLOCK_TYPES.PRE: 'pre',
# Entities now receive the content of `data` directly, instead of the whole entity:
def render(self, props):
- data = props.get('data', {})
link_props = {
- 'href': data['url'],
+ 'href': props['url'],
}
# Remove wrapping around text items.
- DOM.create_text_node(text)
+ text
# Remove fragment calls.
- DOM.create_document_fragment()
+ DOM.create_element()
# Remove text getters and setters. This is not supported anymore.
- DOM.get_text_content(elt)
- DOM.set_text_content(elt, text)