Skip to content

Commit 1f7110f

Browse files
committed
Fix to not add content to template in SVG
Related-to: syntax-tree/hast-util-from-parse5#15. Related-to: syntax-tree/hast-util-from-parse5#16.
1 parent 2dcd77e commit 1f7110f

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎lib/create-h.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ export function createH(schema, defaultTagName, caseSensitive) {
147147
addChild(node.children, child)
148148
}
149149

150-
if (node.type === 'element' && node.tagName === 'template') {
150+
if (
151+
node.type === 'element' &&
152+
node.tagName === 'template' &&
153+
schema.space === 'html'
154+
) {
151155
node.content = {type: 'root', children: node.children}
152156
node.children = []
153157
}

‎test/core.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,20 @@ test('<template>', async function (t) {
980980
}
981981
)
982982
})
983+
984+
await t.test(
985+
'should not move children of a `template` in SVG into `content`',
986+
async function () {
987+
assert.deepEqual(s('template', s('circle')), {
988+
type: 'element',
989+
tagName: 'template',
990+
properties: {},
991+
children: [
992+
{type: 'element', tagName: 'circle', properties: {}, children: []}
993+
]
994+
})
995+
}
996+
)
983997
})
984998

985999
test('svg', async function (t) {

0 commit comments

Comments
 (0)