Skip to content

Commit

Permalink
Trailing newline whitespace should result in a space in text nodes (#142
Browse files Browse the repository at this point in the history
)

* failing test case for missing whitespace

* trailing newline whitespace should result in a space
  • Loading branch information
lachenmayer authored and ungoldman committed May 13, 2019
1 parent 5350635 commit 1b115a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/append-child.js
Expand Up @@ -99,7 +99,7 @@ module.exports = function appendChild (el, childs) {
VERBATIM_TAGS.indexOf(nodeName) === -1) {
value = lastChild.nodeValue
.replace(leadingNewlineRegex, '')
.replace(trailingNewlineRegex, '')
.replace(trailingNewlineRegex, ' ')
.replace(multiSpaceRegex, ' ')

// Remove empty text nodes, append otherwise
Expand Down
12 changes: 12 additions & 0 deletions tests/browser/elements.js
Expand Up @@ -156,6 +156,18 @@ test('space between text and non-text nodes', function (t) {
t.end()
})

test('space between text followed by non-text nodes', function (t) {
t.plan(1)
var result = html`
<p>
whitespace
<strong>is strong</strong>
</p>
`
t.equal(result.outerHTML, '<p>whitespace <strong>is strong</strong></p>', 'should have correct output')
t.end()
})

test('space between non-text nodes', function (t) {
t.plan(1)
var result = html`
Expand Down

0 comments on commit 1b115a6

Please sign in to comment.