Action reference

Generated from the action catalogue in packages/core. Every directive also accepts the common options id, title, auto, cascade, delay, scroll, when, substitute, on-error, described in Pages and actions, which also covers the page syntax, inline roles, conditions and how the editor actions point at text. Paths in options are relative to the learner’s workspace, except from, which names a shipped file and is relative to the workshop directory; see paths. The area option of the actions that open something names the layout area it goes in; see where actions open things.

Terminal

Directive

Capability

Body

Options

Description

execute

terminal

required

session, cwd, wait, timeout

Run a command in a named terminal.

execute-capture

kernel-exec

required

capture, cwd, timeout

Run a command in the background and capture its output into a variable.

terminal-open

terminal

none

session, cwd, area

Open or reveal a named terminal, optionally in a layout area.

terminal-clear

terminal

none

session

Clear a named terminal.

terminal-close

terminal

none

session

Close a named terminal and end its session.

terminal-type

terminal

required

session

Type text into a terminal without pressing Enter.

send-key

terminal

none

session, keys

Send key strokes to a terminal.

interrupt

terminal

none

session

Interrupt the command running in a terminal.

Files and editor

Directive

Capability

Body

Options

Description

file-write

write-files

optional

path, open, mode, from, area

Write the body, or a file shipped with the workshop, to a file.

file-open

none

none

path, line, area, factory

Open a file in the editor, optionally at a line, or in another viewer.

file-close

none

none

path

Close every editor and preview showing a file.

file-delete

write-files

none

path, recursive, missing

Delete a file, or a directory and its contents, closing its tabs.

file-rename

write-files

none

path, to

Rename or move a file or directory, following it in open tabs.

file-copy

write-files

none

path, to

Copy a file to a new path.

directory-create

write-files

none

path

Create a directory and any missing parents.

editor-insert

write-files

required

path, line, match, regex, occurrence, position, save

Insert the body into a file before a line or a match, or at the end.

editor-replace

write-files

optional

path, line, match, regex, occurrence, expand, save

Replace the first match of a pattern, chosen matches, or a range of lines with the body.

editor-select

none

none

path, line, match, regex, occurrence, group

Select matching text or a range of lines in a file.

editor-highlight

none

none

path, line, match, regex, occurrence, group, duration

Briefly highlight matching text or a range of lines in a file.

file-browser-reveal

none

none

path

Show a path in the file browser.

download

none

none

path

Download a file to the learner’s machine.

upload-prompt

none

none

path

Ask the learner to upload files.

file-write writes its body line for line with one newline at the end; a blank line straight after the options is dropped as the separator, and other blank lines are kept, so an appended Python definition that must sit two blank lines below the last one starts its body with three (see directives). With open it shows the file in the editor with the cursor at the start of what it wrote: the top of the file, or with mode: append the first appended line, so a long file opens where the change is. An editor already showing the file is moved there whether or not open is set, since its cursor may have been in text the write replaced. The write replaces what is on disk even when the file has changed there since the editor loaded it, as it has when the learner’s code wrote it, and the learner is not asked which copy to keep. editor-insert and editor-replace leave the cursor at the start of the first text they wrote.

What an edit wrote is marked rather than selected, so a stray key press cannot replace it: the text editor-insert and editor-replace put in, at every place they put it, and the lines a file-write with mode: append added, are tinted, with a bar beside their line numbers. The marks stay until the next action runs, other than a verify, which changes nothing and is often run by the edit it follows. So do those of a deletion, which has no text left to tint: a red triangle beside the line numbers shows where an editor-replace with an empty body took text from, on the boundary between two lines when whole lines went, and beside the line, with a red tick in it at the point, when text went from within one. A file written whole is not marked. editor-highlight tints the text it points at in another colour for its duration, again without selecting it; only editor-select makes a selection, for the learner to copy or type over.

New text is scrolled to a quarter of the way down the view, so it reads downward from there with a few lines of what came before it above; the text file-open with line, editor-select and editor-highlight point at is centred, so it has context on both sides. A position that already serves is left where it is: anywhere in view for centred text, and the upper half of the view for new text, which lower down would run off the bottom, as long as three lines show above it. The ends of the file limit the scroll, so a match near the top sits as far down as the lines before it allow.

file-open opens a file in the text editor unless factory names another of JupyterLab’s widget factories, as docmanager:open takes it: HTML Viewer for an HTML report a command has written, Markdown Preview, CSVTable, JSON and so on, whatever the JupyterLab in use registers, with the name’s case not mattering. The file goes where area says either way (see layouts), and a file already open with that factory is brought forward, reloaded from disk when it has no unsaved changes, and moved only when area asks. An unknown factory name is reported when the action runs, since the factories a deployment has are only known then; line goes with the editor alone, and the linter reports invalid-file-open for a line with any other factory.

