Skip to content

Commit e26628c

Browse files
committed
Fix SVG attributes on svg element in HTML
Closes rehypejs/rehype#56.
1 parent 240f877 commit e26628c

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Diff for: lib/element.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ function serializeElement(ctx, node, index, parent) {
2020
schema.space === 'svg'
2121
? ctx.closeEmpty
2222
: ctx.voids.indexOf(node.tagName.toLowerCase()) > -1
23-
var attrs = serializeAttributes(ctx, node.properties)
23+
var attrs
2424
var content
2525
var last
2626

2727
if (schema.space === 'html' && node.tagName === 'svg') {
2828
ctx.schema = svg
2929
}
3030

31+
attrs = serializeAttributes(ctx, node.properties)
32+
3133
content = all(
3234
ctx,
3335
schema.space === 'html' && node.tagName === 'template' ? node.content : node

Diff for: test/svg.js

+19
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,25 @@ test('svg', function (t) {
308308
'should serialize an SVG tree'
309309
)
310310

311+
t.deepEqual(
312+
to(
313+
h('div', [
314+
s(
315+
'svg',
316+
{
317+
xlmns: 'http://www.w3.org/2000/svg',
318+
strokeLineCap: 'round',
319+
strokeLineJoin: 'round',
320+
viewBox: [0, 0, 8, 8]
321+
},
322+
[s('path', {stroke: 'blue', d: 'M0 6V3h1l1 1v2'})]
323+
)
324+
])
325+
),
326+
'<div><svg xlmns="http://www.w3.org/2000/svg" stroke-linecap="round" stroke-linejoin="round" viewBox="0 0 8 8"><path stroke="blue" d="M0 6V3h1l1 1v2"></path></svg></div>',
327+
'should serialize SVG props on an `svg` element in HTML'
328+
)
329+
311330
t.deepEqual(
312331
to(
313332
u('root', [

0 commit comments

Comments
 (0)