Playground

In this article

playgroundProcessor generates links to code playgrounds.

Usage

const docs = new Generator(import.meta.url, {
    processors: [
        playgroundProcessor({
            entries: [
                {
                    id: "example-playground",
                    variable: "exampleUrl",
                    urlFormat: "https://example.net/#{{ base64 }}",
                    folder: "docs/playground",
                },
            ],
        }),
    ],
});

Configuration

The playgroundProcessor takes a configuration object:

readonly enabled?: boolean; Optional
Enable/disable processor. Default: true
readonly entries?: PlaygroundProcessorEntry[]; Optional

List of playgrounds available.

Default is empty array (no playgrounds enabled)

Each entry consists of:

readonly folder?: string; Optional

Path to a folder with files to inject into the playground url.

If unspecified, no files will be injected by default.

readonly id: string;
Unique identifier for this playground.

serialize?(this: void, context: { readonly files: Map<string, string>; }): string | Promise<string>; Optional : Serialize the files to a string for using in the url generation.

Default is `JSON.stringify()`.
readonly urlFormat: string;

The URL format.

The following placeholders are available:

  • base64: Base64 encoded payload (use "atou" to decode unicode codepoints).
  • zlibBase64: zlib base64 encoded payload.
readonly variable?: string; Optional

Name of template variable with the playground URL to inject.

If unspecified, no template variable will be available.

Search

Esc to close Arrow up/down to navigate Enter to select

Select version

Please wait, loading version data...