file-delete refuses the workshop directory and its _workshop state directory however the path is spelt, and refuses a directory unless recursive is set; a path that does not exist is nothing to do unless missing is error. file-rename and file-copy create the destination’s directory when it is missing and refuse a destination that exists, so neither replaces the learner’s work; file-rename also moves, since to is a full path. All four go through the contents API, so they behave the same on every platform, including JupyterLite, and the paths stay inside the workspace like any write.

Notebooks and kernels

Directive

Capability

Body

Options

Description

notebook-open

none

none

path, cell, area

Open a notebook, optionally at a cell.

notebook-create

write-files

yaml

path, kernel, existing, open, area

Create a notebook with the cells listed in the body, replacing one already there unless told to keep it.

cell-insert

write-files

required

path, at, kind, tags, run

Insert a cell into a notebook.

cell-run

kernel-exec

none

path, cell

Run a cell of a notebook.

cell-run-all

kernel-exec

none

path

Run every cell of a notebook.

cell-run-to

kernel-exec

none

path, cell

Run every cell up to and including one.

cell-select

none

none

path, cell

Make a cell the active cell.

cell-highlight

none

none

path, cell, duration

Briefly highlight a cell.

kernel-restart

kernel-exec

none

path

Restart the kernel of a notebook.

kernel-interrupt

none

none

path

Interrupt the kernel of a notebook.

kernel-select

none

none

path, kernel

Change the kernel of a notebook.

kernel-execute

kernel-exec

required

path, kernel, silent, capture

Run code in a kernel, optionally capturing the output into a variable.

console-open

none

none

path, area

Open a console attached to a notebook.

output-clear

none

none

path

Clear the outputs of a notebook.

notebook-create writes the notebook afresh each time it runs: a notebook already at the path is closed and replaced with the cells in the body, which is what a learner asking for a clean start wants from a click. With existing: keep a notebook already there is opened as it is and nothing is written. Use that on any notebook-create that runs on its own, such as one with auto: page-enter that makes a workshop open with its notebook showing: the page is entered again whenever the learner comes back to it, and replacing would discard every cell they had added and run since. The linter reports notebook-overwrite for an automatic notebook-create without it.

The box for a notebook-create shows the content of each cell, one below the other, and not the YAML of its body, so a learner sees what the notebook will hold.

kernel-execute with a path runs its code in the kernel of that notebook, where the learner’s own names are, and in the notebook’s directory. Without a path the code runs in the hidden workshop kernel, in the workspace and with the variables and the manifest’s env in the environment, as a kernel check does, so a file it writes by a relative path lands where the learner’s files are.

cell-insert with run reports an error when the kernel never ran the cell, since what the cell defines is then missing for the steps after it. A cell that ran and raised still counts as run: showing an error can be the point of the cell.

The body of a cell-insert is the source of the cell, line for line. A blank line before the closing fence leaves the cell ending with an empty line, which is what a cell holding only a comment that says where to write needs, so the learner has a line to click on and type.

Interface and layout

Directive

Capability

Body

Options

Description

command

none

optional

command

Run a JupyterLab command, with JSON arguments in the body.

layout

none

none

name

Arrange the JupyterLab panels using a named layout.

panel-open

none

none

id

Show a JupyterLab panel or widget by id.

panel-close

none

none

id, side

Collapse a sidebar, by default the one beside the instructions.

focus

none

none

id

Give a widget focus.

settings-set

ui-settings

required

plugin, key

Change a setting of the editor, with the JSON value in the body.

launcher-open

none

none

area

Open the launcher, or show the open one.

url-open

none

none

url, pane, area, label

Open a web page in a new browser tab, or in a named pane in the main area.

url-open opens the web page its url option names. Without pane it opens a new browser tab, which the browser only allows on a click, so it cannot run automatically. With pane it opens the page in an iframe in a main area tab of that name, creating the pane if there is none and loading the page afresh into it if there is, even when the URL is the same, so an application in the page starts over. area places a new pane like the other opening actions; label names the tab, and defaults to the pane name. The URL is substituted like any option, and the action waits until every variable in it has a value. A site that forbids being framed shows as an empty pane, and nothing can detect that, so try each URL once. A JupyterLab served over https cannot show an http page in a pane and opens it in a new tab instead, so lint warns about an http URL. It does not warn about one on a loopback host (localhost, 127.0.0.1 or [::1]), such as a server the workshop starts in a terminal: that address reaches the server only when the browser is on the machine JupyterLab runs on, where JupyterLab is itself reached over http. It does not reach it in a container or on a hosted JupyterLab, where the address is the learner’s own machine. Panes come back after the browser page reloads, at the last URL they were sent, and close with the workshop.

