mirror of https://github.com/sveltejs/svelte
Merge 0be07cac3d
into 2344b4052e
commit
430a0a2517
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': minor
|
||||
---
|
||||
|
||||
Add TrustedTypes support
|
@ -1,6 +1,27 @@
|
||||
/** @import { TrustedTypePolicy } from 'trusted-types' */
|
||||
|
||||
const policy = /* @__PURE__ */ globalThis?.window?.trustedTypes?.createPolicy(
|
||||
'svelte-trusted-html',
|
||||
{
|
||||
/** @param {string} html */
|
||||
createHTML: (html) => {
|
||||
return html;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/** @param {string} html */
|
||||
export function create_fragment_from_html(html) {
|
||||
function create_trusted_html(html) {
|
||||
return /** @type {string} */ (policy?.createHTML(html) ?? html);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} html
|
||||
* @param {boolean} untrusted
|
||||
*/
|
||||
export function create_fragment_from_html(html, untrusted = false) {
|
||||
var elem = document.createElement('template');
|
||||
elem.innerHTML = html.replaceAll('<!>', '<!---->'); // XHTML compliance
|
||||
html = html.replaceAll('<!>', '<!---->'); // XHTML compliance
|
||||
elem.innerHTML = untrusted ? html : create_trusted_html(html);
|
||||
return elem.content;
|
||||
}
|
||||
|
Loading…
Reference in new issue