mirror of https://github.com/sveltejs/svelte
parent
eb530c82c4
commit
5673d60424
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Add TrustedTypes support
|
@ -1,6 +1,25 @@
|
|||||||
|
/** @import { TrustedTypePolicy } from 'trusted-types' */
|
||||||
|
|
||||||
|
/** @type {Pick<TrustedTypePolicy, 'createHTML'> | undefined} */
|
||||||
|
let policy;
|
||||||
|
|
||||||
|
if (globalThis?.window?.trustedTypes) {
|
||||||
|
policy = globalThis.window.trustedTypes.createPolicy('svelte-trusted-html', {
|
||||||
|
/** @param {string} html */
|
||||||
|
createHTML: (html) => {
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param {string} html */
|
||||||
|
function create_trusted_html(html) {
|
||||||
|
return /** @type {string} */(policy?.createHTML(html) ?? html);
|
||||||
|
}
|
||||||
|
|
||||||
/** @param {string} html */
|
/** @param {string} html */
|
||||||
export function create_fragment_from_html(html) {
|
export function create_fragment_from_html(html) {
|
||||||
var elem = document.createElement('template');
|
var elem = document.createElement('template');
|
||||||
elem.innerHTML = html.replaceAll('<!>', '<!---->'); // XHTML compliance
|
elem.innerHTML = create_trusted_html(html.replaceAll('<!>', '<!---->')); // XHTML compliance
|
||||||
return elem.content;
|
return elem.content;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue