Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to serialize as HTML instead of XML #22

Merged
merged 3 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions packages/rehype-dom-stringify/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,8 @@ function serialize(node) {
return '<DOCTYPE html>'
}

// Element.
if ('outerHTML' in node) {
return node.outerHTML
}

// Comment, text, fragment.
if ('textContent' in node) {
const div = document.createElement('div')
div.append(node)
return div.innerHTML
/* c8 ignore next 4 */
}

// ?
return ''
// Comment, element, fragment, text.
const template = document.createElement('template')
template.content.append(node)
ChristianMurphy marked this conversation as resolved.
Show resolved Hide resolved
return template.innerHTML
}
8 changes: 4 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ test('parse', async (t) => {
.data('settings', {fragment: false})
.processSync('<title>Hi</title><h2>Hello world!')
.toString(),
'<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Hi</title></head><body><h2>Hello world!</h2></body></html>',
'<html><head><title>Hi</title></head><body><h2>Hello world!</h2></body></html>',
'should stringify a complete document'
)

Expand All @@ -101,13 +101,13 @@ test('parse', async (t) => {
.data('settings', {fragment: false})
.processSync('<!doctype html>')
.toString(),
'<DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head></head><body></body></html>',
'<DOCTYPE html><html><head></head><body></body></html>',
'should stringify a doctype'
)

assert.equal(
processor().processSync('<!doctype html>').toString(),
'<DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head></head><body></body></html>',
'<DOCTYPE html><html><head></head><body></body></html>',
'should support empty documents'
)

Expand Down Expand Up @@ -184,7 +184,7 @@ test('parse', async (t) => {
.data('settings', {fragment: false})
.processSync('<title>Hi</title><h2>Hello world!')
.toString(),
'<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Hi</title></head><body><h2>Hello world!</h2></body></html>',
'<html><head><title>Hi</title></head><body><h2>Hello world!</h2></body></html>',
'should parse a complete document'
)

Expand Down
Loading