-
Notifications
You must be signed in to change notification settings - Fork 99
DOMParser.parseFromString(...) does not insert HTML into <html><body> document boilerplate #106
Copy link
Copy link
Closed
Description
DOMParser.parseFromString(...) does not insert HTML into the <html><body>...</body></html> document boilerplate which makes grabbing nodes inside inconsistent from the browser.
Tested in Chrome and Firefox (expected):
new DOMParser().parseFromString(`<div>asdf</div>`, "text/html").documentElement.outerHTML
// '<html><head></head><body><div>asdf</div></body></html>'
new DOMParser().parseFromString(`<div>asdf</div>`, "text/html").body.outerHTML
// '<body><div>asdf</div></body>'
new DOMParser().parseFromString(`<html><body><div>asdf</div></body></html>`, "text/html").body.outerHTML
// '<body><div>asdf</div></body>'linkeddom (actual):
import {DOMParser} from 'linkedom';
new DOMParser().parseFromString(`<div>asdf</div>`, "text/html").documentElement.outerHTML
// <div>asdf</div>
new DOMParser().parseFromString(`<div>asdf</div>`, "text/html").body.outerHTML
// <body></body>
new DOMParser().parseFromString(`<html><body><div>asdf</div></body></html>`, "text/html").body.outerHTML
// '<body></body>'For reference: I am using linkedom to server-side render (SSR) https://github.com/vector-im/hydrogen-web which uses the DOMParser for some of its templating, see src/platform/web/parsehtml.js#L67. Project is at: https://github.com/matrix-org/matrix-public-archive and linkedom usage is in server/render-hydrogen-to-string.js.
Relevant code
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels