preact-render-to-string
preact-render-to-string copied to clipboard
Add option to preserve whitespace for certain elements
Add an option to preserve whitespace/indentation for certain elements. Defaults to ['pre']
Caution I'm not 100% sure this doesn't break pretty printing, tests seem fine though.
Fixes #143
It seems the change will break indentation of text nodes. Honestly I'm not sure we can actually change text indent in a safe way. I'd therefore suggest to not indent html (dangerouslySetInnerHtml, string children, etc.) in pretty mode
Just to keep you posted: I'll add the discussion with @marvinhagemeister on slack here publicly:
Marvin mentioned the issue is that we are indenting after rendering instead of during rendering. While trying to change that I ran into issues on how to determine whether we need to wrap/indent text content/children.
This is unfortunately a pretty big issue for microsite
, a Preact-based SSG, since developer blogs with code examples are a big use case. I'd like to keep pretty
enabled in the spirit of the "view source" web.
Any updates?
@natemoo-re Are you using the { pretty: true }
option? It's really only designed for use in things like tests - none of the options for renderToString() are part of the public API.
@developit I was at the time! We've since moved to formatting the output as a separate step for other reasons.
@natemoo-re ah okay, good. I'd like to remove this from the default render to string implementation.