Skip to content

Commit

Permalink
fix whitespace creation
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshuawuyts committed May 17, 2017
1 parent 3a05345 commit 049ca61
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,23 @@ function belCreateElement (tag, props, children) {
}

if (typeof node === 'string') {
if (/^[\n\r\s]+$/.test(node)) continue
if (el.lastChild && el.lastChild.nodeName === '#text') {
el.lastChild.nodeValue += node
// - if empty space, skip
// - if last node was a text node
// - if current node is a newline, push a space
// - else push the node value
// - else create a text node with the new text
if (/^[\r\s]+$/.test(node)) {
continue
} else if (el.lastChild && el.lastChild.nodeName === '#text') {
if (/^[\n]+$/.test(node)) {
el.lastChild.nodeValue += ' '
} else {
el.lastChild.nodeValue += node
}
continue
} else {
node = document.createTextNode(node)
}
node = document.createTextNode(node)
}

if (node && node.nodeType) {
Expand Down

0 comments on commit 049ca61

Please sign in to comment.