Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tiddly-gittly/zx-script

Run Javascript inside tiddlywiki like jupyter notebook
https://github.com/tiddly-gittly/zx-script

code-execution interactive ipython-notebook javascript jupyter-notebook literate-programming neteract playground tiddlywiki tiddlywiki5 tidgi zx

Last synced: about 1 month ago
JSON representation

Run Javascript inside tiddlywiki like jupyter notebook

Awesome Lists containing this project

README

        

title: $:/plugins/linonetwo/zx-script/readme
created: 20210915220048497
type: text/vnd.tiddlywiki

!! 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.

!! Basic Usage

!!! Prerequisit

This plugin requires [TidGi](https://github.com/tiddly-gittly/TidGi-Desktop) Desktop App environment to function properly. It will send tiddler content to the `zx` inside TidGi, and prints the output.

!!! Tiddler Type

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`.

!!! 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.

!!! Demo

```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.

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