-
Notifications
You must be signed in to change notification settings - Fork 0
/
readme.tid
executable file
·62 lines (35 loc) · 2.06 KB
/
readme.tid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
title: $:/plugins/linonetwo/zx-script/readme
!! Background
[[google/zx|https://github.com/google/zx]] is a tool for writing better scripts, with Javascript.
This tiddlywiki plugin enables you to run any tiddler with zx.
!! Prerequisit
This plugin requires [[TidGi Desktop App|https://github.com/tiddly-gittly/TidGi-Desktop]] environment to function properly. It will send tiddler content to the `zx` inside TidGi, and prints the output.
!! Basic Usage
!!! Button
A ViewToolbar button is added. You can click on it to execute the script inside your tiddler.
And the zx output will be printed below your tiddler content.
Tiddler with title extension `*.js *.md *.mjs` can be execute without problem. Other tiddler witout extension (no `.xxx`) will be executed as `*.md` file, for example, tid file without extions will be executed as `*.md`, but it works without problem too, even you are writing wiki text instead of markdown.
If you add filetype `application/javascript` to your tiddler, it will be recognized as `*.mjs`.
!!! Codeblock
An execution button is added to the codeblock widget, if language is supported.
```js
console.log(`!! Hi!`);
```
See [[$:/plugins/linonetwo/zx-script/demo]] for demo of full tiddler execution.
!! Wiki Scripting
!!! Execute the code block on the $tw context
You can write some code that is surrounded with `/** tw */` separator. They will be recognized as js code and executed on the context that have access to the $tw api.
See [[$:/plugins/linonetwo/zx-script/demo]] for examples.
Global variables you can use:
* `$tw` try it in your [[developer tool|https://developer.mozilla.org/en-US/docs/Tools]] to play around!
* `_` [[lodash|https://lodash.com/docs/]]
This means you can fetch some data on the zx script, and write the results to the wiki, creating new tiddlers.
!!! Access filter and macros
Filter function's call example is
```js
/** tw */
const result = $tw.wiki.filterOperators.sum((callback) => {callback({}, '2');callback({}, '2')})
console.log(result)
```
!! Developer Documentation
See [[$:/plugins/linonetwo/zx-script/developer]]