No, you canβt. The best thing you could do is have a script that changes another script with an invalid type and changes it to a valid type so that you get an effect like.
<script type="text/x-algolscript"> function hello() begin alert("Hello, world!"); end hello(); </script> <script type="text/javascript"> Array.prototype.forEach.call(document.getElementsByTagName('script'), function(script) { if(script.type === 'text/x-algolscript') { var oldParent = script.parentNode; var oldNext = script.nextSibling; oldParent.removeChild(script); script.textContent = script.textContent.replace(/\bbegin\b/g, '{').replace(/\bend\b/g, '}'); script.type = 'text/javascript'; oldParent.insertBefore(script, oldNext); } }); </script>
It does not depend on the context, and will happily change your lines, etc.
Bonus: Minimum and more browser compatible version:
!function(s,i,t,e,l,p,o,n){for(l=s.length;i<l;i++)((e=s[i]).type==='text/x-algolscript')&&t.push(e);for(i=0;i<t.length;i++)o=(e=t[i]).parentNode,n=e.nextSibling,o.removeChild(e),p='textContent',e[p]||(p='innerText'),e[p]=e[p].replace(/\bbegin\b/,'{').replace(/\bend\b/,'}'),e.type='text/javascript',o.insertBefore(e,n)}(document.getElementsByTagName('script'),0,[]);
source share