Skip to content

tiddly-gittly/zx-script

Repository files navigation

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]]