block-content-to-hyperscript icon indicating copy to clipboard operation
block-content-to-hyperscript copied to clipboard

feat: add config option for opting out of wrapper container

Open runeb opened this issue 3 years ago • 1 comments

Adds renderContainer option which defaults to true and the current behaviour. If set to false we simply return the innerHTML of the normal rendering, thus avoiding the wrapping element. This was deemed to be the least intrusive way to achieve this feature.

Unsure, however, if it is okay for this module to return a string versus a node with children. But the frequent usage of rootNode.outerHTML || rootNode in both this test suite and in downstream modules indicate that the contract is not all that clear to begin with.

runeb avatar Jan 27 '22 19:01 runeb

Possibly it would be best to just have the consumers of this module do this unwrapping themselves, but unfortunately this module is often not used directly, but through convenience modules like block-content-to-html and those modules do this before the user has a chance to modify the node tree:

https://github.com/sanity-io/block-content-to-html/blob/main/src/blocksToHtml.js#L6

  return rootNode.outerHTML || rootNode

runeb avatar Jan 27 '22 19:01 runeb