Update serialize-doctype.ts

This commit is contained in:
Jun 2022-02-25 14:59:30 -08:00 committed by GitHub
parent 50d61960c2
commit a6fee57c11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,8 +23,7 @@ const htmlEscape = (str: string | null): string => {
return escaped;
}
// @ts-ignore
const createDocType = (ignored: string, doctype?: DocumentType | null): string => {
const createDocType = (doctype?: DocumentType | null): string => {
if (!doctype)
return '<html></html>';
@ -39,7 +38,9 @@ const createDocType = (ignored: string, doctype?: DocumentType | null): string =
let doctypePolicy: TrustedTypePolicy;
if ((window as any).trustedTypes) {
doctypePolicy = (window as any).trustedTypes.createPolicy('html2canvas', {
createHTML: createDocType
createHTML: (ignored: string, doctype?: DocumentType | null): TrustedHTML => {
return createDocType(doctype);
}
});
}
@ -47,6 +48,6 @@ export const serializeDoctype = (doctype?: DocumentType | null): string | Truste
if (doctypePolicy !== undefined) {
return doctypePolicy.createHTML('', doctype);
} else {
return createDocType('', doctype);
return createDocType(doctype);
}
}