@@ -20,6 +20,7 @@ const noop = () => {};
20
20
* @param {Boolean } [options.shallow=false] If `true`, renders nested Components as HTML elements (`<Foo a="b" />`).
21
21
* @param {Boolean } [options.xml=false] If `true`, uses self-closing tags for elements without children.
22
22
* @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.
23
24
*/
24
25
renderToString . render = renderToString ;
25
26
@@ -51,7 +52,7 @@ function renderToString(vnode, context, opts, inner, isSvgMode, selectValue) {
51
52
context = context || { } ;
52
53
opts = opts || { } ;
53
54
54
- let pretty = opts . pretty ,
55
+ let pretty = ( opts . preserveWhitespace || [ 'pre' ] ) . indexOf ( nodeName ) === - 1 && opts . pretty ,
55
56
indentChar = pretty && typeof pretty === 'string' ? pretty : '\t' ;
56
57
57
58
// #text nodes
@@ -73,7 +74,7 @@ function renderToString(vnode, context, opts, inner, isSvgMode, selectValue) {
73
74
for ( let i = 0 ; i < children . length ; i ++ ) {
74
75
rendered += ( i > 0 && pretty ? '\n' : '' ) + renderToString ( children [ i ] , context , opts , opts . shallowHighOrder !== false , isSvgMode , selectValue ) ;
75
76
}
76
- return rendered ;
77
+ return indent ( rendered , indentChar ) ;
77
78
}
78
79
else {
79
80
let rendered ;
@@ -269,7 +270,7 @@ function renderToString(vnode, context, opts, inner, isSvgMode, selectValue) {
269
270
}
270
271
if ( pretty && hasLarge ) {
271
272
for ( let i = pieces . length ; i -- ; ) {
272
- pieces [ i ] = '\n' + indentChar + indent ( pieces [ i ] , indentChar ) ;
273
+ pieces [ i ] = '\n' + indentChar + pieces [ i ] ;
273
274
}
274
275
}
275
276
}
0 commit comments