From 2fe31ddd8415c2b5958c425928653765c886909b Mon Sep 17 00:00:00 2001 From: Loic Teixeira Date: Thu, 11 Jan 2018 16:19:32 +1000 Subject: [PATCH] Update to latest draftjs_exporter See draftjs_exporter v2.0.0 release notes: https://github.com/springload/draftjs_exporter/releases/tag/v2.0.0 --- setup.py | 2 +- .../rich_text/converters/contentstate.py | 22 ++++++++----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/setup.py b/setup.py index f25c9cccdc..f14a2e558d 100755 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ install_requires = [ "django-taggit>=0.22.2,<1.0", "django-treebeard>=4.2.0,<5.0", "djangorestframework>=3.1.3,<4.0", - "draftjs_exporter>=1.0,<2.0", + "draftjs_exporter>=2.0,<2.1", "Pillow>=2.6.1,<5.0", "beautifulsoup4>=4.5.1,<5.0", "html5lib>=0.999,<1", diff --git a/wagtail/admin/rich_text/converters/contentstate.py b/wagtail/admin/rich_text/converters/contentstate.py index 5b4e99d1c6..d6a5f0a290 100644 --- a/wagtail/admin/rich_text/converters/contentstate.py +++ b/wagtail/admin/rich_text/converters/contentstate.py @@ -28,18 +28,11 @@ def Link(props): return DOM.create_element('a', link_props, props['children']) -class BR: - """ - Replace line breaks (\n) with br tags. - """ - SEARCH_RE = re.compile(r'\n') +def br(props): + if props['block']['type'] == BLOCK_TYPES.CODE: + return props['children'] - def render(self, props): - # Do not process matches inside code blocks. - if props['block']['type'] == BLOCK_TYPES.CODE: - return props['children'] - - return DOM.create_element('br') + return DOM.create_element('br') def BlockFallback(props): @@ -70,9 +63,12 @@ class ContentstateConverter(): ENTITY_TYPES.FALLBACK: EntityFallback, }, 'composite_decorators': [ - BR, + { + 'strategy': re.compile(r'\n'), + 'component': br, + }, ], - 'engine': 'string', + 'engine': DOM.STRING, } for feature in self.features: