Delete serialize-doctype.ts

This commit is contained in:
Jun 2023-01-12 09:45:40 -08:00 committed by GitHub
parent 33b3f272b0
commit 90ef576ad9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 0 additions and 54 deletions

View File

@ -1,54 +0,0 @@
/// <reference types="trusted-types"/>
const htmlEscape = (str: string | null): string => {
if (!str)
return '';
let escaped: string = '';
str.split('').forEach(char => {
if (char == '&') {
char = '&amp;';
} else if (char == '\'') {
char = '&#039;';
} else if (char == '"') {
char = '&quot;';
} else if (char == '<') {
char = '&lt;';
} else if (char == '>') {
char = '&gt;';
}
escaped += char;
});
return escaped;
}
const createDocType = (doctype?: DocumentType | null): string => {
if (!doctype)
return '<html></html>';
const name = htmlEscape(doctype.name);
const internalSubset = htmlEscape(doctype.internalSubset);
const publicId = doctype.publicId ? `"${htmlEscape(doctype.publicId)}"` : '';
const systemId = doctype.systemId ? `"${htmlEscape(doctype.systemId)}"` : '';
return `<!DOCTYPE ${name}${internalSubset}${publicId}${systemId}><html></html>`;
}
let doctypePolicy: TrustedTypePolicy;
if ((window as any).trustedTypes) {
doctypePolicy = (window as any).trustedTypes.createPolicy('html2canvas', {
// @ts-ignore
createHTML: (ignored: string, doctype?: DocumentType | null): string => {
return createDocType(doctype);
}
});
}
export const serializeDoctype = (doctype?: DocumentType | null): string | TrustedHTML => {
if (doctypePolicy !== undefined) {
return doctypePolicy.createHTML('', doctype);
} else {
return createDocType(doctype);
}
}