Skip to content

Commit df7c680

Browse files
committed
Make voidElements option additive
1 parent e5573ed commit df7c680

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const SHALLOW = { shallow: true };
66
// components without names, kept as a hash for later comparison to return consistent UnnamedComponentXX names.
77
const UNNAMED = [];
88

9-
const DEFAULT_VOID_ELEMENTS = /^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/;
9+
const VOID_ELEMENTS = /^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/;
1010

1111
const noop = () => {};
1212

@@ -20,7 +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 {RegEx} [options.voidElements=DEFAULT_VOID_ELEMENTS] RegeEx that matches elements that are considered void (self-closing)
23+
* @param {RegEx|undefined} [options.voidElements] RegeEx that matches elements that are considered void (self-closing)
2424
*/
2525
renderToString.render = renderToString;
2626

@@ -220,7 +220,7 @@ function renderToString(vnode, context, opts, inner, isSvgMode, selectValue) {
220220
s = `<${nodeName}${s}>`;
221221
if (String(nodeName).match(/[\s\n\\/='"\0<>]/)) throw new Error(`${nodeName} is not a valid HTML tag name in ${s}`);
222222

223-
let isVoid = String(nodeName).match(opts.voidElements || DEFAULT_VOID_ELEMENTS);
223+
let isVoid = String(nodeName).match(VOID_ELEMENTS) || (opts.voidElements && String(nodeName).match(opts.voidElements));
224224
if (isVoid) s = s.replace(/>$/, ' />');
225225

226226
let pieces = [];

0 commit comments

Comments
 (0)