plone / blocks-conversion-tool

A tool to convert HTML (as used in Plone Classic) to Blocks (as used on Volto)
7 stars 5 forks source link

Handling of div is problematic #17

Closed pbauer closed 1 year ago

pbauer commented 1 year ago

This text: "<div><b>Foo</b> <br /><br />Bar</div>"

Creates the following blocks:

{'1e09e7a9-9bb1-47bc-a3e5-f982d2424dfe': {'@type': 'slate', 'plaintext': '', 'value': ['\n']},
 '4e4d3c39-7eec-469f-977b-0bc93cd97d3e': {'@type': 'slate', 'plaintext': 'Foo', 'value': [{'children': [{'text': 'Foo'}], 'type': 'strong'}]},
 'd0e71e76-332c-480d-8e32-1623ecb32179': {'@type': 'slate', 'plaintext': '', 'value': ['\n']}}

Bar is missing and the ['\n'] create these tracebacks:

Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 167, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 376, in publish_module
  Module ZPublisher.WSGIPublisher, line 271, in publish
  Module ZPublisher.mapply, line 85, in mapply
  Module Products.PDBDebugMode.wsgi_runcall, line 60, in pdb_runcall
  Module plone.rest.service, line 22, in __call__
  Module plone.restapi.services, line 19, in render
  Module plone.restapi.services.content.get, line 16, in reply
  Module plone.restapi.serializer.dxcontent, line 159, in __call__
  Module plone.restapi.serializer.dxcontent, line 111, in __call__
  Module plone.restapi.serializer.blocks, line 82, in __call__
  Module plone.restapi.serializer.blocks, line 69, in apply_block_serialization_transforms
  Module plone.restapi.deserializer.blocks, line 265, in __call__
AttributeError: 'str' object has no attribute 'get'

Without the line-breaks it is also broken:

"<div><b>Foo</b> Bar</div>" drops the Bar:

{'ea9dff8a-7164-42dd-95a0-d57f49621bd1': {'@type': 'slate', 'plaintext': 'Foo', 'value': [{'children': [{'text': 'Foo'}], 'type': 'strong'}]}}

Inside a <p> the result is ok: <p><b>Foo</b> <br /><br />Bar</p>

{'5868681d-3aea-4e41-b3cf-d95affacf945': {'@type': 'slate',
                                          'plaintext': 'Foo Bar',
                                          'value': [{'children': [{'children': [{'text': 'Foo'}], 'type': 'strong'}, {'text': '\n\nBar'}],
                                                     'type': 'p'}]}}

Example: https://plone.org/foundation/materials/privacy