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 |
|---|---|---|---|---|
|
terminal |
required |
|
Run a command in a named terminal. |
|
kernel-exec |
required |
|
Run a command in the background and capture its output into a variable. |
|
terminal |
none |
|
Open or reveal a named terminal, optionally in a layout area. |
|
terminal |
none |
|
Clear a named terminal. |
|
terminal |
none |
|
Close a named terminal and end its session. |
|
terminal |
required |
|
Type text into a terminal without pressing Enter. |
|
terminal |
none |
|
Send key strokes to a terminal. |
|
terminal |
none |
|
Interrupt the command running in a terminal. |
Files and editor¶
Directive |
Capability |
Body |
Options |
Description |
|---|---|---|---|---|
|
write-files |
optional |
|
Write the body, or a file shipped with the workshop, to a file. |
|
none |
none |
|
Open a file in the editor, optionally at a line, or in another viewer. |
|
none |
none |
|
Close every editor and preview showing a file. |
|
write-files |
none |
|
Delete a file, or a directory and its contents, closing its tabs. |
|
write-files |
none |
|
Rename or move a file or directory, following it in open tabs. |
|
write-files |
none |
|
Copy a file to a new path. |
|
write-files |
none |
|
Create a directory and any missing parents. |
|
write-files |
required |
|
Insert the body into a file before a line or a match, or at the end. |
|
write-files |
optional |
|
Replace the first match of a pattern, chosen matches, or a range of lines with the body. |
|
none |
none |
|
Select matching text or a range of lines in a file. |
|
none |
none |
|
Briefly highlight matching text or a range of lines in a file. |
|
none |
none |
|
Show a path in the file browser. |
|
none |
none |
|
Download a file to the learner’s machine. |
|
none |
none |
|
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 |
|---|---|---|---|---|
|
none |
none |
|
Open a notebook, optionally at a cell. |
|
write-files |
yaml |
|
Create a notebook with the cells listed in the body, replacing one already there unless told to keep it. |
|
write-files |
required |
|
Insert a cell into a notebook. |
|
kernel-exec |
none |
|
Run a cell of a notebook. |
|
kernel-exec |
none |
|
Run every cell of a notebook. |
|
kernel-exec |
none |
|
Run every cell up to and including one. |
|
none |
none |
|
Make a cell the active cell. |
|
none |
none |
|
Briefly highlight a cell. |
|
kernel-exec |
none |
|
Restart the kernel of a notebook. |
|
none |
none |
|
Interrupt the kernel of a notebook. |
|
none |
none |
|
Change the kernel of a notebook. |
|
kernel-exec |
required |
|
Run code in a kernel, optionally capturing the output into a variable. |
|
none |
none |
|
Open a console attached to a notebook. |
|
none |
none |
|
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 |
|---|---|---|---|---|
|
none |
optional |
|
Run a JupyterLab command, with JSON arguments in the body. |
|
none |
none |
|
Arrange the JupyterLab panels using a named layout. |
|
none |
none |
|
Show a JupyterLab panel or widget by id. |
|
none |
none |
|
Collapse a sidebar, by default the one beside the instructions. |
|
none |
none |
|
Give a widget focus. |
|
ui-settings |
required |
|
Change a setting of the editor, with the JSON value in the body. |
|
none |
none |
|
Open the launcher, or show the open one. |
|
none |
none |
|
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 |
|---|---|---|---|---|
|
none |
optional |
|
Draw attention to part of the interface. |
|
none |
yaml |
(none) |
Walk through interface elements listed in the body. |
|
none |
required |
|
Show a notification message. |
|
none |
required |
|
Pin a note to an element until dismissed. |
|
none |
required |
|
Ask a question and store the answer in a variable. |
|
none |
markdown |
|
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 |
|---|---|---|---|---|
|
none |
optional |
|
Let the learner pick a value, optionally choosing a track. |
|
none |
required |
|
Set a variable, with the value in the body. |
|
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 |
|---|---|---|---|---|
|
none |
optional |
|
Check learner progress with code, a script, or file and interface predicates. |
|
none |
yaml |
|
Ask a question, with the options to pick from or the answer to type in the body. |
|
none |
yaml |
|
Collect variable values from the learner with the fields in the body. |
|
none |
markdown |
|
An answer for the self-test to try against a check, with what the check should say; never shown to the learner. |
|
none |
none |
|
Snapshot the workshop files and variables under a name. |
|
write-files |
none |
|
Restore the workshop files and variables from a checkpoint. |
External¶
Directive |
Capability |
Body |
Options |
Description |
|---|---|---|---|---|
|
none |
required |
(none) |
Copy the body to the clipboard. |
|
install-packages |
none |
|
Create the isolated environment declared in the manifest and register its kernel; a no-op once it exists unless |
Inline roles¶
Role |
Description |
|---|---|
|
Copy the text to the clipboard. |
|
Open the named file in the editor. |
|
Highlight the element matching the selector. |
|
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.