preact-render-to-string icon indicating copy to clipboard operation
preact-render-to-string copied to clipboard

Add option to preserve whitespace for certain elements

Open sventschui opened this issue 4 years ago • 6 comments

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

sventschui avatar Jun 02 '20 13:06 sventschui

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

sventschui avatar Jun 02 '20 14:06 sventschui

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.

sventschui avatar Jun 03 '20 06:06 sventschui

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 avatar Nov 16 '20 15:11 natemoo-re

@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 avatar Feb 05 '21 02:02 developit

@developit I was at the time! We've since moved to formatting the output as a separate step for other reasons.

natemoo-re avatar Feb 05 '21 03:02 natemoo-re

@natemoo-re ah okay, good. I'd like to remove this from the default render to string implementation.

developit avatar Feb 05 '21 04:02 developit