mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Update serialize-doctype.ts
This commit is contained in:
parent
d0e63a8f56
commit
89998e258f
@ -4,7 +4,7 @@ const htmlEscape = (str: string | null): string => {
|
|||||||
if (!str)
|
if (!str)
|
||||||
return '';
|
return '';
|
||||||
|
|
||||||
const escaped = [];
|
let escaped: string = '';
|
||||||
str.split('').forEach(char => {
|
str.split('').forEach(char => {
|
||||||
if (char == '&') {
|
if (char == '&') {
|
||||||
char = '&';
|
char = '&';
|
||||||
@ -17,13 +17,14 @@ const htmlEscape = (str: string | null): string => {
|
|||||||
} else if (char == '>') {
|
} else if (char == '>') {
|
||||||
char = '>';
|
char = '>';
|
||||||
}
|
}
|
||||||
escaped.push(char);
|
escaped += char;
|
||||||
});
|
});
|
||||||
|
|
||||||
return escaped.join('');
|
return escaped;
|
||||||
}
|
}
|
||||||
|
|
||||||
const docRule: TrustedTypePolicyOptions = {
|
const docRule: TrustedTypePolicyOptions = {
|
||||||
|
// @ts-ignore
|
||||||
createHTML: (ignored: string, doctype?: DocumentType | null): string => {
|
createHTML: (ignored: string, doctype?: DocumentType | null): string => {
|
||||||
if (!doctype)
|
if (!doctype)
|
||||||
return '<html></html>';
|
return '<html></html>';
|
||||||
@ -37,13 +38,11 @@ const docRule: TrustedTypePolicyOptions = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let doctypePolicy: TrustedTypePolicy | TrustedTypePolicyOptions;
|
let doctypePolicy: TrustedTypePolicy | TrustedTypePolicyOptions = docRule;
|
||||||
if ((window as any).trustedTypes) {
|
if ((window as any).trustedTypes) {
|
||||||
doctypePolicy = (window as any).trustedTypes.createPolicy('html2canvas', docRule);
|
doctypePolicy = (window as any).trustedTypes.createPolicy('html2canvas', docRule);
|
||||||
} else {
|
|
||||||
doctypePolicy = docRule;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const serializeDoctype = (doctype?: DocumentType | null): string => {
|
export const serializeDoctype = (doctype?: DocumentType | null): string => {
|
||||||
doctypePolicy.createHTML('', doctype);
|
return doctypePolicy.createHTML('', doctype);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user