wix-incubator / react-templates

Light weight templates for react
https://wix.github.io/react-templates
MIT License
2.82k stars 206 forks source link

Option for trimming white-space #146

Closed nippur72 closed 8 years ago

nippur72 commented 8 years ago

In order to keep the generated code small, I propose to trim out white-spaces on all tags except <pre> or when the special rt-pre attribute is specified.

For backward compatibility, the trimming would be enabled via the switch --trim-white-space.

Example:

<div>
   Hello
</div>

would result into:

return React.createElement('div', {}, '\n   Hello\n');  // old way
return React.createElement('div', {}, 'Hello');         // --trim-white-space

Also:

<div rt-pre>
   Hello
</div>

into:

return React.createElement('div', {}, '\n   Hello\n');  // even if --trim-white-space is specified
nippur72 commented 8 years ago

I have a PR for this waiting to be pulled.

I use normalize-html-whitespace for processing text content.