tiddly-gittly / zx-script

Run Javascript inside tiddlywiki like jupyter notebook
https://tiddly-gittly.github.io/zx-script/
MIT License
3 stars 0 forks source link
code-execution interactive ipython-notebook javascript jupyter-notebook literate-programming neteract playground tiddlywiki tiddlywiki5 tidgi zx

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

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:

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

/** tw */
const result = $tw.wiki.filterOperators.sum((callback) => {callback({}, '2');callback({}, '2')})
console.log(result)

!! Developer Documentation

See [[$:/plugins/linonetwo/zx-script/developer]]