Kaynağa Gözat

Update to latest draftjs_exporter

See draftjs_exporter v2.0.0 release notes: https://github.com/springload/draftjs_exporter/releases/tag/v2.0.0
Loic Teixeira 7 yıl önce
ebeveyn
işleme
2fe31ddd84
2 değiştirilmiş dosya ile 10 ekleme ve 14 silme
  1. 1 1
      setup.py
  2. 9 13
      wagtail/admin/rich_text/converters/contentstate.py

+ 1 - 1
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",

+ 9 - 13
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 render(self, props):
-        # Do not process matches inside code blocks.
-        if props['block']['type'] == BLOCK_TYPES.CODE:
-            return props['children']
+def br(props):
+    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: