diff --git a/src/directives/html.ts b/src/directives/html.ts index c503313..e91c468 100644 --- a/src/directives/html.ts +++ b/src/directives/html.ts @@ -1,7 +1,21 @@ +import { nextTick } from '../scheduler' import { Directive } from '.' -export const html: Directive = ({ el, get, effect }) => { +export const html: Directive = ({ el, modifiers, get, effect }) => { effect(() => { el.innerHTML = get() + if (modifiers?.script) { + nextTick(() => { + const cs = el.querySelectorAll('script') + for (const oldScript of cs) { + const newScript = document.createElement('script') + oldScript.type && (newScript.type = oldScript.type) + oldScript.src && (newScript.src = oldScript.src) + oldScript.text && (newScript.text = oldScript.text) + oldScript.parentElement?.insertBefore(newScript, oldScript) + oldScript.remove() + } + }) + } }) } diff --git a/tests/html.html b/tests/html.html index ae86bf3..8a7d44f 100644 --- a/tests/html.html +++ b/tests/html.html @@ -7,3 +7,7 @@

+
+

+
+