Skip to content

Commit 38b4869

Browse files
authored
Merge pull request #433 from antfu/feat/runtime
feat: support browser runtime
2 parents 889103e + 231b2bf commit 38b4869

File tree

7 files changed

+980
-277
lines changed

7 files changed

+980
-277
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ You can now translate JavaScript to wenyan-lang using the [wenyanizer](https://g
9595
- [Plugin for Vim](https://github.com/voldikss/vim-wenyan) by [voldikss](https://github.com/voldikss)
9696
- [Plugin for Sublime Text](https://github.com/absop/SublimeWenyan) by [absop](https://github.com/absop)
9797

98+
### Browser Runtime
99+
100+
You can now run Wenyan scripts right in your html file.
101+
102+
Please refer to [Browser Runtime](./documentation/Runtime.md)
103+
98104
### Advance Usage
99105

100106
[Compiler API Specification](./documentation/Compiler-API.md)

documentation/Runtime.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[Back to README](../README.md)
2+
3+
# Wenyan Browser Runtime
4+
5+
You can now run Wenyan as normal Javscript script right in your html.
6+
7+
[**Check out the demo**](https://jsfiddle.net/antfu/u532ny49/2/)
8+
9+
## Installation
10+
11+
Add following script in the `<head>` of your html file.
12+
13+
```html
14+
<script src='https://unpkg.com/@wenyanlang/runtime'></script>
15+
```
16+
17+
That's all, you are good to go!
18+
19+
## Usage
20+
21+
To use wenyan in script, you **HAVE TO** specify `type="application/wenyan"` for the `<script>` tag. For example:
22+
23+
```html
24+
<script type="application/wenyan">
25+
吾有一數。曰三。名之曰「甲」。
26+
為是「甲」遍。
27+
吾有一言。曰「「問天地好在。」」。書之。
28+
云云。
29+
</script>
30+
```
31+
32+
### Scoped script
33+
34+
By default, all the variables in wenyan will exposed globally. For the previous example, `` is accessible by `window.甲`. If you do not want to messed up your globals, you can specify the `scoped` attr.
35+
36+
```html
37+
<script type="application/wenyan" scoped>
38+
吾有一數。曰三。名之曰「甲」。
39+
</script>
40+
```
41+
42+
### Remote scripts
43+
44+
You can import remote scripts as you will do for Javascript.
45+
46+
```html
47+
<script type="application/wenyan" src="https://raw.githubusercontent.com/LingDong-/wenyan-lang/master/examples/fizzbuzz.wy"></script>
48+
```
49+
50+
### DOM Hacks
51+
52+
There are some hacks you can do to access the DOM and browser APIs. This allows wenyan to do some realworld applications.
53+
54+
```html
55+
<script type="application/wenyan">
56+
施「((title)=>document.title=title)」於「「文言」」。
57+
施「((text)=>document.body.innerText=text)」於「「問天地好在。」」。
58+
</script>
59+
```

0 commit comments

Comments
 (0)