mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Delete serialize-doctype.ts
This commit is contained in:
parent
33b3f272b0
commit
90ef576ad9
@ -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 = '&';
|
|
||||||
} else if (char == '\'') {
|
|
||||||
char = ''';
|
|
||||||
} else if (char == '"') {
|
|
||||||
char = '"';
|
|
||||||
} else if (char == '<') {
|
|
||||||
char = '<';
|
|
||||||
} else if (char == '>') {
|
|
||||||
char = '>';
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user