Skip to content

Commit 418a992

Browse files
authored
Fix serializing empty fragment
Closes GH-26. Reviewed-by: Titus Wormer <[email protected]>
1 parent a97897d commit 418a992

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/rehype-dom-stringify/lib/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function serialize(node) {
4444
// Document.
4545
if ('doctype' in node) {
4646
const doctype = node.doctype ? serialize(node.doctype) : ''
47-
const docelem = serialize(node.documentElement)
47+
const docelem = node.documentElement ? serialize(node.documentElement) : ''
4848
return doctype + docelem
4949
}
5050

test.js

+10
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ test('rehype-dom-stringify', async function (t) {
125125
)
126126
})
127127

128+
await t.test('should support empty fragment', async function () {
129+
assert.equal(
130+
processor()
131+
.data('settings', {fragment: true})
132+
.processSync('')
133+
.toString(),
134+
''
135+
)
136+
})
137+
128138
await t.test('should stringify a fragment', async function () {
129139
assert.equal(
130140
processor()

0 commit comments

Comments
 (0)