Skip to content

Commit

Permalink
Use explicit HTML document boilerplate to get consistent results in b…
Browse files Browse the repository at this point in the history
…rowser and linkedom (for SSR)

Context:

 - WebReflection/linkedom#106
 - WebReflection/linkedom#108
  • Loading branch information
MadLittleMods committed Feb 12, 2022
1 parent e75f18c commit 48825ea
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/platform/web/parsehtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 48825ea

Please sign in to comment.