@@ -20,6 +20,7 @@ const noop = () => {};
2020 * @param {Boolean } [options.shallow=false] If `true`, renders nested Components as HTML elements (`<Foo a="b" />`).
2121 * @param {Boolean } [options.xml=false] If `true`, uses self-closing tags for elements without children.
2222 * @param {Boolean } [options.pretty=false] If `true`, adds whitespace for readability
23+ * @param {Boolean } [options.preserveWhitespace=['pre']] Array of HTML tags for which to preserve indentation.
2324 */
2425renderToString . render = renderToString ;
2526
@@ -51,7 +52,7 @@ function renderToString(vnode, context, opts, inner, isSvgMode, selectValue) {
5152 context = context || { } ;
5253 opts = opts || { } ;
5354
54- let pretty = opts . pretty ,
55+ let pretty = ( opts . preserveWhitespace || [ 'pre' ] ) . indexOf ( nodeName ) === - 1 && opts . pretty ,
5556 indentChar = pretty && typeof pretty === 'string' ? pretty : '\t' ;
5657
5758 // #text nodes
@@ -73,7 +74,7 @@ function renderToString(vnode, context, opts, inner, isSvgMode, selectValue) {
7374 for ( let i = 0 ; i < children . length ; i ++ ) {
7475 rendered += ( i > 0 && pretty ? '\n' : '' ) + renderToString ( children [ i ] , context , opts , opts . shallowHighOrder !== false , isSvgMode , selectValue ) ;
7576 }
76- return rendered ;
77+ return indent ( rendered , indentChar ) ;
7778 }
7879 else {
7980 let rendered ;
@@ -269,7 +270,7 @@ function renderToString(vnode, context, opts, inner, isSvgMode, selectValue) {
269270 }
270271 if ( pretty && hasLarge ) {
271272 for ( let i = pieces . length ; i -- ; ) {
272- pieces [ i ] = '\n' + indentChar + indent ( pieces [ i ] , indentChar ) ;
273+ pieces [ i ] = '\n' + indentChar + pieces [ i ] ;
273274 }
274275 }
275276 }
0 commit comments