A server the workshop starts can also be shown through the Jupyter server’s web proxy, jupyter-server-proxy, which forwards <base>/proxy/<port>/ to a port on the machine the server runs on. That address works wherever JupyterLab does, on Binder or a hub as much as on the learner’s own machine, and is served over the same https as JupyterLab, so it shows in a pane where a loopback address cannot. The built-in variable jupyter_url is JupyterLab’s own address, so the URL is {{ jupyter_url }}proxy/{{ server_port }}/. A url-open of such a URL needs the web-proxy capability, and the proxy is not installed everywhere, so the web_proxy built-in says whether it is: put the action under a condition on it and offer the loopback address otherwise, which lint checks (proxy-unguarded). Without the proxy, the action reports that it cannot show the page. An app behind the proxy sees requests under that path, so one that writes absolute links needs telling its prefix, {{ jupyter_path }}proxy/{{ server_port }}/, the way Datasette’s base_url setting takes it.

```{url-open}
:title: Open the app
:when: web_proxy
:url: {{ jupyter_url }}proxy/{{ server_port }}/
:pane: app
```

```{url-open}
:title: Open the app
:when: not web_proxy
:url: http://127.0.0.1:{{ server_port }}/
:pane: app
```

Guidance

Directive

Capability

Body

Options

Description

highlight

none

optional

selector, duration

Draw attention to part of the interface.

tour

none

yaml

(none)

Walk through interface elements listed in the body.

toast

none

required

type, duration

Show a notification message.

tooltip

none

required

selector

Pin a note to an element until dismissed.

dialog

none

required

title, buttons, capture

Ask a question and store the answer in a variable.

hint

none

markdown

title, open, unlock, locked

Collapsible help, which can hold actions.

The body of a tour is a YAML list of steps, each with a selector for the element to point at and the text to say about it. The box for a tour shows the text of each step, numbered, and not the selectors.

A hint stays closed until the learner opens it, and its body is a piece of page: prose, and any actions written inside it, which is how a solution is kept out of sight until asked for. With unlock it shows locked until a condition holds, with the locked note beside its title. Hints describes both, and what a hint may not hold.

A hint that holds an action or quotes a fenced code block must be fenced with four backticks, so that the block’s three do not close it; see directives.

Flow and variables

Directive

Capability

Body

Options

Description

choice

none

optional

variable, options, track, label

Let the learner pick a value, optionally choosing a track.

env-set

none

required

name, value

Set a variable, with the value in the body.

next-page

none

none

(none)

Go to the next page.

The body of a choice is shown above its buttons, and the values in its :options: are the buttons’ labels. Both take standard inline Markdown on one line: code spans, emphasis and explicit links, with inline roles unrecognised, bare URLs left as text and raw HTML escaped. The buttons of a :track: true choice, or of one whose options come from the manifest variable’s options, show the manifest’s labels as plain text, as does the :label: in the header. The value a choice stores is the option as written, so Markdown in an option ends up in the variable too.

Checks, forms and checkpoints

Directive

Capability

Body

Options

Description

verify

none

optional

label, trigger, substrate, script, path, timeout, message

Check learner progress with code, a script, or file and interface predicates.

quiz

none

yaml

type, shuffle, attempts, case, lines

Ask a question, with the options to pick from or the answer to type in the body.

form

none

yaml

label

Collect variable values from the learner with the fields in the body.

attempt

none

markdown

check, expect, result

An answer for the self-test to try against a check, with what the check should say; never shown to the learner.

checkpoint

none

none

name

Snapshot the workshop files and variables under a name.

restore

write-files

none

name

Restore the workshop files and variables from a checkpoint.

External

Directive

Capability

Body

Options

Description

copy

none

required

(none)

Copy the body to the clipboard.

environment-create

install-packages

none

force

Create the isolated environment declared in the manifest and register its kernel; a no-op once it exists unless :force: true. JupyterLab only: the linter warns when a manifest lists jupyterlite.

Inline roles

Role

Description

{copy}

Copy the text to the clipboard.

{open}

Open the named file in the editor.

{highlight}

Highlight the element matching the selector.

{var}

Show the value of a variable.

Structure

The {when} directive takes a condition as its argument and shows its body only when the condition holds, for example ```{when} track == "pip". Conditions use ==, !=, in, not in, and, or, not and parentheses over variables, quoted strings and [lists]. A when holding an action or a code block is fenced with four backticks, so that the block’s three do not close it; see directives.

The verify, quiz, form, attempt, checkpoint and restore directives are described in checks.md.