Use explicit HTML document boilerplate to get consistent results in browser and linkedom (for SSR)

Context:

 - https://github.com/WebReflection/linkedom/issues/106
 - https://github.com/WebReflection/linkedom/pull/108
This commit is contained in:
Eric Eastwood 2022-02-11 19:23:45 -06:00
parent e75f18c87a
commit 48825ea30f
1 changed files with 1 additions and 3 deletions

View File

@ -64,9 +64,7 @@ export function parseHTML(html) {
// If DOMPurify uses DOMParser, can't we just get the built tree from it
// instead of re-parsing?
const sanitized = DOMPurify.sanitize(html, sanitizeConfig);
// FIXME: DOMParser from linkedom does not behave the same as the browser,
// see https://github.com/WebReflection/linkedom/issues/106
const bodyNode = new DOMParser().parseFromString(`<body>${sanitized}</body>`, "text/html").documentElement;
const bodyNode = new DOMParser().parseFromString(`<!DOCTYPE html><html><body>${sanitized}</body></html>`, "text/html").body;
return new HTMLParseResult(bodyNode);
}