Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML make your own <script type="text/language">?

Javascript is put in text/javascript and Coffeescript also has support for it, but I was wondering it there was a way to make my own? I'd like to make a Golfscript interpreter that anyone can do <script type="text/golfscript"> for and it would be put through the interpreter.

like image 821
jado Avatar asked Dec 19 '22 02:12

jado


1 Answers

Leaving aside the (usually) unrealistic options of persuading all your users to install a browser extension or custom browser…

The only way you can do this is with a programming language already supported by the browser. In most cases that means JavaScript.

You can access the content of the element through the DOM:

document.querySelector('script[type="text/golfscript"]').textContent

… and then have a parser and interpreter written in JS.

You will probably want to use querySelectorAll and a loop.


NB: text/golfscript doesn't appear to be a registered MIME type. You'll probably want to use the x prefix to mark it as experimental and use application since it is a programming language: application/x-golfscript.

like image 100
Quentin Avatar answered Dec 24 '22 02:12

Quentin