File tree Expand file tree Collapse file tree 1 file changed +13
-16
lines changed
Expand file tree Collapse file tree 1 file changed +13
-16
lines changed Original file line number Diff line number Diff line change 11<script >
2- import { onMount } from ' svelte' ;
2+ import { afterUpdate } from ' svelte' ;
33 export let payload;
4+ let container;
45
5- const executeJS = function () {
6- document . body .querySelectorAll (' .html-code ' ) .forEach (element => {
7- element . classList . remove ( ' html-code ' );
6+ const executeJS = function (element ) {
7+ Array . from ( element .querySelectorAll (' script ' )) .forEach (oldScript => {
8+ const newScript = document . createElement ( ' script ' );
89
9- Array .from (element .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- })
10+ Array .from (oldScript .attributes )
11+ .forEach ( attr => newScript .setAttribute (attr .name , attr .value ) );
12+ newScript .appendChild (document .createTextNode (oldScript .innerHTML ));
13+ oldScript .parentNode .replaceChild (newScript, oldScript);
14+ });
1815 }
1916
20- onMount (() => {
21- executeJS ();
17+ afterUpdate (() => {
18+ executeJS (container );
2219 });
2320 </script >
2421
25- <div class =" html-code" >
22+ <div class ="html-code" bind:this ={ container } >
2623 {@html payload .content }
2724</div >
You can’t perform that action at this time.
0 commit comments