File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change 11<script >
2+ import { onMount } from ' svelte' ;
23 export let content;
4+ export const id = ' _' + Math .random ().toString (36 ).substr (2 , 9 );
5+
6+ const setInnerHTML = function (elm , html ) {
7+ elm .innerHTML = html;
8+
9+ Array .from (elm .querySelectorAll (' script' )).forEach (oldScript => {
10+ const newScript = document .createElement (' script' );
11+
12+ Array .from (oldScript .attributes )
13+ .forEach ( attr => newScript .setAttribute (attr .name , attr .value ) );
14+ newScript .appendChild (document .createTextNode (oldScript .innerHTML ));
15+ oldScript .parentNode .replaceChild (newScript, oldScript);
16+ });
17+ }
18+
19+ onMount (() => {
20+ setInnerHTML (document .getElementById (id), content)
21+ });
322 </script >
423
5- { @html content }
24+ < div id ={ id }></ div >
You can’t perform that action at this time.
0 commit comments