From 19663e3b7378d22410dc3ea4b23ed3d6d1ec0480 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Mon, 1 May 2017 17:15:57 +0200 Subject: [PATCH] strip empty text nodes --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 09f2787..2c00571 100644 --- a/index.js +++ b/index.js @@ -131,11 +131,12 @@ function belCreateElement (tag, props, children) { } if (typeof node === 'string') { + if (/^[\S+\n\r\s]+$/.test(node)) continue if (el.lastChild && el.lastChild.nodeName === '#text') { - el.lastChild.nodeValue += node + el.lastChild.nodeValue += node.trim() continue } - node = document.createTextNode(node) + node = document.createTextNode(node.trim()) } if (node && node.nodeType) {