简体   繁体   English

HTML制作你自己的<script type=“text/language”>?

[英]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? Javascript 放在text/javascript ,Coffeescript 也支持它,但我想知道有没有办法制作我自己的? 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.我想制作一个任何人都可以为<script type="text/golfscript">做的 Golfscript 解释器,它会通过解释器。

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.在大多数情况下,这意味着 JavaScript。

You can access the content of the element through the DOM:您可以通过 DOM 访问元素的内容:

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

… and then have a parser and interpreter written in JS. ...然后有一个用 JS 编写的解析器和解释器。

You will probably want to use querySelectorAll and a loop.您可能想要使用querySelectorAll和一个循环。


NB: text/golfscript doesn't appear to be a registered MIME type.注意: text/golfscript似乎不是已注册的 MIME 类型。 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 .您可能希望使用x前缀将其标记为实验性并使用application因为它是一种编程语言: application/x-golfscript

http://paperjs.org/tutorials/getting-started/working-with-paper-js/ http://paperjs.org/tutorials/getting-started/working-with-paper-js/

These people seem to be doing what you are asking about.这些人似乎正在做你问的事情。 I don't know how, but maybe this will get you started.我不知道如何,但也许这会让你开始。

<!-- Load the Paper.js library -->
<script type="text/javascript" src="js/paper.js"></script>
<!-- Load external PaperScript and associate it with myCanvas -->
<script type="text/paperscript" src="js/myScript.js" canvas="myCanvas">
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM