Update serialize-doctype.ts

This commit is contained in:
Jun 2022-02-24 16:29:46 -08:00 committed by GitHub
parent d0e63a8f56
commit 89998e258f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,7 +4,7 @@ const htmlEscape = (str: string | null): string => {
if (!str)
return '';
const escaped = [];
let escaped: string = '';
str.split('').forEach(char => {
if (char == '&') {
char = '&';
@ -17,13 +17,14 @@ const htmlEscape = (str: string | null): string => {
} else if (char == '>') {
char = '>';
}
escaped.push(char);
escaped += char;
});
return escaped.join('');
return escaped;
}
const docRule: TrustedTypePolicyOptions = {
// @ts-ignore
createHTML: (ignored: string, doctype?: DocumentType | null): string => {
if (!doctype)
return '<html></html>';
@ -37,13 +38,11 @@ const docRule: TrustedTypePolicyOptions = {
}
}
let doctypePolicy: TrustedTypePolicy | TrustedTypePolicyOptions;
let doctypePolicy: TrustedTypePolicy | TrustedTypePolicyOptions = docRule;
if ((window as any).trustedTypes) {
doctypePolicy = (window as any).trustedTypes.createPolicy('html2canvas', docRule);
} else {
doctypePolicy = docRule;
}
export const serializeDoctype = (doctype?: DocumentType | null): string => {
doctypePolicy.createHTML('', doctype);
return doctypePolicy.createHTML('', doctype);
}