sanity-io / block-content-to-hyperscript

Function for transforming Sanity block content to HyperScript
MIT License
17 stars 8 forks source link

feat: add config option for opting out of wrapper container #25

Open runeb opened 2 years ago

runeb commented 2 years ago

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 commented 2 years ago

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