Skip to content

Commit e12dd21

Browse files
committed
trim empty textNodes when extracting inline template (fix #949)
1 parent f90b693 commit e12dd21

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/util/dom.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ exports.extractContent = function (el, asFragment) {
183183
el = el.content
184184
}
185185
if (el.hasChildNodes()) {
186+
trim(el, el.firstChild)
187+
trim(el, el.lastChild)
186188
rawContent = asFragment
187189
? document.createDocumentFragment()
188190
: document.createElement('div')
@@ -194,6 +196,12 @@ exports.extractContent = function (el, asFragment) {
194196
return rawContent
195197
}
196198

199+
function trim (content, node) {
200+
if (node && node.nodeType === 3 && !node.data.trim()) {
201+
content.removeChild(node)
202+
}
203+
}
204+
197205
/**
198206
* Check if an element is a template tag.
199207
* Note if the template appears inside an SVG its tagName
@@ -205,4 +213,4 @@ exports.extractContent = function (el, asFragment) {
205213
exports.isTemplate = function (el) {
206214
return el.tagName &&
207215
el.tagName.toLowerCase() === 'template'
208-
}
216+
}

0 commit comments

Comments
 (0)