h3ndrk / interactive-widgets-mkdocs

MkDocs plugin for generating frontend HTML for interactive-widgets-backend
MIT License
1 stars 1 forks source link

interactive-widgets-mkdocs

This repository contains an MkDocs plugin for converting custom HTML tags embedded in the Markdown of MkDocs pages into interactive widgets. The plugin relies on interactive-widgets-backend as the backend for providing isolated Docker containers for running the widgets.

Configuration

See the MkDocs documentation about how to use plugins which shows how to supply configuration values to this plugin.

HTML Tag Reference

The following HTML tags can be used in any Markdown page processed with the interactive-widgets-mkdocs plugin. Special characters within HTML tag attributes need to be escaped. Symptomes of lacking escaping may be missing page contents.

<x-button />

Displays a button which executes a given command.

Attributes:

The frontend shows a button with the given label. The command is also displayed. If the command outputs to the standard output, it will be rendered in the frontend. During execution of the command, any additional execution attempts are ignored.

Clicking the button in the frontend results in starting a Docker container in the backend and waiting for the termination. During the execution, output is transmitted to all connected frontend clients and additional execution requests are ignored.

Example: <x-button command="date" image="ubuntu:latest" label="Print date" working-directory="/data" />

<x-epilogue />

Executes a given command at room tear down.

Attributes:

The frontend shows the given command. If the command outputs to the standard output, it will be rendered in the frontend.

The backend runs the given command in a new Docker container during room tear down and waits for the termination.

Example: <x-epilogue command="date" image="ubuntu:latest" working-directory="/data" />

<x-image-viewer />

Displays and monitors a given image file.

Attributes:

The frontend shows the image or an error message if an error occurred. In the caption it displays the given image file path.

The backend monitors the given image file for changes and sends the contents or error messages to the frontend. It runs the monitoring process in new long-running Docker container (configurable via configuration values backend_monitor_image and backend_monitor_command).

Example: <x-image-viewer file="/data/image.png" mime="image/png" success-timeout="0.1" failure-timeout="5" />

<x-prologue />

Executes a given command at room instantiation.

Attributes:

The frontend shows the given command. If the command outputs to the standard output, it will be rendered in the frontend.

The backend runs the given command in a new Docker container during room instantiation and waits for the termination.

Example: <x-prologue command="date" image="ubuntu:latest" working-directory="/data" />

<x-terminal />

Execute a given command in a pseudo-terminal and display the output.

Attributes:

The frontend shows a terminal widget (behaves like a normal terminal) and also displays the current terminal title if a title is set (else the given command and working-directory is shown).

The backend executes the given command in the given working-directory in a new long-running and restarting Docker container. It sends the containers output to the frontend and receives the input for the container.

Example: <x-terminal image="ubuntu:latest" command="/bin/bash" working-directory="/data" />

<x-text-editor />

Displays, monitors and allows to edit a given text file.

Attributes:

The frontend shows the text editor or an error message if an error occurred. In the caption it displays the given text file path. Three buttons allow to create or truncate the monitored file, save the current editor contents to that file, or delete the monitored file.

The backend monitors the given text file for changes and sends the contents or error messages to the frontend. The backend receives commands for writing or deleting the given text file. It runs the monitoring process in new long-running Docker container (configurable via configuration values backend_monitor_image and backend_monitor_command).

Example: <x-text-editor file="/data/example.py" mode="python" success-timeout="0.1" failure-timeout="5" />

<x-text-viewer />

Displays and monitors a given text file.

Attributes:

The frontend shows the text or an error message if an error occurred. In the caption it displays the given text file path.

The backend monitors the given text file for changes and sends the contents or error messages to the frontend. It runs the monitoring process in new long-running Docker container (configurable via configuration values backend_monitor_image and backend_monitor_command).

Example: <x-text-viewer file="/data/example.py" mode="python" success-timeout="0.1" failure-timeout="5" />

Usage

This section covers all necessary steps to build a complete and deployable website based on interactive-widgets-mkdocs.

License

MIT